22
33declare (strict_types=1 );
44
5- namespace Solution ;
5+ namespace PhpSchool \ PhpWorkshopTest \ Solution ;
66
77use PhpSchool \PhpWorkshop \Solution \InTempSolutionMapper ;
88use PhpSchool \PhpWorkshop \Utils \Path ;
9+ use PhpSchool \PhpWorkshop \Utils \System ;
910use PHPUnit \Framework \TestCase ;
1011
1112class InTempSolutionMapperTest extends TestCase
1213{
1314 public function testFileMapping (): void
1415 {
15- $ filePath = Path:: join ( realpath ( sys_get_temp_dir ()), 'test.file ' );
16+ $ filePath = System:: tempDir ( 'test.file ' );
1617 touch ($ filePath );
1718
1819 $ mappedFile = InTempSolutionMapper::mapFile ($ filePath );
1920
2021 self ::assertFileExists ($ mappedFile );
2122 self ::assertNotSame ($ filePath , $ mappedFile );
22- self ::assertStringContainsString (realpath ( sys_get_temp_dir () ), $ mappedFile );
23+ self ::assertStringContainsString (System:: tempDir ( ), $ mappedFile );
2324 }
2425
2526 public function testDirectoryMapping (): void
2627 {
27- $ tempDir = Path:: join ( realpath ( sys_get_temp_dir ()), bin2hex (random_bytes (10 )));
28+ $ tempDir = System:: tempDir ( bin2hex (random_bytes (10 )));
2829 $ file = Path::join ($ tempDir , 'test.file ' );
2930 $ inner = Path::join ($ tempDir , 'innerDir ' );
3031 $ innerFile = Path::join ($ inner , 'test.file ' );
@@ -45,39 +46,39 @@ public function testDirectoryMapping(): void
4546
4647 public function testMappingIsDeterministicTempDir (): void
4748 {
48- $ filePath = Path:: join ( realpath ( sys_get_temp_dir ()), 'test.file ' );
49+ $ filePath = System:: tempDir ( 'test.file ' );
4950 touch ($ filePath );
5051
5152 $ dirName = bin2hex (random_bytes (10 ));
52- $ tempDir = Path:: join ( realpath ( sys_get_temp_dir ()), $ dirName );
53+ $ tempDir = System:: tempDir ( $ dirName );
5354 @mkdir ($ tempDir );
5455
5556 $ fileHash = md5 ($ filePath );
5657 $ dirHash = md5 ($ tempDir );
5758
5859 self ::assertSame (
5960 InTempSolutionMapper::mapFile ($ filePath ),
60- Path::join (realpath ( sys_get_temp_dir () ), 'php-school ' , $ fileHash , 'test.file ' )
61+ Path::join (System:: tempDir ( ), 'php-school ' , $ fileHash , 'test.file ' )
6162 );
6263
6364 self ::assertNotSame (
6465 InTempSolutionMapper::mapDirectory ($ tempDir ),
65- Path::join (realpath ( sys_get_temp_dir () ), 'php-school ' , $ dirHash , $ dirName )
66+ Path::join (System:: tempDir ( ), 'php-school ' , $ dirHash , $ dirName )
6667 );
6768 }
6869
6970 public function testContentsAreNotOverwroteIfExists (): void
7071 {
71- $ filePath = Path:: join ( realpath ( sys_get_temp_dir ()), 'test.file ' );
72+ $ filePath = System:: tempDir ( 'test.file ' );
7273 file_put_contents ($ filePath , 'Old contents ' );
7374
7475 $ dirName = bin2hex (random_bytes (10 ));
75- $ tempDir = Path:: join ( realpath ( sys_get_temp_dir ()), $ dirName );
76+ $ tempDir = System:: tempDir ( $ dirName );
7677 mkdir ($ tempDir );
7778 file_put_contents (Path::join ($ tempDir , 'test.file ' ), 'Old contents ' );
7879
79- $ tempFilePath = Path::join (realpath ( sys_get_temp_dir () ), 'php-school ' , md5 ($ filePath ), 'test.file ' );
80- $ tempDirPath = Path::join (realpath ( sys_get_temp_dir () ), 'php-school ' , md5 ($ tempDir ), $ dirName );
80+ $ tempFilePath = Path::join (System:: tempDir ( ), 'php-school ' , md5 ($ filePath ), 'test.file ' );
81+ $ tempDirPath = Path::join (System:: tempDir ( ), 'php-school ' , md5 ($ tempDir ), $ dirName );
8182
8283 file_put_contents ($ tempFilePath , 'Fresh contents ' );
8384 mkdir ($ tempDirPath , 0777 , true );
0 commit comments