forked from geocoder-php/BazingaGeocoderBundle
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFactoryValidatorPassTest.php
More file actions
86 lines (72 loc) · 2.71 KB
/
FactoryValidatorPassTest.php
File metadata and controls
86 lines (72 loc) · 2.71 KB
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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
<?php
declare(strict_types=1);
/*
* This file is part of the BazingaGeocoderBundle package.
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*
* @license MIT License
*/
namespace Bazinga\GeocoderBundle\Tests\DependencyInjection\Compiler;
use Bazinga\GeocoderBundle\DependencyInjection\Compiler\FactoryValidatorPass;
use PHPUnit\Framework\TestCase;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Exception\ServiceNotFoundException;
final class FactoryValidatorPassTest extends TestCase
{
private FactoryValidatorPass $compilerPass;
private string $factoryId;
protected function setUp(): void
{
$this->compilerPass = new FactoryValidatorPass();
$this->factoryId = 'dummy_factory_id';
$this->compilerPass::addFactoryServiceId($this->factoryId);
}
protected function tearDown(): void
{
$reflection = new \ReflectionObject($this->compilerPass);
$prop = $reflection->getProperty('factoryServiceIds');
$prop->setValue(null, []);
}
public function testProcessThrows(): void
{
$this->expectException(ServiceNotFoundException::class);
$this->expectExceptionMessage("Factory with ID \"$this->factoryId\" could not be found");
$container = $this->createMock(ContainerBuilder::class);
$container->expects($this->once())
->method('hasAlias')
->with($this->factoryId)
->willReturn(false);
$container->expects($this->once())
->method('hasDefinition')
->with($this->factoryId)
->willReturn(false);
$this->compilerPass->process($container);
}
public function testProcessDoesntThrowIfAliasExists(): void
{
$container = $this->createMock(ContainerBuilder::class);
$container->expects($this->once())
->method('hasAlias')
->with($this->factoryId)
->willReturn(true);
$container->expects($this->never())
->method('hasDefinition')
->with($this->factoryId)
->willReturn(false);
$this->compilerPass->process($container);
}
public function testProcessDoesntThrowIfDefinitionExists(): void
{
$container = $this->createMock(ContainerBuilder::class);
$container->expects($this->once())
->method('hasAlias')
->with($this->factoryId)
->willReturn(false);
$container->expects($this->once())
->method('hasDefinition')
->with($this->factoryId)
->willReturn(true);
$this->compilerPass->process($container);
}
}