-
Notifications
You must be signed in to change notification settings - Fork 69
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #108 from linaori/fix/lazy-factory-recursion
Prevent recursion when the lazy adapter refers to itself
- Loading branch information
Showing
2 changed files
with
59 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the flysystem-bundle project. | ||
* | ||
* (c) Titouan Galopin <[email protected]> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace Tests\League\FlysystemBundle\Lazy; | ||
|
||
use League\Flysystem\InMemory\InMemoryFilesystemAdapter; | ||
use League\FlysystemBundle\Lazy\LazyFactory; | ||
use PHPUnit\Framework\TestCase; | ||
use Symfony\Component\DependencyInjection\ContainerBuilder; | ||
|
||
class LazyFactoryTest extends TestCase | ||
{ | ||
public function testItPreventsInfiniteRecursion(): void | ||
{ | ||
$containerBuilder = new ContainerBuilder(); | ||
$factory = new LazyFactory($containerBuilder); | ||
|
||
$this->expectException(\InvalidArgumentException::class); | ||
$this->expectExceptionMessage('The "lazy" adapter source is referring to itself as "lazy_storage", which would lead to infinite recursion.'); | ||
$factory->createStorage('lazy_storage', 'lazy_storage'); | ||
} | ||
|
||
public function testItErrorsWhenServiceIsNotAvailable(): void | ||
{ | ||
$containerBuilder = new ContainerBuilder(); | ||
$factory = new LazyFactory($containerBuilder); | ||
|
||
$this->expectException(\InvalidArgumentException::class); | ||
$this->expectExceptionMessage('You have requested a non-existent source storage "source_storage" in lazy storage "lazy_storage".'); | ||
$factory->createStorage('source_storage', 'lazy_storage'); | ||
} | ||
|
||
public function testItReturnsTheRequestedStorageService(): void | ||
{ | ||
$actual = new InMemoryFilesystemAdapter(); | ||
$lazy = new InMemoryFilesystemAdapter(); | ||
|
||
$containerBuilder = new ContainerBuilder(); | ||
$containerBuilder->set('source_storage', $actual); | ||
$containerBuilder->set('lazy_storage', $lazy); | ||
|
||
$factory = new LazyFactory($containerBuilder); | ||
|
||
$adapter = $factory->createStorage('source_storage', 'lazy_storage'); | ||
self::assertSame($actual, $adapter); | ||
} | ||
} |