1313use PHPUnit \Framework \TestCase ;
1414
1515/**
16- * @inheritdoc
16+ * Test class for ThemeResolver
1717 */
1818class ThemeResolverTest extends TestCase
1919{
2020 /**
21- * @var ThemeResolver
21+ * @var ThemeResolver|MockObject
2222 */
2323 private $ themeResolver ;
2424
@@ -36,34 +36,46 @@ protected function setUp(): void
3636
3737 $ this ->themeResolver = $ this ->getMockBuilder (ThemeResolver::class)
3838 ->onlyMethods (['getThemes ' ])
39- ->setConstructorArgs ([
40- $ this ->loggerMock ,
41- ])->getMock ();
39+ ->setConstructorArgs ([$ this ->loggerMock ])
40+ ->getMock ();
4241 }
4342
4443 /**
45- * @param string $expectedReturn
46- * @param string $passedTheme
47- *
44+ * @param string $expectedReturn
45+ * @param string $passedTheme
4846 * @dataProvider testResolveDataProvider
4947 */
5048 public function testResolve (string $ expectedReturn , string $ passedTheme ): void
5149 {
52- $ this ->themeResolver ->expects ($ this ->once ())
53- ->method ('getThemes ' )
50+ $ this ->themeResolver ->method ('getThemes ' )
5451 ->willReturn (['SomeVendor/sometheme ' ]);
5552
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+ }
6160 );
6261
62+ $ this ->loggerMock ->expects ($ this ->never ())
63+ ->method ('error ' );
64+
6365 $ this ->assertEquals (
6466 $ expectedReturn ,
6567 $ this ->themeResolver ->resolve ($ passedTheme )
6668 );
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+ );
6779 }
6880
6981 public function testResolveDataProvider (): array
@@ -82,9 +94,9 @@ public function testResolveDataProvider(): array
8294
8395 public function testCorrect (): void
8496 {
85- $ this ->themeResolver ->expects ($ this ->once ())
86- ->method ('getThemes ' )
97+ $ this ->themeResolver ->method ('getThemes ' )
8798 ->willReturn (['SomeVendor/sometheme ' ]);
99+
88100 $ this ->loggerMock ->expects ($ this ->never ())
89101 ->method ('warning ' );
90102 $ this ->loggerMock ->expects ($ this ->never ())
@@ -98,19 +110,35 @@ public function testCorrect(): void
98110
99111 public function testNoResolve (): void
100112 {
101- $ this ->themeResolver ->expects ($ this ->once ())
102- ->method ('getThemes ' )
113+ $ this ->themeResolver ->method ('getThemes ' )
103114 ->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+ );
110132
111133 $ this ->assertEquals (
112134 '' ,
113135 $ this ->themeResolver ->resolve ('SomeVendor/doesntExist ' )
114136 );
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 ]);
115143 }
116144}
0 commit comments