-
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 #5 from tienvx/application-tests
test: Test UserController
- Loading branch information
Showing
15 changed files
with
128 additions
and
18 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
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
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
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 |
---|---|---|
|
@@ -4,4 +4,4 @@ parameters: | |
- src | ||
- tests | ||
excludePaths: | ||
- 'tests/Integration/TestApplication/var' | ||
- 'tests/TestApplication/var' |
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
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,61 @@ | ||
<?php | ||
|
||
namespace Tienvx\Bundle\PactMessengerBundle\Tests\Application\Controller; | ||
|
||
use Symfony\Bundle\FrameworkBundle\Test\WebTestCase; | ||
use Symfony\Component\Messenger\Envelope; | ||
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 UserControllerTest extends WebTestCase | ||
{ | ||
public function testCreateUser(): void | ||
{ | ||
$client = static::createClient(); | ||
$client->request('POST', '/create'); | ||
$this->assertResponseIsSuccessful(); | ||
|
||
$container = static::getContainer(); | ||
$collector = $container->get(EnvelopeCollectorInterface::class); | ||
$this->assertCount(1, $all = $collector->getAll()); | ||
|
||
$this->assertInstanceOf(Envelope::class, $created = $collector->getSingle(UserCreated::class)); | ||
$this->assertTrue(in_array($created, $all)); | ||
$this->assertInstanceOf(UserCreated::class, $message = $created->getMessage()); | ||
$this->assertSame(123, $message->userId); | ||
} | ||
|
||
public function testUpdateUser(): void | ||
{ | ||
$client = static::createClient(); | ||
$client->request('PUT', '/update/123'); | ||
$this->assertResponseIsSuccessful(); | ||
|
||
$container = static::getContainer(); | ||
$collector = $container->get(EnvelopeCollectorInterface::class); | ||
$this->assertCount(1, $all = $collector->getAll()); | ||
|
||
$this->assertInstanceOf(Envelope::class, $created = $collector->getSingle(UserUpdated::class)); | ||
$this->assertTrue(in_array($created, $all)); | ||
$this->assertInstanceOf(UserUpdated::class, $message = $created->getMessage()); | ||
$this->assertSame(123, $message->userId); | ||
} | ||
|
||
public function testDeleteUser(): void | ||
{ | ||
$client = static::createClient(); | ||
$client->request('DELETE', '/delete/123'); | ||
$this->assertResponseIsSuccessful(); | ||
|
||
$container = static::getContainer(); | ||
$collector = $container->get(EnvelopeCollectorInterface::class); | ||
$this->assertCount(1, $all = $collector->getAll()); | ||
|
||
$this->assertInstanceOf(Envelope::class, $created = $collector->getSingle(UserDeleted::class)); | ||
$this->assertTrue(in_array($created, $all)); | ||
$this->assertInstanceOf(UserDeleted::class, $message = $created->getMessage()); | ||
$this->assertSame(123, $message->userId); | ||
} | ||
} |
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
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
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,8 @@ | ||
<?php | ||
|
||
use Symfony\Component\Routing\Loader\Configurator\RoutingConfigurator; | ||
use Tienvx\Bundle\PactMessengerBundle\Tests\TestApplication\Kernel; | ||
|
||
return function (RoutingConfigurator $routes) { | ||
$routes->import('../src/Controller/', Kernel::MAJOR_VERSION >= 6 ? 'attribute' : 'annotation'); | ||
}; |
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
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,38 @@ | ||
<?php | ||
|
||
namespace Tienvx\Bundle\PactMessengerBundle\Tests\TestApplication\Controller; | ||
|
||
use Symfony\Component\HttpFoundation\Request; | ||
use Symfony\Component\HttpFoundation\Response; | ||
use Symfony\Component\Messenger\MessageBusInterface; | ||
use Symfony\Component\Routing\Annotation\Route; | ||
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 UserController | ||
{ | ||
#[Route('/create', name: 'create_user', methods: Request::METHOD_POST)] | ||
public function create(MessageBusInterface $bus): Response | ||
{ | ||
$bus->dispatch(new UserCreated(123)); | ||
|
||
return new Response('created'); | ||
} | ||
|
||
#[Route('/update/{id}', name: 'update_user', methods: Request::METHOD_PUT)] | ||
public function update(int $id, MessageBusInterface $bus): Response | ||
{ | ||
$bus->dispatch(new UserUpdated($id)); | ||
|
||
return new Response('updated'); | ||
} | ||
|
||
#[Route('/delete/{id}', name: 'delete_user', methods: Request::METHOD_DELETE)] | ||
public function delete(int $id, MessageBusInterface $bus): Response | ||
{ | ||
$bus->dispatch(new UserDeleted($id)); | ||
|
||
return new Response('deleted'); | ||
} | ||
} |
2 changes: 1 addition & 1 deletion
2
...ntegration/TestApplication/src/Kernel.php → tests/TestApplication/src/Kernel.php
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
2 changes: 1 addition & 1 deletion
2
...stApplication/src/Message/UserCreated.php → ...stApplication/src/Message/UserCreated.php
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
2 changes: 1 addition & 1 deletion
2
...stApplication/src/Message/UserDeleted.php → ...stApplication/src/Message/UserDeleted.php
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
2 changes: 1 addition & 1 deletion
2
...stApplication/src/Message/UserUpdated.php → ...stApplication/src/Message/UserUpdated.php
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