tests: add IndexController tests
This commit is contained in:
parent
3cb6f7488f
commit
3182dd93cf
12
config/services_test.yaml
Normal file
12
config/services_test.yaml
Normal file
@ -0,0 +1,12 @@
|
||||
services:
|
||||
# default configuration for services in *this* file
|
||||
_defaults:
|
||||
autowire: true # Automatically injects dependencies in your services.
|
||||
autoconfigure: true # Automatically registers your services as commands, event subscribers, etc.
|
||||
public: true
|
||||
|
||||
App\Service\QRCodeGeneratorInterface:
|
||||
lazy: true
|
||||
public: true
|
||||
# add more service definitions when explicit configuration is needed
|
||||
# please note that last definitions always *replace* previous ones
|
92
tests/Controller/IndexControllerTest.php
Normal file
92
tests/Controller/IndexControllerTest.php
Normal file
@ -0,0 +1,92 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Tests\Controller;
|
||||
|
||||
use App\Service\QRCodeGeneratorInterface;
|
||||
use Symfony\Bundle\FrameworkBundle\KernelBrowser;
|
||||
use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;
|
||||
|
||||
class IndexControllerTest extends WebTestCase
|
||||
{
|
||||
public function testFormIsPresentAfterLoadHomepage(): void
|
||||
{
|
||||
$client = static::createClient();
|
||||
$client->request('GET', '/');
|
||||
|
||||
$this->assertResponseIsSuccessful();
|
||||
$this->assertSelectorExists('form');
|
||||
}
|
||||
|
||||
public function testImageIsPresentAfterSubmitForm(): void {
|
||||
$client = $this->generateClientForSubmitTest();
|
||||
$response = $client->request('GET', '/');
|
||||
$this->assertResponseIsSuccessful();
|
||||
$form = $response->selectButton('Vygenerovat QR kód')->form();
|
||||
$dt = new \DateTime('now+1 hour'); // In case of 23:59:59
|
||||
$client->submit($form, [
|
||||
'qr_code' => [
|
||||
'iban' => 'CZ5508000000001234567899',
|
||||
'dueDate' => $dt->format('Y-m-d'),
|
||||
'message' => 'foo',
|
||||
'money' => [
|
||||
'currency' => 'CZK',
|
||||
'amount' => '100'
|
||||
],
|
||||
'paymentIdentification' => [
|
||||
'variableSymbol' => '123',
|
||||
'constantSymbol' => '123',
|
||||
'specificSymbol' => '123'
|
||||
]
|
||||
]
|
||||
]);
|
||||
|
||||
$this->assertResponseIsSuccessful();
|
||||
$this->assertSelectorExists('form');
|
||||
$this->assertSelectorExists('img');
|
||||
}
|
||||
|
||||
public function testImageIsNotPresentAfterFailSubmitForm(): void {
|
||||
$client = $this->generateClientForSubmitTest();
|
||||
$response = $client->request('GET', '/');
|
||||
$this->assertResponseIsSuccessful();
|
||||
$form = $response->selectButton('Vygenerovat QR kód')->form();
|
||||
$dt = new \DateTime('now+1 hour'); // In case of 23:59:59
|
||||
$client->submit($form, [
|
||||
'qr_code' => [
|
||||
'iban' => 'IBAN_THAT_NOT_EXISTS',
|
||||
'dueDate' => $dt->format('Y-m-d'),
|
||||
'message' => 'foo',
|
||||
'money' => [
|
||||
'currency' => 'CZK',
|
||||
'amount' => '100'
|
||||
],
|
||||
'paymentIdentification' => [
|
||||
'variableSymbol' => '123',
|
||||
'constantSymbol' => '123',
|
||||
'specificSymbol' => '123'
|
||||
]
|
||||
]
|
||||
]);
|
||||
|
||||
$this->assertResponseIsUnprocessable();
|
||||
$this->assertSelectorExists('form');
|
||||
$this->assertSelectorNotExists('img');
|
||||
}
|
||||
|
||||
private function generateClientForSubmitTest(): KernelBrowser
|
||||
{
|
||||
$mock = $this->createMock(QRCodeGeneratorInterface::class);
|
||||
$mock->expects($this->any())
|
||||
->method('generateQRCodeFromEntity')
|
||||
->will($this->returnValue('foo'));
|
||||
|
||||
|
||||
$client = static::createClient();
|
||||
$client->disableReboot();
|
||||
|
||||
self::getContainer()->set('App\Service\QRCodeGeneratorInterface', $mock);
|
||||
|
||||
return $client;
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user