13
13
use PHPUnit \Framework \TestCase ;
14
14
15
15
/**
16
- * @inheritdoc
16
+ * Test class for ThemeResolver
17
17
*/
18
18
class ThemeResolverTest extends TestCase
19
19
{
20
20
/**
21
- * @var ThemeResolver
21
+ * @var ThemeResolver|MockObject
22
22
*/
23
23
private $ themeResolver ;
24
24
@@ -36,34 +36,46 @@ protected function setUp(): void
36
36
37
37
$ this ->themeResolver = $ this ->getMockBuilder (ThemeResolver::class)
38
38
->onlyMethods (['getThemes ' ])
39
- ->setConstructorArgs ([
40
- $ this ->loggerMock ,
41
- ])->getMock ();
39
+ ->setConstructorArgs ([$ this ->loggerMock ])
40
+ ->getMock ();
42
41
}
43
42
44
43
/**
45
- * @param string $expectedReturn
46
- * @param string $passedTheme
47
- *
44
+ * @param string $expectedReturn
45
+ * @param string $passedTheme
48
46
* @dataProvider testResolveDataProvider
49
47
*/
50
48
public function testResolve (string $ expectedReturn , string $ passedTheme ): void
51
49
{
52
- $ this ->themeResolver ->expects ($ this ->once ())
53
- ->method ('getThemes ' )
50
+ $ this ->themeResolver ->method ('getThemes ' )
54
51
->willReturn (['SomeVendor/sometheme ' ]);
55
52
56
- $ this ->loggerMock ->expects ($ this ->exactly (2 ))
57
- ->method ('warning ' )
58
- ->willReturnOnConsecutiveCalls (
59
- 'Theme SomeVendor/Sometheme does not exist, attempting to resolve. ' ,
60
- 'Theme found as SomeVendor/sometheme Using corrected name instead '
53
+ $ messages = [];
54
+
55
+ $ this ->loggerMock ->method ('warning ' )
56
+ ->willReturnCallback (
57
+ function ($ msg ) use (&$ messages ) {
58
+ $ messages [] = $ msg ;
59
+ }
61
60
);
62
61
62
+ $ this ->loggerMock ->expects ($ this ->never ())
63
+ ->method ('error ' );
64
+
63
65
$ this ->assertEquals (
64
66
$ expectedReturn ,
65
67
$ this ->themeResolver ->resolve ($ passedTheme )
66
68
);
69
+
70
+ $ this ->assertCount (2 , $ messages );
71
+ $ this ->assertSame (
72
+ 'Theme ' . $ passedTheme . ' does not exist, attempting to resolve. ' ,
73
+ $ messages [0 ]
74
+ );
75
+ $ this ->assertSame (
76
+ 'Theme found as SomeVendor/sometheme. Using corrected name instead. ' ,
77
+ $ messages [1 ]
78
+ );
67
79
}
68
80
69
81
public function testResolveDataProvider (): array
@@ -82,9 +94,9 @@ public function testResolveDataProvider(): array
82
94
83
95
public function testCorrect (): void
84
96
{
85
- $ this ->themeResolver ->expects ($ this ->once ())
86
- ->method ('getThemes ' )
97
+ $ this ->themeResolver ->method ('getThemes ' )
87
98
->willReturn (['SomeVendor/sometheme ' ]);
99
+
88
100
$ this ->loggerMock ->expects ($ this ->never ())
89
101
->method ('warning ' );
90
102
$ this ->loggerMock ->expects ($ this ->never ())
@@ -98,19 +110,35 @@ public function testCorrect(): void
98
110
99
111
public function testNoResolve (): void
100
112
{
101
- $ this ->themeResolver ->expects ($ this ->once ())
102
- ->method ('getThemes ' )
113
+ $ this ->themeResolver ->method ('getThemes ' )
103
114
->willReturn (['SomeVendor/sometheme ' ]);
104
- $ this ->loggerMock ->expects ($ this ->once ())
105
- ->method ('warning ' )
106
- ->willReturn ('Theme SomeVendor/doesntExist does not exist, attempting to resolve. ' );
107
- $ this ->loggerMock ->expects ($ this ->once ())
108
- ->method ('error ' )
109
- ->willReturn ('Unable to resolve theme. ' );
115
+
116
+ $ warnings = [];
117
+ $ errors = [];
118
+
119
+ $ this ->loggerMock ->method ('warning ' )
120
+ ->willReturnCallback (
121
+ function ($ msg ) use (&$ warnings ) {
122
+ $ warnings [] = $ msg ;
123
+ }
124
+ );
125
+
126
+ $ this ->loggerMock ->method ('error ' )
127
+ ->willReturnCallback (
128
+ function ($ msg ) use (&$ errors ) {
129
+ $ errors [] = $ msg ;
130
+ }
131
+ );
110
132
111
133
$ this ->assertEquals (
112
134
'' ,
113
135
$ this ->themeResolver ->resolve ('SomeVendor/doesntExist ' )
114
136
);
137
+
138
+ $ this ->assertCount (1 , $ warnings );
139
+ $ this ->assertSame ('Theme SomeVendor/doesntExist does not exist, attempting to resolve. ' , $ warnings [0 ]);
140
+
141
+ $ this ->assertCount (1 , $ errors );
142
+ $ this ->assertSame ('Unable to resolve theme. ' , $ errors [0 ]);
115
143
}
116
144
}
0 commit comments