Skip to content

Commit

Permalink
Added stream wrapper support to FileLocator
Browse files Browse the repository at this point in the history
This pr allows the FileLocator to support stream wrappers.
  • Loading branch information
Bittarman committed Jan 27, 2020
1 parent 20cd371 commit 9353637
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 3 deletions.
3 changes: 2 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
7 changes: 5 additions & 2 deletions src/ProxyManager/FileLocator/FileLocator.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

use ProxyManager\Exception\InvalidProxyDirectoryException;
use const DIRECTORY_SEPARATOR;
use function is_dir;
use function realpath;
use function str_replace;

Expand All @@ -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;
}

/**
Expand Down
13 changes: 13 additions & 0 deletions tests/ProxyManagerTest/FileLocator/FileLocatorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

namespace ProxyManagerTest\FileLocator;

use org\bovigo\vfs\vfsStream;
use PHPUnit\Framework\TestCase;
use ProxyManager\Exception\InvalidProxyDirectoryException;
use ProxyManager\FileLocator\FileLocator;
Expand Down Expand Up @@ -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'));
}
}

0 comments on commit 9353637

Please sign in to comment.