1
+ <?php
2
+ declare (strict_types=1 );
3
+
4
+ namespace RunAsRoot \CliConstructorArgAutoProxy \Test \Unit \Plugin \Dom ;
5
+
6
+ use PHPUnit \Framework \TestCase ;
7
+ use Psr \Log \LoggerInterface ;
8
+ use RunAsRoot \CliConstructorArgAutoProxy \Plugin \Dom \EnrichCliConfigWithProxyPlugin ;
9
+ use RunAsRoot \CliConstructorArgAutoProxy \Preference \Framework \ObjectManager \Config \Reader \Dom \Interceptor ;
10
+ use RunAsRoot \CliConstructorArgAutoProxy \Service \EnrichCliConfigWithProxyService ;
11
+
12
+ final class EnrichCliConfigWithProxyPluginTest extends TestCase
13
+ {
14
+ private EnrichCliConfigWithProxyService $ service ;
15
+ private LoggerInterface $ logger ;
16
+ private EnrichCliConfigWithProxyPlugin $ sut ;
17
+
18
+ protected function setUp (): void
19
+ {
20
+ $ this ->service = $ this ->createMock (EnrichCliConfigWithProxyService::class);
21
+ $ this ->logger = $ this ->createMock (LoggerInterface::class);
22
+ $ this ->sut = new EnrichCliConfigWithProxyPlugin ($ this ->service , $ this ->logger );
23
+ }
24
+
25
+ public function test_after_read (): void
26
+ {
27
+ $ subject = $ this ->createMock (Interceptor::class);
28
+ $ result = ['foo ' => 'bar ' ];
29
+ $ scope = 'global ' ;
30
+
31
+ $ this ->service ->expects ($ this ->once ())->method ('execute ' )->with ($ result )
32
+ ->willReturn (['abc ' => 'def ' ]);
33
+ $ this ->logger ->expects ($ this ->never ())->method ('error ' );
34
+
35
+ $ this ->assertSame (['abc ' => 'def ' ], $ this ->sut ->afterRead ($ subject , $ result , $ scope ));
36
+ }
37
+
38
+ public function test_after_read_with_non_global_scope (): void
39
+ {
40
+ $ subject = $ this ->createMock (Interceptor::class);
41
+ $ result = ['foo ' => 'bar ' ];
42
+ $ scope = 'foo ' ;
43
+
44
+ $ this ->service ->expects ($ this ->never ())->method ('execute ' );
45
+ $ this ->logger ->expects ($ this ->never ())->method ('error ' );
46
+
47
+ $ this ->assertSame ($ result , $ this ->sut ->afterRead ($ subject , $ result , $ scope ));
48
+ }
49
+
50
+ public function test_after_read_with_exception (): void
51
+ {
52
+ $ subject = $ this ->createMock (Interceptor::class);
53
+ $ result = ['foo ' => 'bar ' ];
54
+ $ scope = 'global ' ;
55
+
56
+ $ this ->service ->expects ($ this ->once ())->method ('execute ' )
57
+ ->with ($ result )->willThrowException (new \ReflectionException ('foo ' ));
58
+ $ this ->logger ->expects ($ this ->once ())->method ('error ' );
59
+
60
+ $ this ->assertSame ($ result , $ this ->sut ->afterRead ($ subject , $ result , $ scope ));
61
+ }
62
+ }
0 commit comments