44
55namespace Pest \Browser \Support ;
66
7- use SplFileObject ;
7+ use Pest \ TestSuite ;
88
99/**
1010 * @internal
1111 */
1212final class Screenshot
1313{
14- private const string DEFAULT_DIR = '/tmp/pest-browser-screenshots ' ;
15-
1614 /**
17- * Return the path to the screenshots directory.
15+ * Return the path to the screenshots' directory.
1816 */
1917 public static function dir (): string
2018 {
21- // @phpstan-ignore-next-line
22- return mb_rtrim (( string ) $ _ENV [ ' PEST_BROWSER_SCREENSHOT_DIR ' ] ?? self :: DEFAULT_DIR , ' / ' ) ;
19+ return TestSuite:: getInstance ()-> rootPath
20+ . ' /tests/Browser/screenshots ' ;
2321 }
2422
2523 /**
2624 * Return the full path for a screenshot file.
2725 */
2826 public static function path (string $ filename ): string
2927 {
30- return self ::dir ().'/ ' .mb_ltrim ($ filename , '/ ' ).'.png ' ;
28+ $ filename = self ::dir ().'/ ' .mb_ltrim ($ filename , '/ ' );
29+
30+ // check if there is extension, if not, add .png
31+ if (pathinfo ($ filename , PATHINFO_EXTENSION ) === '' ) {
32+ $ filename .= '.png ' ;
33+ }
34+
35+ return $ filename ;
3136 }
3237
3338 /**
@@ -43,11 +48,10 @@ public static function save(string $binary, ?string $filename = null): void
4348 }
4449
4550 if (is_dir (self ::dir ()) === false ) {
46- mkdir (self ::dir (), 0775 , true );
51+ mkdir (self ::dir (), 0755 , true );
4752 }
4853
49- $ file = new SplFileObject (self ::path ($ filename ), 'wb ' );
50- $ file ->fwrite ($ decodedBinary );
54+ file_put_contents (self ::path ($ filename ), $ decodedBinary );
5155 }
5256
5357 /**
0 commit comments