/
TestClientPassTest.php
68 lines (57 loc) · 2.43 KB
/
TestClientPassTest.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
<?php
/*
* This file is part of the API Platform project.
*
* (c) Kévin Dunglas <dunglas@gmail.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
declare(strict_types=1);
namespace ApiPlatform\Core\Tests\Bridge\Symfony\Bundle\DependencyInjection\Compiler;
use ApiPlatform\Core\Bridge\Symfony\Bundle\DependencyInjection\Compiler\TestClientPass;
use ApiPlatform\Core\Bridge\Symfony\Bundle\Test\Client;
use PHPUnit\Framework\TestCase;
use Prophecy\Argument;
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Definition;
final class TestClientPassTest extends TestCase
{
private $containerBuilderProphecy;
private $testClientPass;
protected function setUp(): void
{
$this->containerBuilderProphecy = $this->prophesize(ContainerBuilder::class);
$this->testClientPass = new TestClientPass();
}
public function testConstruct(): void
{
self::assertInstanceOf(CompilerPassInterface::class, $this->testClientPass);
}
public function testProcessWithoutTestClientParameters(): void
{
$this->containerBuilderProphecy->hasParameter('test.client.parameters')->willReturn(false)->shouldBeCalledOnce();
$this->containerBuilderProphecy->setDefinition('test.api_platform.client', Argument::type(Definition::class))->shouldNotBeCalled();
$this->testClientPass->process($this->containerBuilderProphecy->reveal());
}
public function testProcess(): void
{
$this->containerBuilderProphecy->hasParameter('test.client.parameters')->willReturn(true)->shouldBeCalledOnce();
$this->containerBuilderProphecy
->setDefinition(
'test.api_platform.client',
Argument::allOf(
Argument::type(Definition::class),
Argument::that(function (Definition $testClientDefinition) {
return
Client::class === $testClientDefinition->getClass() &&
!$testClientDefinition->isShared() &&
$testClientDefinition->isPublic();
})
)
)
->shouldBeCalledOnce();
$this->testClientPass->process($this->containerBuilderProphecy->reveal());
}
}