From 5f75d3aca9478302d8427353c67671a30210e80b Mon Sep 17 00:00:00 2001 From: Jonathan Vollebregt Date: Fri, 12 Jul 2024 13:59:42 +0200 Subject: [PATCH] SplFileInfoRepresentationTest: Remove further references to __FILE__ Using a source file from git causes inconsistencies in testing if the perms are changed by the dev --- .../SplFileInfoRepresentationTest.php | 44 ++++++++++--------- 1 file changed, 24 insertions(+), 20 deletions(-) diff --git a/tests/Zval/Representation/SplFileInfoRepresentationTest.php b/tests/Zval/Representation/SplFileInfoRepresentationTest.php index 29bc6d6de..7d8550914 100644 --- a/tests/Zval/Representation/SplFileInfoRepresentationTest.php +++ b/tests/Zval/Representation/SplFileInfoRepresentationTest.php @@ -49,8 +49,9 @@ protected function setUp(): void \ini_set('open_basedir', \realpath(__DIR__.'/../../../').':/dev:/tmp'); + \touch(__DIR__.'/testFile'); \symlink(\dirname(__DIR__), __DIR__.'/testDirLink'); - \symlink(__FILE__, __DIR__.'/testFileLink'); + \symlink(__DIR__.'/testFile', __DIR__.'/testFileLink'); \symlink(__DIR__.'/testDirLink', __DIR__.'/testDirLink2'); \symlink(__DIR__.'/testFileLink', __DIR__.'/testFileLink2'); @@ -70,6 +71,7 @@ protected function tearDown(): void \unlink(__DIR__.'/testFileLink2'); \unlink(__DIR__.'/testDirLink'); \unlink(__DIR__.'/testFileLink'); + \unlink(__DIR__.'/testFile'); \unlink(__DIR__.'/testPipe'); @@ -82,27 +84,29 @@ protected function tearDown(): void */ public function testConstructFile() { - $r = new SplFileInfoRepresentation(new SplFileInfo(__FILE__)); + $f = __DIR__.'/testFile'; + + $r = new SplFileInfoRepresentation(new SplFileInfo($f)); - $this->assertSame(\filesize(__FILE__), $r->size); - $this->assertSame(\filectime(__FILE__), $r->ctime); - $this->assertSame(\filemtime(__FILE__), $r->mtime); - $this->assertSame(\fileperms(__FILE__), $r->perms); - $this->assertSame(\fileowner(__FILE__), $r->owner); - $this->assertSame(\filegroup(__FILE__), $r->group); + $this->assertSame(\filesize($f), $r->size); + $this->assertSame(\filectime($f), $r->ctime); + $this->assertSame(\filemtime($f), $r->mtime); + $this->assertSame(\fileperms($f), $r->perms); + $this->assertSame(\fileowner($f), $r->owner); + $this->assertSame(\filegroup($f), $r->group); $this->assertSame('File', $r->typename); $this->assertSame('-', $r->typeflag); - $this->assertSame(__FILE__, $r->path); - $this->assertSame(__FILE__, $r->realpath); + $this->assertSame($f, $r->path); + $this->assertSame($f, $r->realpath); $this->assertNull($r->linktarget); - $this->assertSame(\str_split('-rw-r--r--'), $r->flags); + $this->assertSame(\str_split('-rw-rw-rw-'), $r->flags); - if ('file' === \filetype(__FILE__)) { + if ('file' === \filetype($f)) { $this->assertTrue($r->is_file); $this->assertFalse($r->is_dir); $this->assertFalse($r->is_link); } else { - throw new UnexpectedValueException(__FILE__.' type is not "file"'); + throw new UnexpectedValueException($f.' type is not "file"'); } } @@ -124,9 +128,9 @@ public function testConstructFileLink() $this->assertSame('File symlink', $r->typename); $this->assertSame('l', $r->typeflag); $this->assertSame($f, $r->path); - $this->assertSame(__FILE__, $r->realpath); + $this->assertSame(__DIR__.'/testFile', $r->realpath); $this->assertSame(__DIR__.'/testFileLink', $r->linktarget); - $this->assertSame(\str_split('lrw-r--r--'), $r->flags); + $this->assertSame(\str_split('lrw-rw-rw-'), $r->flags); if ('link' === \filetype($f)) { $this->assertTrue($r->is_file); @@ -142,7 +146,7 @@ public function testConstructFileLink() */ public function testConstructLinkedFile() { - $f = __DIR__.'/testDirLink/'.\basename(__DIR__).'/'.\basename(__FILE__); + $f = __DIR__.'/testDirLink/'.\basename(__DIR__).'/testFile'; $r = new SplFileInfoRepresentation(new SplFileInfo($f)); @@ -155,9 +159,9 @@ public function testConstructLinkedFile() $this->assertSame('File', $r->typename); $this->assertSame('-', $r->typeflag); $this->assertSame($f, $r->path); - $this->assertSame(__FILE__, $r->realpath); + $this->assertSame(__DIR__.'/testFile', $r->realpath); $this->assertNull($r->linktarget); - $this->assertSame(\str_split('-rw-r--r--'), $r->flags); + $this->assertSame(\str_split('-rw-rw-rw-'), $r->flags); if ('file' === \filetype($f)) { $this->assertTrue($r->is_file); @@ -401,8 +405,8 @@ public function testConstructBlockDevice() $mock->getCTime()->willReturn($ctime = \time()); $mock->getMTime()->willReturn($mtime = \time()); $mock->getPerms()->willReturn($perms = 0x6444); - $mock->getOwner()->willReturn($owner = \fileowner(__FILE__)); - $mock->getGroup()->willReturn($group = \filegroup(__FILE__)); + $mock->getOwner()->willReturn($owner = \getmyuid()); + $mock->getGroup()->willReturn($group = \getmyuid()); $mock->getPathname()->willReturn($f); $mock->getRealPath()->willReturn($f); $mock->isDir()->willReturn(false);