From a4b7fd08131c9934ef756a98d65227c15c3056c9 Mon Sep 17 00:00:00 2001 From: Bas Kamer Date: Fri, 6 Jan 2023 11:56:24 +0100 Subject: [PATCH] tests: improve coverage by adding some tests and ignoring some code --- composer.json | 1 + .../Factory/AbstractAdapterFactory.php | 4 ++ src/Adapter/Factory/AwsS3v3AdapterFactory.php | 18 ++----- .../AzureBlobStorageAdapterFactory.php | 3 ++ src/Adapter/Factory/DropboxAdapterFactory.php | 3 ++ src/Adapter/Factory/FtpAdapterFactory.php | 3 ++ .../GoogleCloudStorageAdapterFactory.php | 3 ++ .../Factory/InMemoryAdapterFactory.php | 3 ++ src/Adapter/Factory/LocalAdapterFactory.php | 3 ++ .../Factory/ReplicateAdapterFactory.php | 3 ++ src/Adapter/Factory/SftpAdapterFactory.php | 3 ++ src/Adapter/Factory/WebDAVAdapterFactory.php | 3 ++ .../Factory/ZipArchiveAdapterFactory.php | 3 ++ .../Factory/AwsS3v3AdapterFactoryTest.php | 22 +++++++- .../AzureBlobStorageAdapterFactoryTest.php | 53 +++++++++++++++++++ .../Factory/DropboxAdapterFactoryTest.php | 30 +++++++++++ .../Adapter/Factory/FtpAdapterFactoryTest.php | 16 ++++++ .../GoogleCloudStorageAdapterFactoryTest.php | 16 ++++++ .../Factory/InMemoryAdapterFactoryTest.php | 16 ++++++ .../Factory/ReplicateAdapterFactoryTest.php | 16 ++++++ .../Factory/SftpAdapterFactoryTest.php | 16 ++++++ .../Factory/WebDAVAdapterFactoryTest.php | 16 ++++++ .../Factory/ZipArchiveAdapterFactoryTest.php | 16 ++++++ test/Services/AdapterManagerTest.php | 22 +++++--- 24 files changed, 270 insertions(+), 22 deletions(-) diff --git a/composer.json b/composer.json index 8ba4e7c..495ebc1 100644 --- a/composer.json +++ b/composer.json @@ -42,6 +42,7 @@ "league/flysystem-webdav": "^3.0", "league/flysystem-ziparchive": "^3.0", "league/mime-type-detection": "^1.11", + "php-mock/php-mock-phpunit": "^2.6", "phpspec/prophecy": "^1.16", "phpunit/phpunit": "^9.4.2", "spatie/flysystem-dropbox": "^2.0" diff --git a/src/Adapter/Factory/AbstractAdapterFactory.php b/src/Adapter/Factory/AbstractAdapterFactory.php index b9985e6..2a20708 100644 --- a/src/Adapter/Factory/AbstractAdapterFactory.php +++ b/src/Adapter/Factory/AbstractAdapterFactory.php @@ -42,6 +42,8 @@ public function __construct(array $options = []) /** * Set creation options. + * + * @codeCoverageIgnore */ public function setCreationOptions(array $options): void { @@ -123,6 +125,8 @@ protected function mergeMvcConfig(ContainerInterface $container, string $request /** * @throws \InvalidArgumentException + * + * @codeCoverageIgnore */ public function getLazyFactory(ContainerInterface $container): LazyLoadingValueHolderFactory { diff --git a/src/Adapter/Factory/AwsS3v3AdapterFactory.php b/src/Adapter/Factory/AwsS3v3AdapterFactory.php index 8b62ec0..90a0aa7 100644 --- a/src/Adapter/Factory/AwsS3v3AdapterFactory.php +++ b/src/Adapter/Factory/AwsS3v3AdapterFactory.php @@ -21,7 +21,6 @@ use Aws\S3\S3Client; use BsbFlysystem\Exception\RequirementsException; -use BsbFlysystem\Exception\UnexpectedValueException; use League\Flysystem\AwsS3V3\AwsS3V3Adapter; use League\Flysystem\FilesystemAdapter; use Psr\Container\ContainerInterface; @@ -35,20 +34,6 @@ public function doCreateService(ContainerInterface $container): FilesystemAdapte } $clientConfig = $this->options['client']; - // [ - // 'region' => $this->options['client']['region'] ?? null, - // 'version' => $this->options['client']['version'] ?? null, - // 'http' => $this->options['client']['request.options'] ?? null, - // ]; - - // Override the endpoint for example: when using an s3 compatible host - // if (! empty($this->options['client']['endpoint'])) { - // $clientConfig['client']['endpoint'] = $this->options['client']['endpoint']; - // } - - // if (! empty($this->options['client']['use_path_style_endpoint'])) { - // $clientConfig['use_path_style_endpoint'] = $this->options['client']['use_path_style_endpoint']; - // } if (! isset($this->options['iam']) || (isset($this->options['iam']) && (false === $this->options['iam']))) { $credentials = [ @@ -71,6 +56,9 @@ public function doCreateService(ContainerInterface $container): FilesystemAdapte return new AwsS3V3Adapter(...$this->options); } + /** + * @codeCoverageIgnore + */ protected function validateConfig(): void { // if (! isset($this->options['iam']) || (isset($this->options['iam']) && (false === $this->options['iam']))) { diff --git a/src/Adapter/Factory/AzureBlobStorageAdapterFactory.php b/src/Adapter/Factory/AzureBlobStorageAdapterFactory.php index 1f48988..eb546ef 100755 --- a/src/Adapter/Factory/AzureBlobStorageAdapterFactory.php +++ b/src/Adapter/Factory/AzureBlobStorageAdapterFactory.php @@ -51,6 +51,9 @@ public function doCreateService(ContainerInterface $container): FilesystemAdapte return new AzureBlobStorageAdapter(...$this->options); } + /** + * @codeCoverageIgnore + */ protected function validateConfig(): void { \assert( diff --git a/src/Adapter/Factory/DropboxAdapterFactory.php b/src/Adapter/Factory/DropboxAdapterFactory.php index 18e9f33..300fd9f 100644 --- a/src/Adapter/Factory/DropboxAdapterFactory.php +++ b/src/Adapter/Factory/DropboxAdapterFactory.php @@ -47,6 +47,9 @@ public function doCreateService(ContainerInterface $container): FilesystemAdapte return new DropboxAdapter(...$this->options); } + /** + * @codeCoverageIgnore + */ protected function validateConfig(): void { \assert( diff --git a/src/Adapter/Factory/FtpAdapterFactory.php b/src/Adapter/Factory/FtpAdapterFactory.php index 3347b67..83bd627 100644 --- a/src/Adapter/Factory/FtpAdapterFactory.php +++ b/src/Adapter/Factory/FtpAdapterFactory.php @@ -54,6 +54,9 @@ public function doCreateService(ContainerInterface $container): FilesystemAdapte return new FtpAdapter(...$this->options); } + /** + * @codeCoverageIgnore + */ protected function validateConfig(): void { \assert( diff --git a/src/Adapter/Factory/GoogleCloudStorageAdapterFactory.php b/src/Adapter/Factory/GoogleCloudStorageAdapterFactory.php index 4073eee..aba5cba 100644 --- a/src/Adapter/Factory/GoogleCloudStorageAdapterFactory.php +++ b/src/Adapter/Factory/GoogleCloudStorageAdapterFactory.php @@ -46,6 +46,9 @@ public function doCreateService(ContainerInterface $container): FilesystemAdapte return new GoogleCloudStorageAdapter(...$this->options); } + /** + * @codeCoverageIgnore + */ protected function validateConfig(): void { \assert( diff --git a/src/Adapter/Factory/InMemoryAdapterFactory.php b/src/Adapter/Factory/InMemoryAdapterFactory.php index ef17cd3..cbce0c3 100644 --- a/src/Adapter/Factory/InMemoryAdapterFactory.php +++ b/src/Adapter/Factory/InMemoryAdapterFactory.php @@ -40,6 +40,9 @@ public function doCreateService(ContainerInterface $container): FilesystemAdapte return new InMemoryFilesystemAdapter(...$this->options); } + /** + * @codeCoverageIgnore + */ protected function validateConfig(): void { if (\array_key_exists('mimeTypeDetector', $this->options)) { diff --git a/src/Adapter/Factory/LocalAdapterFactory.php b/src/Adapter/Factory/LocalAdapterFactory.php index 63b9fa8..f239493 100644 --- a/src/Adapter/Factory/LocalAdapterFactory.php +++ b/src/Adapter/Factory/LocalAdapterFactory.php @@ -38,6 +38,9 @@ public function doCreateService(ContainerInterface $container): FilesystemAdapte return new LocalFilesystemAdapter(...$this->options); } + /** + * @codeCoverageIgnore + */ protected function validateConfig(): void { \assert( diff --git a/src/Adapter/Factory/ReplicateAdapterFactory.php b/src/Adapter/Factory/ReplicateAdapterFactory.php index cdbbf37..83df551 100644 --- a/src/Adapter/Factory/ReplicateAdapterFactory.php +++ b/src/Adapter/Factory/ReplicateAdapterFactory.php @@ -41,6 +41,9 @@ public function doCreateService(ContainerInterface $container): FilesystemAdapte ); } + /** + * @codeCoverageIgnore + */ protected function validateConfig(): void { \assert( diff --git a/src/Adapter/Factory/SftpAdapterFactory.php b/src/Adapter/Factory/SftpAdapterFactory.php index 8739eb7..87245cf 100644 --- a/src/Adapter/Factory/SftpAdapterFactory.php +++ b/src/Adapter/Factory/SftpAdapterFactory.php @@ -50,6 +50,9 @@ public function doCreateService(ContainerInterface $container): FilesystemAdapte return new SftpAdapter(...$this->options); } + /** + * @codeCoverageIgnore + */ protected function validateConfig(): void { \assert( diff --git a/src/Adapter/Factory/WebDAVAdapterFactory.php b/src/Adapter/Factory/WebDAVAdapterFactory.php index a24012f..8f540b3 100644 --- a/src/Adapter/Factory/WebDAVAdapterFactory.php +++ b/src/Adapter/Factory/WebDAVAdapterFactory.php @@ -39,6 +39,9 @@ public function doCreateService(ContainerInterface $container): FilesystemAdapte return new WebDAVAdapter(...$this->options); } + /** + * @codeCoverageIgnore + */ protected function validateConfig(): void { \assert( diff --git a/src/Adapter/Factory/ZipArchiveAdapterFactory.php b/src/Adapter/Factory/ZipArchiveAdapterFactory.php index 39ab225..78c6bb6 100644 --- a/src/Adapter/Factory/ZipArchiveAdapterFactory.php +++ b/src/Adapter/Factory/ZipArchiveAdapterFactory.php @@ -46,6 +46,9 @@ public function doCreateService(ContainerInterface $container): FilesystemAdapte return new ZipArchiveAdapter(...$this->options); } + /** + * @codeCoverageIgnore + */ protected function validateConfig(): void { \assert( diff --git a/test/Adapter/Factory/AwsS3v3AdapterFactoryTest.php b/test/Adapter/Factory/AwsS3v3AdapterFactoryTest.php index 72e051c..fea2a0e 100644 --- a/test/Adapter/Factory/AwsS3v3AdapterFactoryTest.php +++ b/test/Adapter/Factory/AwsS3v3AdapterFactoryTest.php @@ -21,13 +21,30 @@ use Aws\Command; use BsbFlysystem\Adapter\Factory\AwsS3v3AdapterFactory; +use BsbFlysystem\Exception\RequirementsException; use BsbFlysystemTest\Bootstrap; use League\Flysystem\AwsS3V3\AwsS3V3Adapter; +use League\Flysystem\AwsS3V3\VisibilityConverter; use League\MimeTypeDetection\MimeTypeDetector; +use phpmock\phpunit\PHPMock; use Psr\Container\ContainerInterface; class AwsS3v3AdapterFactoryTest extends BaseAdapterFactory { + use PHPMock; + + public function testClassExists(): void + { + $classExists = $this->getFunctionMock('BsbFlysystem\Adapter\Factory', 'class_exists'); + $classExists->expects($this->once())->willReturn(false); + + $factory = new AwsS3v3AdapterFactory(); + $container = $this->prophet->prophesize(ContainerInterface::class); + + $this->expectException(RequirementsException::class); + $factory->doCreateService($container->reveal()); + } + public function testCreateService(): void { $sm = Bootstrap::getServiceManager(); @@ -45,6 +62,9 @@ public function testGettingFromServiceManager(): void $container = $this->prophet->prophesize(ContainerInterface::class); $container->has('config')->willReturn(false); + $visibility = $this->prophet->prophesize(VisibilityConverter::class); + $container->get('a-visibility')->willReturn($visibility->reveal()); + $mimeTypeDetector = $this->prophet->prophesize(MimeTypeDetector::class); $container->get('a-mime-type-detector')->willReturn($mimeTypeDetector->reveal()); @@ -58,7 +78,7 @@ public function testGettingFromServiceManager(): void 'version' => 'latest', ], 'bucket' => 'xxxxx', - + 'visibility' => 'a-visibility', 'mimeTypeDetector' => 'a-mime-type-detector', ]); diff --git a/test/Adapter/Factory/AzureBlobStorageAdapterFactoryTest.php b/test/Adapter/Factory/AzureBlobStorageAdapterFactoryTest.php index 31e88cf..6c13f57 100644 --- a/test/Adapter/Factory/AzureBlobStorageAdapterFactoryTest.php +++ b/test/Adapter/Factory/AzureBlobStorageAdapterFactoryTest.php @@ -20,13 +20,29 @@ namespace BsbFlysystemTest\Adapter\Factory; use BsbFlysystem\Adapter\Factory\AzureBlobStorageAdapterFactory; +use BsbFlysystem\Exception\RequirementsException; use League\Flysystem\AzureBlobStorage\AzureBlobStorageAdapter; use League\MimeTypeDetection\MimeTypeDetector; use MicrosoftAzure\Storage\Blob\BlobRestProxy; +use phpmock\phpunit\PHPMock; use Psr\Container\ContainerInterface; class AzureBlobStorageAdapterFactoryTest extends BaseAdapterFactory { + use PHPMock; + + public function testClassExists(): void + { + $classExists = $this->getFunctionMock('BsbFlysystem\Adapter\Factory', 'class_exists'); + $classExists->expects($this->once())->willReturn(false); + + $factory = new AzureBlobStorageAdapterFactory(); + $container = $this->prophet->prophesize(ContainerInterface::class); + + $this->expectException(RequirementsException::class); + $factory->doCreateService($container->reveal()); + } + public function testGettingFromServiceManager(): void { $factory = new AzureBlobStorageAdapterFactory(); @@ -48,4 +64,41 @@ public function testGettingFromServiceManager(): void $this->assertInstanceOf(AzureBlobStorageAdapter::class, $adapter); } + + public function testClientOptions(): void + { + $factory = new AzureBlobStorageAdapterFactory(); + + $container = $this->prophet->prophesize(ContainerInterface::class); + $container->has('config')->willReturn(false); + + $adapter = $factory($container->reveal(), 'azureblobstorage_default', [ + 'container' => 'xxx', + 'client' => ['connectionString' => 'DefaultEndpointsProtocol=https;AccountName=xxx;AccountKey=xxx'], + ]); + + $this->assertInstanceOf(AzureBlobStorageAdapter::class, $adapter); + } + + public function testServiceSettingsOptions(): void + { + $factory = new AzureBlobStorageAdapterFactory(); + + $container = $this->prophet->prophesize(ContainerInterface::class); + $container->has('config')->willReturn(false); + + $adapter = $factory($container->reveal(), 'azureblobstorage_default', [ + 'container' => 'xxx', + 'client' => ['connectionString' => 'DefaultEndpointsProtocol=https;AccountName=xxx;AccountKey=xxx'], + 'serviceSettings' => [ + 'name' => 'xxx', + 'key' => 'xxx', + 'blobEndpointUri' => 'https://xxx.blob.core.windows.net/', + 'queueEndpointUri' => 'https://xxx.queue.core.windows.net/', + 'tableEndpointUri' => 'https://xxx.table.core.windows.net/', + 'fileEndpointUri' => 'https://xxx.file.core.windows.net/', ], + ]); + + $this->assertInstanceOf(AzureBlobStorageAdapter::class, $adapter); + } } diff --git a/test/Adapter/Factory/DropboxAdapterFactoryTest.php b/test/Adapter/Factory/DropboxAdapterFactoryTest.php index fcd70bc..67adcd5 100644 --- a/test/Adapter/Factory/DropboxAdapterFactoryTest.php +++ b/test/Adapter/Factory/DropboxAdapterFactoryTest.php @@ -20,12 +20,28 @@ namespace BsbFlysystemTest\Adapter\Factory; use BsbFlysystem\Adapter\Factory\DropboxAdapterFactory; +use BsbFlysystem\Exception\RequirementsException; use League\MimeTypeDetection\MimeTypeDetector; +use phpmock\phpunit\PHPMock; use Psr\Container\ContainerInterface; use Spatie\FlysystemDropbox\DropboxAdapter; class DropboxAdapterFactoryTest extends BaseAdapterFactory { + use PHPMock; + + public function testClassExists(): void + { + $classExists = $this->getFunctionMock('BsbFlysystem\Adapter\Factory', 'class_exists'); + $classExists->expects($this->once())->willReturn(false); + + $factory = new DropboxAdapterFactory(); + $container = $this->prophet->prophesize(ContainerInterface::class); + + $this->expectException(RequirementsException::class); + $factory->doCreateService($container->reveal()); + } + public function testGettingFromServiceManager(): void { $factory = new DropboxAdapterFactory(); @@ -46,4 +62,18 @@ public function testGettingFromServiceManager(): void $this->assertInstanceOf(DropboxAdapter::class, $adapter); } + + public function testClientOptionsAsArray(): void + { + $factory = new DropboxAdapterFactory(); + + $container = $this->prophet->prophesize(ContainerInterface::class); + $container->has('config')->willReturn(false); + + $adapter = $factory($container->reveal(), 'dropbox_default', [ + 'client' => ['accessTokenOrAppCredentials' => 'string'], + ]); + + $this->assertInstanceOf(DropboxAdapter::class, $adapter); + } } diff --git a/test/Adapter/Factory/FtpAdapterFactoryTest.php b/test/Adapter/Factory/FtpAdapterFactoryTest.php index 67ade0b..e4236ea 100644 --- a/test/Adapter/Factory/FtpAdapterFactoryTest.php +++ b/test/Adapter/Factory/FtpAdapterFactoryTest.php @@ -20,15 +20,31 @@ namespace BsbFlysystemTest\Adapter\Factory; use BsbFlysystem\Adapter\Factory\FtpAdapterFactory; +use BsbFlysystem\Exception\RequirementsException; use League\Flysystem\Ftp\ConnectivityChecker; use League\Flysystem\Ftp\FtpAdapter; use League\Flysystem\Ftp\FtpConnectionProvider; use League\Flysystem\UnixVisibility\VisibilityConverter; use League\MimeTypeDetection\MimeTypeDetector; +use phpmock\phpunit\PHPMock; use Psr\Container\ContainerInterface; class FtpAdapterFactoryTest extends BaseAdapterFactory { + use PHPMock; + + public function testClassExists(): void + { + $classExists = $this->getFunctionMock('BsbFlysystem\Adapter\Factory', 'class_exists'); + $classExists->expects($this->once())->willReturn(false); + + $factory = new FtpAdapterFactory(); + $container = $this->prophet->prophesize(ContainerInterface::class); + + $this->expectException(RequirementsException::class); + $factory->doCreateService($container->reveal()); + } + public function testGettingFromServiceManager(): void { $factory = new FtpAdapterFactory(); diff --git a/test/Adapter/Factory/GoogleCloudStorageAdapterFactoryTest.php b/test/Adapter/Factory/GoogleCloudStorageAdapterFactoryTest.php index 29cecc9..c201a29 100644 --- a/test/Adapter/Factory/GoogleCloudStorageAdapterFactoryTest.php +++ b/test/Adapter/Factory/GoogleCloudStorageAdapterFactoryTest.php @@ -20,14 +20,30 @@ namespace BsbFlysystemTest\Adapter\Factory; use BsbFlysystem\Adapter\Factory\GoogleCloudStorageAdapterFactory; +use BsbFlysystem\Exception\RequirementsException; use Google\Cloud\Storage\Bucket; use League\Flysystem\GoogleCloudStorage\GoogleCloudStorageAdapter; use League\Flysystem\GoogleCloudStorage\VisibilityHandler; use League\MimeTypeDetection\MimeTypeDetector; +use phpmock\phpunit\PHPMock; use Psr\Container\ContainerInterface; class GoogleCloudStorageAdapterFactoryTest extends BaseAdapterFactory { + use PHPMock; + + public function testClassExists(): void + { + $classExists = $this->getFunctionMock('BsbFlysystem\Adapter\Factory', 'class_exists'); + $classExists->expects($this->once())->willReturn(false); + + $factory = new GoogleCloudStorageAdapterFactory(); + $container = $this->prophet->prophesize(ContainerInterface::class); + + $this->expectException(RequirementsException::class); + $factory->doCreateService($container->reveal()); + } + public function testGettingFromServiceManager(): void { $factory = new GoogleCloudStorageAdapterFactory(); diff --git a/test/Adapter/Factory/InMemoryAdapterFactoryTest.php b/test/Adapter/Factory/InMemoryAdapterFactoryTest.php index 29f85a7..b04587e 100644 --- a/test/Adapter/Factory/InMemoryAdapterFactoryTest.php +++ b/test/Adapter/Factory/InMemoryAdapterFactoryTest.php @@ -20,12 +20,28 @@ namespace BsbFlysystemTest\Adapter\Factory; use BsbFlysystem\Adapter\Factory\InMemoryAdapterFactory; +use BsbFlysystem\Exception\RequirementsException; use League\Flysystem\InMemory\InMemoryFilesystemAdapter; use League\MimeTypeDetection\MimeTypeDetector; +use phpmock\phpunit\PHPMock; use Psr\Container\ContainerInterface; class InMemoryAdapterFactoryTest extends BaseAdapterFactory { + use PHPMock; + + public function testClassExists(): void + { + $classExists = $this->getFunctionMock('BsbFlysystem\Adapter\Factory', 'class_exists'); + $classExists->expects($this->once())->willReturn(false); + + $factory = new InMemoryAdapterFactory(); + $container = $this->prophet->prophesize(ContainerInterface::class); + + $this->expectException(RequirementsException::class); + $factory->doCreateService($container->reveal()); + } + public function testGettingFromServiceManager(): void { $factory = new InMemoryAdapterFactory(); diff --git a/test/Adapter/Factory/ReplicateAdapterFactoryTest.php b/test/Adapter/Factory/ReplicateAdapterFactoryTest.php index 91b453e..52e2518 100644 --- a/test/Adapter/Factory/ReplicateAdapterFactoryTest.php +++ b/test/Adapter/Factory/ReplicateAdapterFactoryTest.php @@ -21,12 +21,28 @@ use Ajgl\Flysystem\Replicate\ReplicateFilesystemAdapter; use BsbFlysystem\Adapter\Factory\ReplicateAdapterFactory; +use BsbFlysystem\Exception\RequirementsException; use BsbFlysystem\Service\AdapterManager; use League\Flysystem\FilesystemAdapter; +use phpmock\phpunit\PHPMock; use Psr\Container\ContainerInterface; class ReplicateAdapterFactoryTest extends BaseAdapterFactory { + use PHPMock; + + public function testClassExists(): void + { + $classExists = $this->getFunctionMock('BsbFlysystem\Adapter\Factory', 'class_exists'); + $classExists->expects($this->once())->willReturn(false); + + $factory = new ReplicateAdapterFactory(); + $container = $this->prophet->prophesize(ContainerInterface::class); + + $this->expectException(RequirementsException::class); + $factory->doCreateService($container->reveal()); + } + public function testGettingFromServiceManager(): void { $factory = new ReplicateAdapterFactory(); diff --git a/test/Adapter/Factory/SftpAdapterFactoryTest.php b/test/Adapter/Factory/SftpAdapterFactoryTest.php index 3310fa6..0f7d3f2 100644 --- a/test/Adapter/Factory/SftpAdapterFactoryTest.php +++ b/test/Adapter/Factory/SftpAdapterFactoryTest.php @@ -20,14 +20,30 @@ namespace BsbFlysystemTest\Adapter\Factory; use BsbFlysystem\Adapter\Factory\SftpAdapterFactory; +use BsbFlysystem\Exception\RequirementsException; use League\Flysystem\PhpseclibV3\ConnectivityChecker; use League\Flysystem\PhpseclibV3\SftpAdapter; use League\Flysystem\UnixVisibility\VisibilityConverter; use League\MimeTypeDetection\MimeTypeDetector; +use phpmock\phpunit\PHPMock; use Psr\Container\ContainerInterface; class SftpAdapterFactoryTest extends BaseAdapterFactory { + use PHPMock; + + public function testClassExists(): void + { + $classExists = $this->getFunctionMock('BsbFlysystem\Adapter\Factory', 'class_exists'); + $classExists->expects($this->once())->willReturn(false); + + $factory = new SftpAdapterFactory(); + $container = $this->prophet->prophesize(ContainerInterface::class); + + $this->expectException(RequirementsException::class); + $factory->doCreateService($container->reveal()); + } + public function testGettingFromServiceManager(): void { $factory = new SftpAdapterFactory(); diff --git a/test/Adapter/Factory/WebDAVAdapterFactoryTest.php b/test/Adapter/Factory/WebDAVAdapterFactoryTest.php index a49595a..12905be 100644 --- a/test/Adapter/Factory/WebDAVAdapterFactoryTest.php +++ b/test/Adapter/Factory/WebDAVAdapterFactoryTest.php @@ -20,11 +20,27 @@ namespace BsbFlysystemTest\Adapter\Factory; use BsbFlysystem\Adapter\Factory\WebDAVAdapterFactory; +use BsbFlysystem\Exception\RequirementsException; use League\Flysystem\WebDAV\WebDAVAdapter; +use phpmock\phpunit\PHPMock; use Psr\Container\ContainerInterface; class WebDAVAdapterFactoryTest extends BaseAdapterFactory { + use PHPMock; + + public function testClassExists(): void + { + $classExists = $this->getFunctionMock('BsbFlysystem\Adapter\Factory', 'class_exists'); + $classExists->expects($this->once())->willReturn(false); + + $factory = new WebDAVAdapterFactory(); + $container = $this->prophet->prophesize(ContainerInterface::class); + + $this->expectException(RequirementsException::class); + $factory->doCreateService($container->reveal()); + } + public function testGettingFromServiceManager(): void { $factory = new WebDAVAdapterFactory(); diff --git a/test/Adapter/Factory/ZipArchiveAdapterFactoryTest.php b/test/Adapter/Factory/ZipArchiveAdapterFactoryTest.php index 9b821fe..7b4d630 100644 --- a/test/Adapter/Factory/ZipArchiveAdapterFactoryTest.php +++ b/test/Adapter/Factory/ZipArchiveAdapterFactoryTest.php @@ -20,13 +20,29 @@ namespace BsbFlysystemTest\Adapter\Factory; use BsbFlysystem\Adapter\Factory\ZipArchiveAdapterFactory; +use BsbFlysystem\Exception\RequirementsException; use League\Flysystem\UnixVisibility\VisibilityConverter; use League\Flysystem\ZipArchive\ZipArchiveAdapter; use League\MimeTypeDetection\MimeTypeDetector; +use phpmock\phpunit\PHPMock; use Psr\Container\ContainerInterface; class ZipArchiveAdapterFactoryTest extends BaseAdapterFactory { + use PHPMock; + + public function testClassExists(): void + { + $classExists = $this->getFunctionMock('BsbFlysystem\Adapter\Factory', 'class_exists'); + $classExists->expects($this->once())->willReturn(false); + + $factory = new ZipArchiveAdapterFactory(); + $container = $this->prophet->prophesize(ContainerInterface::class); + + $this->expectException(RequirementsException::class); + $factory->doCreateService($container->reveal()); + } + public function testGettingFromServiceManager(): void { $factory = new ZipArchiveAdapterFactory(); diff --git a/test/Services/AdapterManagerTest.php b/test/Services/AdapterManagerTest.php index 2d8fd18..a72a265 100644 --- a/test/Services/AdapterManagerTest.php +++ b/test/Services/AdapterManagerTest.php @@ -23,6 +23,8 @@ use BsbFlysystem\Service\AdapterManager; use BsbFlysystemTest\Bootstrap; use Laminas\ServiceManager\ServiceManager; +use League\Flysystem\PathPrefixing\PathPrefixedAdapter; +use League\Flysystem\ReadOnly\ReadOnlyFilesystemAdapter; use PHPUnit\Framework\TestCase; class AdapterManagerTest extends TestCase @@ -66,11 +68,19 @@ public function testCreateViaServiceManagerLocal(): void $this->assertInstanceOf(\League\Flysystem\FilesystemAdapter::class, $manager->get('local_default')); } - // public function testCreateViaServiceManagerNull(): void - // { - // $sm = Bootstrap::getServiceManager(); - // $manager = $sm->get(AdapterManager::class); + public function testWrapsPathPrefixedAdapter(): void + { + $sm = Bootstrap::getServiceManager(); + $adapter = $sm->get(AdapterManager::class)->get('local_default', ['prefix' => '/path']); + + $this->assertInstanceOf(PathPrefixedAdapter::class, $adapter); + } - // $this->assertInstanceOf(\League\Flysystem\Adapter\NullAdapter::class, $manager->get('null_default')); - // } + public function testWrapsReadOnlyFilesystemAdapter(): void + { + $sm = Bootstrap::getServiceManager(); + $adapter = $sm->get(AdapterManager::class)->get('local_default', ['readonly' => true]); + + $this->assertInstanceOf(ReadOnlyFilesystemAdapter::class, $adapter); + } }