10
10
11
11
namespace MezzioTest \Plates \Extension ;
12
12
13
+ use League \Plates \Engine ;
13
14
use Mezzio \Helper \ServerUrlHelper ;
14
15
use Mezzio \Helper \UrlHelper ;
15
16
use Mezzio \Plates \Exception \MissingHelperException ;
16
17
use Mezzio \Plates \Extension \UrlExtension ;
17
18
use Mezzio \Plates \Extension \UrlExtensionFactory ;
18
19
use PHPUnit \Framework \TestCase ;
20
+ use Prophecy \PhpUnit \ProphecyTrait ;
19
21
use Prophecy \Prophecy \ProphecyInterface ;
20
22
use Psr \Container \ContainerInterface ;
21
23
22
24
class UrlExtensionFactoryTest extends TestCase
23
25
{
26
+ use ProphecyTrait;
27
+
24
28
/** @var ContainerInterface|ProphecyInterface */
25
29
private $ container ;
26
30
@@ -30,38 +34,47 @@ class UrlExtensionFactoryTest extends TestCase
30
34
/** @var ServerUrlHelper|ProphecyInterface */
31
35
private $ serverUrlHelper ;
32
36
33
- public function setUp ()
37
+ public function setUp (): void
34
38
{
35
- $ this ->container = $ this ->prophesize (ContainerInterface::class);
36
- $ this ->urlHelper = $ this ->prophesize (UrlHelper::class);
39
+ $ this ->container = $ this ->prophesize (ContainerInterface::class);
40
+ $ this ->urlHelper = $ this ->prophesize (UrlHelper::class);
37
41
$ this ->serverUrlHelper = $ this ->prophesize (ServerUrlHelper::class);
38
42
}
39
43
40
44
public function testFactoryReturnsUrlExtensionInstanceWhenHelpersArePresent ()
41
45
{
46
+ $ urlHelper = $ this ->urlHelper ->reveal ();
47
+ $ serverUrlHelper = $ this ->serverUrlHelper ->reveal ();
48
+
42
49
$ this ->container ->has (UrlHelper::class)->willReturn (true );
43
- $ this ->container ->get (UrlHelper::class)->willReturn ($ this -> urlHelper -> reveal () );
50
+ $ this ->container ->get (UrlHelper::class)->willReturn ($ urlHelper );
44
51
$ this ->container ->has (ServerUrlHelper::class)->willReturn (true );
45
- $ this ->container ->get (ServerUrlHelper::class)->willReturn ($ this -> serverUrlHelper -> reveal () );
52
+ $ this ->container ->get (ServerUrlHelper::class)->willReturn ($ serverUrlHelper );
46
53
47
- $ factory = new UrlExtensionFactory ();
54
+ $ factory = new UrlExtensionFactory ();
48
55
$ extension = $ factory ($ this ->container ->reveal ());
49
56
$ this ->assertInstanceOf (UrlExtension::class, $ extension );
50
57
51
- $ this ->assertAttributeSame ($ this ->urlHelper ->reveal (), 'urlHelper ' , $ extension );
52
- $ this ->assertAttributeSame ($ this ->serverUrlHelper ->reveal (), 'serverUrlHelper ' , $ extension );
58
+ $ engine = $ this ->createMock (Engine::class);
59
+ $ engine ->method ('registerFunction ' )
60
+ ->withConsecutive (
61
+ ['url ' , $ this ->equalTo ($ urlHelper )],
62
+ ['serverurl ' , $ this ->equalTo ($ serverUrlHelper )]
63
+ );
64
+
65
+ $ extension ->register ($ engine );
53
66
}
54
67
55
68
public function testFactoryRaisesExceptionIfUrlHelperIsMissing ()
56
69
{
57
70
$ this ->container ->has (UrlHelper::class)->willReturn (false );
58
- $ this ->container ->has (\Zend \ Expressive \Helper \UrlHelper::class)->willReturn (false );
71
+ $ this ->container ->has (\Mezzio \Helper \UrlHelper::class)->willReturn (false );
59
72
$ this ->container ->get (UrlHelper::class)->shouldNotBeCalled ();
60
- $ this ->container ->get (\Zend \ Expressive \Helper \UrlHelper::class)->shouldNotBeCalled ();
73
+ $ this ->container ->get (\Mezzio \Helper \UrlHelper::class)->shouldNotBeCalled ();
61
74
$ this ->container ->has (ServerUrlHelper::class)->shouldNotBeCalled ();
62
- $ this ->container ->has (\Zend \ Expressive \Helper \ServerUrlHelper::class)->shouldNotBeCalled ();
75
+ $ this ->container ->has (\Mezzio \Helper \ServerUrlHelper::class)->shouldNotBeCalled ();
63
76
$ this ->container ->get (ServerUrlHelper::class)->shouldNotBeCalled ();
64
- $ this ->container ->get (\Zend \ Expressive \Helper \ServerUrlHelper::class)->shouldNotBeCalled ();
77
+ $ this ->container ->get (\Mezzio \Helper \ServerUrlHelper::class)->shouldNotBeCalled ();
65
78
66
79
$ factory = new UrlExtensionFactory ();
67
80
@@ -74,11 +87,11 @@ public function testFactoryRaisesExceptionIfServerUrlHelperIsMissing()
74
87
{
75
88
$ this ->container ->has (UrlHelper::class)->willReturn (true );
76
89
$ this ->container ->get (UrlHelper::class)->shouldNotBeCalled ();
77
- $ this ->container ->get (\Zend \ Expressive \Helper \UrlHelper::class)->shouldNotBeCalled ();
90
+ $ this ->container ->get (\Mezzio \Helper \UrlHelper::class)->shouldNotBeCalled ();
78
91
$ this ->container ->has (ServerUrlHelper::class)->willReturn (false );
79
- $ this ->container ->has (\Zend \ Expressive \Helper \ServerUrlHelper::class)->willReturn (false );
92
+ $ this ->container ->has (\Mezzio \Helper \ServerUrlHelper::class)->willReturn (false );
80
93
$ this ->container ->get (ServerUrlHelper::class)->shouldNotBeCalled ();
81
- $ this ->container ->get (\Zend \ Expressive \Helper \ServerUrlHelper::class)->shouldNotBeCalled ();
94
+ $ this ->container ->get (\Mezzio \Helper \ServerUrlHelper::class)->shouldNotBeCalled ();
82
95
83
96
$ factory = new UrlExtensionFactory ();
84
97
0 commit comments