@@ -32,17 +32,42 @@ public function testGetScreenshotFullscreenWithResize(): void {
3232 $ session = $ this ->createMock (Session::class);
3333 $ driver = $ this ->createMock (Selenium2Driver::class);
3434
35- // Mock the JavaScript evaluation to return document dimensions.
35+ // Mock the JavaScript evaluation to return both original and document
36+ // dimensions.
3637 $ session ->method ('evaluateScript ' )
37- ->willReturn ([
38- 'scrollWidth ' => 1440 ,
39- 'scrollHeight ' => 2000 ,
40- ]);
41-
42- // Cannot mock getWindowSize in PHPUnit 11, so we'll rely on default values.
43- $ session ->expects ($ this ->once ())
38+ ->willReturnOnConsecutiveCalls (
39+ // First call: get original window dimensions.
40+ [
41+ 'width ' => 1440 ,
42+ 'height ' => 900 ,
43+ ],
44+ // Second call: get document scroll dimensions.
45+ [
46+ 'scrollWidth ' => 1440 ,
47+ 'scrollHeight ' => 2000 ,
48+ ]
49+ );
50+
51+ // Expect resize to be called twice: once to expand, once to restore.
52+ $ session ->expects ($ this ->exactly (2 ))
4453 ->method ('resizeWindow ' )
45- ->with (1440 , 2200 , 'current ' );
54+ ->willReturnCallback (function ($ width , $ height , $ name ): void {
55+ static $ call_count = 0 ;
56+ $ call_count ++;
57+
58+ if ($ call_count === 1 ) {
59+ // First call: resize to fullscreen.
60+ $ this ->assertEquals (1440 , $ width );
61+ $ this ->assertEquals (2200 , $ height );
62+ $ this ->assertEquals ('current ' , $ name );
63+ }
64+ elseif ($ call_count === 2 ) {
65+ // Second call: restore to original.
66+ $ this ->assertEquals (1440 , $ width );
67+ $ this ->assertEquals (900 , $ height );
68+ $ this ->assertEquals ('current ' , $ name );
69+ }
70+ });
4671
4772 $ session ->method ('getDriver ' )->willReturn ($ driver );
4873 $ screenshot_context ->method ('getSession ' )->willReturn ($ session );
@@ -71,13 +96,24 @@ public function testGetScreenshotFullscreenWithResizeInvalidDimensions(): void {
7196 $ session = $ this ->createMock (Session::class);
7297 $ driver = $ this ->createMock (Selenium2Driver::class);
7398
74- // Mock the JavaScript evaluation to return invalid dimensions.
99+ // Mock the JavaScript evaluation to return invalid dimensions for both
100+ // calls.
75101 $ session ->method ('evaluateScript ' )
76- ->willReturn ([
77- 'scrollWidth ' => 0 ,
78- 'scrollHeight ' => 0 ,
79- ]);
80-
102+ ->willReturnOnConsecutiveCalls (
103+ // First call: get original window dimensions.
104+ [
105+ 'width ' => 1440 ,
106+ 'height ' => 900 ,
107+ ],
108+ // Second call: get document scroll dimensions (invalid).
109+ [
110+ 'scrollWidth ' => 0 ,
111+ 'scrollHeight ' => 0 ,
112+ ]
113+ );
114+
115+ // Should not resize when dimensions are invalid, but returns regular
116+ // screenshot.
81117 $ session ->expects ($ this ->never ())->method ('resizeWindow ' );
82118
83119 $ session ->method ('getDriver ' )->willReturn ($ driver );
0 commit comments