Skip to content

Commit

Permalink
tests: improve coverage by adding some tests and ignoring some code
Browse files Browse the repository at this point in the history
  • Loading branch information
basz committed Jan 6, 2023
1 parent dfa1c59 commit a4b7fd0
Show file tree
Hide file tree
Showing 24 changed files with 270 additions and 22 deletions.
1 change: 1 addition & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
4 changes: 4 additions & 0 deletions src/Adapter/Factory/AbstractAdapterFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ public function __construct(array $options = [])

/**
* Set creation options.
*
* @codeCoverageIgnore
*/
public function setCreationOptions(array $options): void
{
Expand Down Expand Up @@ -123,6 +125,8 @@ protected function mergeMvcConfig(ContainerInterface $container, string $request

/**
* @throws \InvalidArgumentException
*
* @codeCoverageIgnore
*/
public function getLazyFactory(ContainerInterface $container): LazyLoadingValueHolderFactory
{
Expand Down
18 changes: 3 additions & 15 deletions src/Adapter/Factory/AwsS3v3AdapterFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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 = [
Expand All @@ -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']))) {
Expand Down
3 changes: 3 additions & 0 deletions src/Adapter/Factory/AzureBlobStorageAdapterFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,9 @@ public function doCreateService(ContainerInterface $container): FilesystemAdapte
return new AzureBlobStorageAdapter(...$this->options);
}

/**
* @codeCoverageIgnore
*/
protected function validateConfig(): void
{
\assert(
Expand Down
3 changes: 3 additions & 0 deletions src/Adapter/Factory/DropboxAdapterFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,9 @@ public function doCreateService(ContainerInterface $container): FilesystemAdapte
return new DropboxAdapter(...$this->options);
}

/**
* @codeCoverageIgnore
*/
protected function validateConfig(): void
{
\assert(
Expand Down
3 changes: 3 additions & 0 deletions src/Adapter/Factory/FtpAdapterFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,9 @@ public function doCreateService(ContainerInterface $container): FilesystemAdapte
return new FtpAdapter(...$this->options);
}

/**
* @codeCoverageIgnore
*/
protected function validateConfig(): void
{
\assert(
Expand Down
3 changes: 3 additions & 0 deletions src/Adapter/Factory/GoogleCloudStorageAdapterFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,9 @@ public function doCreateService(ContainerInterface $container): FilesystemAdapte
return new GoogleCloudStorageAdapter(...$this->options);
}

/**
* @codeCoverageIgnore
*/
protected function validateConfig(): void
{
\assert(
Expand Down
3 changes: 3 additions & 0 deletions src/Adapter/Factory/InMemoryAdapterFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -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)) {
Expand Down
3 changes: 3 additions & 0 deletions src/Adapter/Factory/LocalAdapterFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,9 @@ public function doCreateService(ContainerInterface $container): FilesystemAdapte
return new LocalFilesystemAdapter(...$this->options);
}

/**
* @codeCoverageIgnore
*/
protected function validateConfig(): void
{
\assert(
Expand Down
3 changes: 3 additions & 0 deletions src/Adapter/Factory/ReplicateAdapterFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,9 @@ public function doCreateService(ContainerInterface $container): FilesystemAdapte
);
}

/**
* @codeCoverageIgnore
*/
protected function validateConfig(): void
{
\assert(
Expand Down
3 changes: 3 additions & 0 deletions src/Adapter/Factory/SftpAdapterFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,9 @@ public function doCreateService(ContainerInterface $container): FilesystemAdapte
return new SftpAdapter(...$this->options);
}

/**
* @codeCoverageIgnore
*/
protected function validateConfig(): void
{
\assert(
Expand Down
3 changes: 3 additions & 0 deletions src/Adapter/Factory/WebDAVAdapterFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,9 @@ public function doCreateService(ContainerInterface $container): FilesystemAdapte
return new WebDAVAdapter(...$this->options);
}

/**
* @codeCoverageIgnore
*/
protected function validateConfig(): void
{
\assert(
Expand Down
3 changes: 3 additions & 0 deletions src/Adapter/Factory/ZipArchiveAdapterFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,9 @@ public function doCreateService(ContainerInterface $container): FilesystemAdapte
return new ZipArchiveAdapter(...$this->options);
}

/**
* @codeCoverageIgnore
*/
protected function validateConfig(): void
{
\assert(
Expand Down
22 changes: 21 additions & 1 deletion test/Adapter/Factory/AwsS3v3AdapterFactoryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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());

Expand All @@ -58,7 +78,7 @@ public function testGettingFromServiceManager(): void
'version' => 'latest',
],
'bucket' => 'xxxxx',

'visibility' => 'a-visibility',
'mimeTypeDetector' => 'a-mime-type-detector',
]);

Expand Down
53 changes: 53 additions & 0 deletions test/Adapter/Factory/AzureBlobStorageAdapterFactoryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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);
}
}
30 changes: 30 additions & 0 deletions test/Adapter/Factory/DropboxAdapterFactoryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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);
}
}
16 changes: 16 additions & 0 deletions test/Adapter/Factory/FtpAdapterFactoryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
16 changes: 16 additions & 0 deletions test/Adapter/Factory/GoogleCloudStorageAdapterFactoryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
Loading

0 comments on commit a4b7fd0

Please sign in to comment.