This repository has been archived by the owner on Feb 12, 2023. It is now read-only.
-
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.
Integration tests for console commands.
- Loading branch information
Showing
6 changed files
with
296 additions
and
4 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
102 changes: 102 additions & 0 deletions
102
tests/Bridge/Symfony/Console/Command/MvdLookupCommandTest.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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,102 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Damax\Services\Client\Tests\Bridge\Symfony\Console\Command; | ||
|
||
use Damax\Services\Client\Bridge\Symfony\Console\Command\MvdLookupCommand; | ||
use Damax\Services\Client\Client; | ||
use Damax\Services\Client\InvalidRequestException; | ||
use Damax\Services\Client\PassportCheck; | ||
use PHPUnit\Framework\MockObject\MockObject; | ||
use Symfony\Bundle\FrameworkBundle\Console\Application; | ||
use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase; | ||
use Symfony\Component\Console\Tester\CommandTester; | ||
|
||
/** | ||
* @group integration | ||
* @group console | ||
*/ | ||
class MvdLookupCommandTest extends KernelTestCase | ||
{ | ||
/** | ||
* @var Client|MockObject | ||
*/ | ||
private $client; | ||
|
||
/** | ||
* @var CommandTester | ||
*/ | ||
private $tester; | ||
|
||
protected function setUp() | ||
{ | ||
static::bootKernel(); | ||
|
||
$this->client = $this->createMock(Client::class); | ||
|
||
$command = new MvdLookupCommand($this->client); | ||
$command->setApplication(new Application(self::$kernel)); | ||
|
||
$this->tester = new CommandTester($command); | ||
} | ||
|
||
/** | ||
* @test | ||
*/ | ||
public function it_checks_passport() | ||
{ | ||
$this->client | ||
->expects($this->once()) | ||
->method('checkPassport') | ||
->with('0000000001') | ||
->willReturn(new PassportCheck([ | ||
'source' => '0000000001', | ||
'code' => 1, | ||
'message' => 'Valid passport', | ||
'ok' => true, | ||
'series' => '0000', | ||
'number' => '000001', | ||
])) | ||
; | ||
|
||
$code = $this->tester->execute(['command' => 'damax:mvd:passport:lookup', 'number' => '0000000001']); | ||
|
||
$output = <<<CONSOLE | ||
--------- ---------------- | ||
Field Value | ||
--------- ---------------- | ||
source 0000000001 | ||
code 1 | ||
message Valid passport | ||
ok + | ||
series 0000 | ||
number 000001 | ||
--------- ---------------- | ||
CONSOLE; | ||
|
||
$this->assertSame(0, $code); | ||
$this->assertEquals($output, $this->tester->getDisplay()); | ||
} | ||
|
||
/** | ||
* @test | ||
*/ | ||
public function it_throws_request_exception() | ||
{ | ||
$this->client | ||
->expects($this->once()) | ||
->method('checkPassport') | ||
->with('0000000001') | ||
->willThrowException(new InvalidRequestException('Connection problem.')) | ||
; | ||
|
||
$code = $this->tester->execute(['command' => 'damax:mvd:passport:lookup', 'number' => '0000000001']); | ||
|
||
$this->assertSame(1, $code); | ||
$this->assertEquals('[ERROR] Connection problem.', trim($this->tester->getDisplay())); | ||
} | ||
} |
145 changes: 145 additions & 0 deletions
145
tests/Bridge/Symfony/Console/Command/RosfinLookupCommandTest.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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,145 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Damax\Services\Client\Tests\Bridge\Symfony\Console\Command; | ||
|
||
use Damax\Services\Client\Bridge\Symfony\Console\Command\RosfinLookupCommand; | ||
use Damax\Services\Client\Client; | ||
use Damax\Services\Client\InvalidRequestException; | ||
use Damax\Services\Client\RosfinCheck; | ||
use PHPUnit\Framework\MockObject\MockObject; | ||
use Symfony\Bundle\FrameworkBundle\Console\Application; | ||
use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase; | ||
use Symfony\Component\Console\Tester\CommandTester; | ||
|
||
class RosfinLookupCommandTest extends KernelTestCase | ||
{ | ||
/** | ||
* @var Client|MockObject | ||
*/ | ||
private $client; | ||
|
||
/** | ||
* @var CommandTester | ||
*/ | ||
private $tester; | ||
|
||
protected function setUp() | ||
{ | ||
static::bootKernel(); | ||
|
||
$this->client = $this->createMock(Client::class); | ||
|
||
$command = new RosfinLookupCommand($this->client); | ||
$command->setApplication(new Application(self::$kernel)); | ||
|
||
$this->tester = new CommandTester($command); | ||
} | ||
|
||
/** | ||
* @test | ||
*/ | ||
public function it_throws_request_exception() | ||
{ | ||
$this->client | ||
->expects($this->once()) | ||
->method('checkRosfin') | ||
->with('John Doe', '1983-01-20') | ||
->willThrowException(new InvalidRequestException('Connection problem.')) | ||
; | ||
|
||
$code = $this->tester->execute(['command' => 'damax:rosfin:lookup', 'fullName' => 'John Doe', 'birthDate' => '1983-01-20']); | ||
|
||
$this->assertSame(1, $code); | ||
$this->assertEquals('[ERROR] Connection problem.', trim($this->tester->getDisplay())); | ||
} | ||
|
||
/** | ||
* @test | ||
*/ | ||
public function it_finds_no_results() | ||
{ | ||
$this->client | ||
->expects($this->once()) | ||
->method('checkRosfin') | ||
->with('John Doe', '1983-01-20') | ||
->willReturn(new RosfinCheck([])) | ||
; | ||
|
||
$code = $this->tester->execute(['command' => 'damax:rosfin:lookup', 'fullName' => 'John Doe', 'birthDate' => '1983-01-20']); | ||
|
||
$this->assertSame(0, $code); | ||
$this->assertEquals('[OK] Not found.', trim($this->tester->getDisplay())); | ||
} | ||
|
||
/** | ||
* @test | ||
*/ | ||
public function it_finds_results() | ||
{ | ||
$this->client | ||
->expects($this->once()) | ||
->method('checkRosfin') | ||
->with('John Doe', '1983-01-20') | ||
->willReturn(new RosfinCheck([ | ||
[ | ||
'id' => 3302081139, | ||
'type' => 4, | ||
'fullName' => ['СОКОЛОВСКИЙ РУСЛАН ГЕННАДЬЕВИЧ'], | ||
], | ||
[ | ||
'id' => 1, | ||
'type' => 3, | ||
'fullName' => ['John Doe', 'Jane Doe'], | ||
'birthDate' => '1983-01-20', | ||
'birthPlace' => 'Riga', | ||
'description' => 'Extremely dangerous.', | ||
'address' => 'Military base.', | ||
'resolution' => 'Wanted by FBI.', | ||
'passport' => '0000000001', | ||
], | ||
])) | ||
; | ||
|
||
$code = $this->tester->execute(['command' => 'damax:rosfin:lookup', 'fullName' => 'John Doe', 'birthDate' => '1983-01-20']); | ||
|
||
$output = <<<CONSOLE | ||
------------- -------------------------------- | ||
Field Value | ||
------------- -------------------------------- | ||
ID 3302081139 | ||
Type 4 | ||
Full name СОКОЛОВСКИЙ РУСЛАН ГЕННАДЬЕВИЧ | ||
Birth date - | ||
Birth place - | ||
Description - | ||
Address - | ||
Resolution - | ||
Passport - | ||
------------- -------------------------------- | ||
------------- ---------------------- | ||
Field Value | ||
------------- ---------------------- | ||
ID 1 | ||
Type 3 | ||
Full name John Doe | ||
Jane Doe | ||
Birth date 1983-01-20 | ||
Birth place Riga | ||
Description Extremely dangerous. | ||
Address Military base. | ||
Resolution Wanted by FBI. | ||
Passport 0000000001 | ||
------------- ---------------------- | ||
CONSOLE; | ||
|
||
$this->assertSame(0, $code); | ||
$this->assertEquals($output, $this->tester->getDisplay()); | ||
} | ||
} |
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,30 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Damax\Services\Client\Tests\Functional; | ||
|
||
use Symfony\Component\Config\Loader\LoaderInterface; | ||
use Symfony\Component\HttpKernel\Kernel; | ||
|
||
class AppKernel extends Kernel | ||
{ | ||
public function getCacheDir() | ||
{ | ||
return sys_get_temp_dir() . DIRECTORY_SEPARATOR . 'cache'; | ||
} | ||
|
||
public function getLogDir(): string | ||
{ | ||
return sys_get_temp_dir() . DIRECTORY_SEPARATOR . 'logs'; | ||
} | ||
|
||
public function registerBundles(): array | ||
{ | ||
return []; | ||
} | ||
|
||
public function registerContainerConfiguration(LoaderInterface $loader): void | ||
{ | ||
} | ||
} |