Skip to content

Commit

Permalink
test: Add integration tests
Browse files Browse the repository at this point in the history
  • Loading branch information
tienvx committed Mar 29, 2024
1 parent de93aba commit 957f6a7
Show file tree
Hide file tree
Showing 3 changed files with 84 additions and 1 deletion.
39 changes: 39 additions & 0 deletions tests/Integration/Service/MessageDispatcherManagerTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
<?php

namespace Tienvx\Bundle\PactProviderBundle\Tests\Integration\Service;

use PHPUnit\Framework\Attributes\TestWith;
use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase;
use Tienvx\Bundle\PactProviderBundle\Exception\NoDispatcherForMessageException;
use Tienvx\Bundle\PactProviderBundle\Model\Message;
use Tienvx\Bundle\PactProviderBundle\Service\MessageDispatcherManagerInterface;

class MessageDispatcherManagerTest extends KernelTestCase
{
#[TestWith(['no message', null])]
#[TestWith(['has message', new Message('message content', 'text/plain', '{"key":"value","contentType":"text\/plain"}')])]
public function testHandle(string $description, ?Message $message): void
{
self::bootKernel();

$container = static::getContainer();

$manager = $container->get(MessageDispatcherManagerInterface::class);
$this->assertEquals($message, $manager->dispatch($description));
}

public function testMissingDispatcher(): void
{
self::bootKernel();

$container = static::getContainer();
$manager = $container->get(MessageDispatcherManagerInterface::class);

$description = 'no dispatcher';

$this->expectException(NoDispatcherForMessageException::class);
$this->expectExceptionMessage(sprintf("No dispatcher for description '%s'.", $description));

$manager->dispatch($description);
}
}
44 changes: 44 additions & 0 deletions tests/Integration/Service/StateHandlerManagerTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
<?php

namespace Tienvx\Bundle\PactProviderBundle\Tests\Integration\Service;

use PHPUnit\Framework\Attributes\TestWith;
use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase;
use Tienvx\Bundle\PactProviderBundle\Enum\Action;
use Tienvx\Bundle\PactProviderBundle\Exception\NoHandlerForStateException;
use Tienvx\Bundle\PactProviderBundle\Model\StateValues;
use Tienvx\Bundle\PactProviderBundle\Service\StateHandlerManagerInterface;

class StateHandlerManagerTest extends KernelTestCase
{
#[TestWith(['no values', Action::SETUP, null])]
#[TestWith(['no values', Action::TEARDOWN, null])]
#[TestWith(['required state', Action::SETUP, new StateValues(['id' => 123])])]
#[TestWith(['required state', Action::TEARDOWN, null])]
public function testHandle(string $state, Action $action, ?StateValues $stateValues): void
{
self::bootKernel();

$container = static::getContainer();

$manager = $container->get(StateHandlerManagerInterface::class);
$this->assertEquals($stateValues, $manager->handle($state, $action, ['key' => 'value']));
}

#[TestWith([Action::SETUP])]
#[TestWith([Action::TEARDOWN])]
public function testMissingHandler(Action $action): void
{
self::bootKernel();

$container = static::getContainer();
$manager = $container->get(StateHandlerManagerInterface::class);

$state = 'no handler';

$this->expectException(NoHandlerForStateException::class);
$this->expectExceptionMessage(sprintf("No handler for state '%s'.", $state));

$manager->handle($state, $action, ['key' => 'value']);
}
}
2 changes: 1 addition & 1 deletion tests/Unit/Service/MessageDispatcherManagerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ protected function setUp(): void

public function testNoHandler(): void
{
$description = 'no handler';
$description = 'no dispatcher';
$this->locator
->expects($this->once())
->method('has')
Expand Down

0 comments on commit 957f6a7

Please sign in to comment.