-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #6 from tienvx/test-service
test: Test EnvelopeCollector
- Loading branch information
Showing
1 changed file
with
64 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
<?php | ||
|
||
namespace Tienvx\Bundle\PactProviderBundle\Tests\Unit\Service; | ||
|
||
use PHPUnit\Framework\TestCase; | ||
use Symfony\Component\Messenger\Envelope; | ||
use Tienvx\Bundle\PactMessengerBundle\Exception\LogicException; | ||
use Tienvx\Bundle\PactMessengerBundle\Service\EnvelopeCollector; | ||
use Tienvx\Bundle\PactMessengerBundle\Service\EnvelopeCollectorInterface; | ||
use Tienvx\Bundle\PactMessengerBundle\Tests\TestApplication\Message\UserCreated; | ||
use Tienvx\Bundle\PactMessengerBundle\Tests\TestApplication\Message\UserDeleted; | ||
use Tienvx\Bundle\PactMessengerBundle\Tests\TestApplication\Message\UserUpdated; | ||
|
||
class EnvelopeCollectorTest extends TestCase | ||
{ | ||
private EnvelopeCollectorInterface $collector; | ||
|
||
protected function setUp(): void | ||
{ | ||
$this->collector = new EnvelopeCollector(); | ||
} | ||
|
||
public function testGetAll(): void | ||
{ | ||
$this->collector->collect($create = new Envelope(new UserCreated(123))); | ||
$this->collector->collect($update = new Envelope(new UserUpdated(123))); | ||
$this->collector->collect($delete = new Envelope(new UserDeleted(123))); | ||
$this->assertSame([$create, $update, $delete], $this->collector->getAll()); | ||
} | ||
|
||
public function testSingleWithoutTransport(): void | ||
{ | ||
$this->collector->collect($create = new Envelope(new UserCreated(123))); | ||
$this->collector->collect($update = new Envelope(new UserUpdated(123))); | ||
$this->collector->collect($delete = new Envelope(new UserDeleted(123))); | ||
$this->assertSame($create, $this->collector->getSingle(UserCreated::class)); | ||
} | ||
|
||
public function testSingleWithTransportThrowException(): void | ||
{ | ||
$this->collector->collect($create = new Envelope(new UserCreated(123))); | ||
$this->collector->collect($update = new Envelope(new UserUpdated(123))); | ||
$this->collector->collect($delete = new Envelope(new UserDeleted(123))); | ||
$this->expectException(LogicException::class); | ||
$this->expectExceptionMessage('You need to upgrade to Symfony >=6.2 to be able to filter envelope by transport.'); | ||
$this->collector->getSingle(UserCreated::class, 'async'); | ||
} | ||
|
||
public function testSingleWithTransportFound(): void | ||
{ | ||
$this->collector->collect($create = new Envelope(new UserCreated(123)), ['async']); | ||
$this->collector->collect($update = new Envelope(new UserUpdated(123)), ['async']); | ||
$this->collector->collect($delete = new Envelope(new UserDeleted(123)), ['async', 'audit']); | ||
$this->assertSame($delete, $this->collector->getSingle(UserDeleted::class, 'audit')); | ||
} | ||
|
||
public function testSingleWithTransportNotFound(): void | ||
{ | ||
$this->collector->collect($create = new Envelope(new UserCreated(123)), ['async']); | ||
$this->collector->collect($update = new Envelope(new UserUpdated(123)), ['async']); | ||
$this->collector->collect($delete = new Envelope(new UserDeleted(123)), ['async', 'audit']); | ||
$this->assertNull($this->collector->getSingle(UserUpdated::class, 'audit')); | ||
} | ||
} |