|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace ElevenLabs\ApiServiceBundle\Tests\DependencyInjection\Compiler; |
|
4
|
|
|
|
|
5
|
|
|
use ElevenLabs\ApiServiceBundle\DependencyInjection\Compiler\FormatPass; |
|
6
|
|
|
use PHPUnit\Framework\MockObject\MockObject; |
|
7
|
|
|
use PHPUnit\Framework\TestCase; |
|
8
|
|
|
use Symfony\Component\DependencyInjection\ContainerBuilder; |
|
9
|
|
|
use Symfony\Component\DependencyInjection\Definition; |
|
10
|
|
|
|
|
11
|
|
|
/** |
|
12
|
|
|
* Class FormatPassTest. |
|
13
|
|
|
*/ |
|
14
|
|
|
class FormatPassTest extends TestCase |
|
15
|
|
|
{ |
|
16
|
|
|
/** |
|
17
|
|
|
* @var ContainerBuilder|MockObject |
|
18
|
|
|
*/ |
|
19
|
|
|
private $containerBuilder; |
|
20
|
|
|
|
|
21
|
|
|
/** |
|
22
|
|
|
* @var Definition|MockObject |
|
23
|
|
|
*/ |
|
24
|
|
|
private $definition; |
|
25
|
|
|
|
|
26
|
|
|
public function setUp() |
|
27
|
|
|
{ |
|
28
|
|
|
$this->definition = $this->createMock(Definition::class); |
|
29
|
|
|
$this->containerBuilder = $this->createMock(ContainerBuilder::class); |
|
30
|
|
|
} |
|
31
|
|
|
|
|
32
|
|
|
public function testShouldNotAddFormat() |
|
33
|
|
|
{ |
|
34
|
|
|
$this->containerBuilder |
|
35
|
|
|
->expects($this->once()) |
|
36
|
|
|
->method('findTaggedServiceIds') |
|
37
|
|
|
->with('serializer.encoder') |
|
38
|
|
|
->willReturn([]) |
|
39
|
|
|
; |
|
40
|
|
|
$this->containerBuilder |
|
41
|
|
|
->expects($this->once()) |
|
42
|
|
|
->method('getDefinition') |
|
43
|
|
|
->with('api_service.decoder.symfony') |
|
44
|
|
|
->willReturn($this->definition) |
|
45
|
|
|
; |
|
46
|
|
|
$this->definition->expects($this->once())->method('setArgument')->with(0, []); |
|
47
|
|
|
|
|
48
|
|
|
$compiler = new FormatPass(); |
|
49
|
|
|
$compiler->process($this->containerBuilder); |
|
50
|
|
|
} |
|
51
|
|
|
|
|
52
|
|
|
public function testShouldAddFormat() |
|
53
|
|
|
{ |
|
54
|
|
|
$this->containerBuilder |
|
55
|
|
|
->expects($this->once()) |
|
56
|
|
|
->method('findTaggedServiceIds') |
|
57
|
|
|
->with('serializer.encoder') |
|
58
|
|
|
->willReturn(['service_id' => []]) |
|
59
|
|
|
; |
|
60
|
|
|
$this->containerBuilder |
|
61
|
|
|
->expects($this->exactly(2)) |
|
62
|
|
|
->method('getDefinition') |
|
63
|
|
|
->willReturnCallback(function ($id) { |
|
64
|
|
|
$this->assertTrue(\in_array($id, ['api_service.decoder.symfony', 'service_id'])); |
|
65
|
|
|
return $this->definition; |
|
66
|
|
|
}) |
|
67
|
|
|
; |
|
68
|
|
|
$this->definition->expects($this->once())->method('setArgument')->willReturnCallback(function ($position, $argument){ |
|
|
|
|
|
|
69
|
|
|
$this->assertSame(0, $position); |
|
70
|
|
|
$this->assertTrue(\is_array($argument)); |
|
71
|
|
|
$this->assertCount(1, $argument); |
|
72
|
|
|
$this->assertInstanceOf(Definition::class, $argument[0]); |
|
73
|
|
|
}); |
|
74
|
|
|
|
|
75
|
|
|
$compiler = new FormatPass(); |
|
76
|
|
|
$compiler->process($this->containerBuilder); |
|
77
|
|
|
} |
|
78
|
|
|
} |
|
79
|
|
|
|