public static function findHereOrInParent($frag, $start, SystemLocals $locals = null) { if (!is_string($frag)) { throw new \InvalidArgumentException('Frag must be a string'); } if (!is_string($start)) { throw new \InvalidArgumentException('Start must be a string'); } if (empty($locals)) { $locals = new SystemLocals(); } $start = self::homeify($start, $locals); if (!file_exists($start)) { throw new \InvalidArgumentException('Start must be a valid path to a file or directory'); } if (!is_dir($start)) { $start = dirname($start); } $dir = PathUtils::untrailslashit($start); $frag = PathUtils::unleadslashit($frag); while (!file_exists($dir . DIRECTORY_SEPARATOR . $frag) && '/' !== $dir) { $dir = dirname($dir); } return $dir == '/' ? false : realpath($dir . DIRECTORY_SEPARATOR . $frag); }
/** * @test * it should allow untrailslash paths * @dataProvider untrailslashPaths */ public function it_should_allow_untrailslash_paths($path, $expected) { $this->assertEquals($expected, PathUtils::untrailslashit($path)); }