77use Laminas \Config \Config ;
88use Laminas \ServiceManager \AbstractPluginManager ;
99use PHPUnit \Framework \TestCase ;
10- use Prophecy \PhpUnit \ProphecyTrait ;
1110use Psr \Container \ContainerInterface ;
1211use Reinfi \DependencyInjection \Annotation \InjectConfig ;
1312use Reinfi \DependencyInjection \Service \ConfigService ;
1716 */
1817class InjectConfigTest extends TestCase
1918{
20- use ProphecyTrait;
21-
2219 public function testItCallsConfigServiceFromContainerWithValue (): void
2320 {
2421 $ inject = new InjectConfig ([
2522 'value ' => 'reinfi.di.test ' ,
2623 ]);
2724
28- $ configService = $ this ->prophesize (ConfigService::class);
29- $ configService ->resolve ('reinfi.di.test ' )
25+ $ configService = $ this ->createMock (ConfigService::class);
26+ $ configService ->expects ($ this ->once ())
27+ ->method ('resolve ' )
28+ ->with ('reinfi.di.test ' )
3029 ->willReturn (true );
3130
32- $ container = $ this ->prophesize (ContainerInterface::class);
33- $ container ->get (ConfigService::class)
34- ->willReturn ($ configService ->reveal ());
31+ $ container = $ this ->createMock (ContainerInterface::class);
32+ $ container ->expects ($ this ->once ())
33+ ->method ('get ' )
34+ ->with (ConfigService::class)
35+ ->willReturn ($ configService );
3536
36- self ::assertTrue ($ inject ($ container-> reveal () ), 'Invoke should return true ' );
37+ self ::assertTrue ($ inject ($ container ), 'Invoke should return true ' );
3738 }
3839
3940 public function testItCallsConfigServiceFromPluginManagerWithValue (): void
@@ -42,19 +43,24 @@ public function testItCallsConfigServiceFromPluginManagerWithValue(): void
4243 'value ' => 'reinfi.di.test ' ,
4344 ]);
4445
45- $ configService = $ this ->prophesize (ConfigService::class);
46- $ configService ->resolve ('reinfi.di.test ' )
46+ $ configService = $ this ->createMock (ConfigService::class);
47+ $ configService ->expects ($ this ->once ())
48+ ->method ('resolve ' )
49+ ->with ('reinfi.di.test ' )
4750 ->willReturn (true );
4851
49- $ container = $ this ->prophesize (ContainerInterface::class);
50- $ container ->get (ConfigService::class)
51- ->willReturn ($ configService ->reveal ());
52+ $ container = $ this ->createMock (ContainerInterface::class);
53+ $ container ->expects ($ this ->once ())
54+ ->method ('get ' )
55+ ->with (ConfigService::class)
56+ ->willReturn ($ configService );
5257
53- $ pluginManager = $ this ->prophesize (AbstractPluginManager::class);
54- $ pluginManager ->getServiceLocator ()
55- ->willReturn ($ container ->reveal ());
58+ $ pluginManager = $ this ->createMock (AbstractPluginManager::class);
59+ $ pluginManager ->expects ($ this ->once ())
60+ ->method ('getServiceLocator ' )
61+ ->willReturn ($ container );
5662
57- self ::assertTrue ($ inject ($ pluginManager-> reveal () ), 'Invoke should return true ' );
63+ self ::assertTrue ($ inject ($ pluginManager ), 'Invoke should return true ' );
5864 }
5965
6066 public function testItReturnsArrayIfPropertyIsSet (): void
@@ -64,17 +70,23 @@ public function testItReturnsArrayIfPropertyIsSet(): void
6470 'asArray ' => true ,
6571 ]);
6672
67- $ config = $ this ->prophesize (Config::class);
68- $ config ->toArray ()->shouldBeCalled ()->willReturn ([true ]);
73+ $ config = $ this ->createMock (Config::class);
74+ $ config ->expects ($ this ->once ())
75+ ->method ('toArray ' )
76+ ->willReturn ([true ]);
6977
70- $ configService = $ this ->prophesize (ConfigService::class);
71- $ configService ->resolve ('reinfi.di.test ' )
72- ->willReturn ($ config ->reveal ());
78+ $ configService = $ this ->createMock (ConfigService::class);
79+ $ configService ->expects ($ this ->once ())
80+ ->method ('resolve ' )
81+ ->with ('reinfi.di.test ' )
82+ ->willReturn ($ config );
7383
74- $ container = $ this ->prophesize (ContainerInterface::class);
75- $ container ->get (ConfigService::class)
76- ->willReturn ($ configService ->reveal ());
84+ $ container = $ this ->createMock (ContainerInterface::class);
85+ $ container ->expects ($ this ->once ())
86+ ->method ('get ' )
87+ ->with (ConfigService::class)
88+ ->willReturn ($ configService );
7789
78- self ::assertEquals ([true ], $ inject ($ container-> reveal () ), 'Invoke should return array containing true ' );
90+ self ::assertEquals ([true ], $ inject ($ container ), 'Invoke should return array containing true ' );
7991 }
8092}
0 commit comments