Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
"ext-json": "*",
"ext-mongodb": "*",
"symfony/messenger": "^5.0 || ^6.0 || ^7.0",
"mongodb/mongodb": "^1.12"
"mongodb/mongodb": "^1.12 || ^2.1"
},
"require-dev": {
"symfony/serializer": "^5.0 || ^6.0 || ^7.0",
Expand Down
2 changes: 1 addition & 1 deletion docker/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ RUN apk update \
&& apk add --no-cache git zip make autoconf g++ openssl-dev linux-headers \
&& apk add --no-cache --virtual .build-deps $PHPIZE_DEPS

RUN pecl -q install mongodb-1.17.2 \
RUN pecl -q install mongodb-2.1.1 \
&& docker-php-ext-enable mongodb \
&& pecl -q install xdebug \
&& docker-php-ext-enable xdebug
Expand Down
2 changes: 1 addition & 1 deletion src/MongoTransport.php
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ public function send(Envelope $envelope): Envelope
return $envelope->with(new TransportMessageIdStamp($objectId));
}

public function all(int $limit = null): iterable
public function all(int $limit = null): \Traversable
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The ListableReceiverInterface is defined with iterable. Why not keeping iterable?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

8.2.0 The type of iterator has been widened from Traversable to Traversable|array.

Before 8.2 should be \Traversable

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

MongoTransportTest uses $collection = iterator_to_array($transport->all(2));

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

still i don't get why MongoTransport should not respect the interface it implements.

{
$documents = $this->collection->find([], ['limit' => $limit]);

Expand Down
77 changes: 75 additions & 2 deletions tests/Unit/MongoTransportTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
use EmagTechLabs\MessengerMongoBundle\Tests\Unit\Fixtures\HelloMessage;
use MongoDB\BSON\ObjectId;
use MongoDB\Collection;
use MongoDB\Driver\CursorInterface;
use MongoDB\InsertOneResult;
use PHPUnit\Framework\Attributes\Test;
use PHPUnit\Framework\TestCase;
Expand Down Expand Up @@ -128,11 +129,11 @@ public function itShouldListAllMessages(): void

$collection = $this->createMock(Collection::class);
$collection->method('find')
->willReturn([
->willReturn($this->createCursor([
$this->createDocument(),
$this->createDocument(),
$this->createDocument(),
]);
]));

$transport = new MongoTransport(
$collection,
Expand Down Expand Up @@ -290,4 +291,76 @@ private function createSerializer(): SerializerInterface
{
return new Serializer();
}

/**
* Zwraca prosty kursor zgodny z MongoDB\Driver\CursorInterface,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

don't forget to remove the comments

* który iteruje po przekazanej tablicy dokumentów.
*
* @param array<int, array<string, mixed>> $documents
*/
private function createCursor(array $documents): \MongoDB\Driver\CursorInterface
{
return new class($documents) implements \MongoDB\Driver\CursorInterface
{
private array $data;
private int $position = 0;

public function __construct(array $data)
{
$this->data = array_values($data);
}

// Iterator
public function current(): array|null|object
{
return $this->data[$this->position];
}

public function key(): int
{
return $this->position;
}

public function next(): void
{
$this->position++;
}

public function rewind(): void
{
$this->position = 0;
}

public function valid(): bool
{
return array_key_exists($this->position, $this->data);
}

// CursorInterface
public function toArray(): array
{
return $this->data;
}

public function isDead(): bool
{
return false;
}

public function setTypeMap(array $typemap): void
{
// NOP – niepotrzebne w testach
}

public function getId(): \MongoDB\BSON\Int64
{
throw new \RuntimeException('Not implemented in test cursor.');
}

public function getServer(): \MongoDB\Driver\Server
{
throw new \RuntimeException('Not implemented in test cursor.');
}
};
}
}