rootDir); } public function setUp(): void { $this->rootDir = uniqid(sys_get_temp_dir() . DIRECTORY_SEPARATOR . 'test-file-inside-directory', true) . DIRECTORY_SEPARATOR; mkdir($this->rootDir); mkdir($this->rootDir . 'directoryname'); mkdir($this->rootDir . 'FOO'); touch($this->rootDir . 'directoryname/filename'); touch($this->rootDir . 'secure_file'); } public function fileInsideDirectoryDataProvider() { return [ ['filename', 'directoryname', true], ['./filename', 'directoryname', true], ['../secure_file', 'directoryname', false], ['../directoryname/filename', 'directoryname', true], ['../directoryname/../FOO/../directoryname/filename', 'FOO/../directoryname', true], ['../FOO/../directoryname/filename', 'FOO/../directoryname', true], ['directoryname/../filename', 'directoryname', false], ['NON-EXISTING_FILE', 'directoryname', false], ['filename', 'NON-EXISTING_DIRECTORY', false], ]; } /** * @dataProvider fileInsideDirectoryDataProvider */ public function testIsFileInsideDirectory($filename, $directoryName, bool $isInside) { $this->assertEquals(\helpers_File::isFileInsideDirectory($filename, $this->rootDir . $directoryName), $isInside); } }