diff --git a/composer.json b/composer.json index 0e51ffd98..bc956b021 100644 --- a/composer.json +++ b/composer.json @@ -39,7 +39,8 @@ "phpbench/phpbench": "^0.16.10", "infection/infection": "^0.15.0", "symfony/console": "^4.4.2", - "vimeo/psalm": "3.7.0" + "vimeo/psalm": "3.7.0", + "mikey179/vfsstream": "^1.6.8" }, "suggest": { "ocramius/generated-hydrator": "To have very fast object to array to object conversion for ghost objects", diff --git a/src/ProxyManager/FileLocator/FileLocator.php b/src/ProxyManager/FileLocator/FileLocator.php index e9c2cbf23..abff30bb8 100644 --- a/src/ProxyManager/FileLocator/FileLocator.php +++ b/src/ProxyManager/FileLocator/FileLocator.php @@ -6,6 +6,7 @@ use ProxyManager\Exception\InvalidProxyDirectoryException; use const DIRECTORY_SEPARATOR; +use function is_dir; use function realpath; use function str_replace; @@ -24,10 +25,12 @@ public function __construct(string $proxiesDirectory) $absolutePath = realpath($proxiesDirectory); if ($absolutePath === false) { - throw InvalidProxyDirectoryException::proxyDirectoryNotFound($proxiesDirectory); + if (! is_dir($proxiesDirectory)) { + throw InvalidProxyDirectoryException::proxyDirectoryNotFound($proxiesDirectory); + } } - $this->proxiesDirectory = $absolutePath; + $this->proxiesDirectory = $absolutePath ?: $proxiesDirectory; } /** diff --git a/tests/ProxyManagerTest/FileLocator/FileLocatorTest.php b/tests/ProxyManagerTest/FileLocator/FileLocatorTest.php index 3efcd412d..58447bc6c 100644 --- a/tests/ProxyManagerTest/FileLocator/FileLocatorTest.php +++ b/tests/ProxyManagerTest/FileLocator/FileLocatorTest.php @@ -4,6 +4,7 @@ namespace ProxyManagerTest\FileLocator; +use org\bovigo\vfs\vfsStream; use PHPUnit\Framework\TestCase; use ProxyManager\Exception\InvalidProxyDirectoryException; use ProxyManager\FileLocator\FileLocator; @@ -36,4 +37,16 @@ public function testRejectsNonExistingDirectory() : void $this->expectException(InvalidProxyDirectoryException::class); new FileLocator(__DIR__ . '/non-existing'); } + + /** + * @covers \ProxyManager\FileLocator\FileLocator::__construct + */ + public function testStreamWrappersSupported() : void + { + $vfs = vfsStream::setup('root', null, ['dir' => []]); + $path = $vfs->url() . '/dir'; + $locator = new FileLocator($path); + self::assertSame($path . DIRECTORY_SEPARATOR . 'FooBarBaz.php', $locator->getProxyFileName('Foo\\Bar\\Baz')); + self::assertSame($path . DIRECTORY_SEPARATOR . 'Foo_Bar_Baz.php', $locator->getProxyFileName('Foo_Bar_Baz')); + } }