Actualización

This commit is contained in:
Xes
2025-04-10 12:24:57 +02:00
parent 8969cc929d
commit 45420b6f0d
39760 changed files with 4303286 additions and 0 deletions

View File

@@ -0,0 +1,43 @@
<?php
namespace spec\Gaufrette\Adapter;
use AsyncAws\SimpleS3\SimpleS3Client;
use Gaufrette\Adapter\MimeTypeProvider;
use PhpSpec\ObjectBehavior;
class AsyncAwsS3Spec extends ObjectBehavior
{
/**
* @param \AsyncAws\SimpleS3\SimpleS3Client $service
*/
function let(SimpleS3Client $service)
{
$this->beConstructedWith($service, 'bucketName');
}
function it_is_initializable()
{
$this->shouldHaveType('Gaufrette\Adapter\AsyncAwsS3');
}
function it_is_adapter()
{
$this->shouldHaveType('Gaufrette\Adapter');
}
function it_supports_metadata()
{
$this->shouldHaveType('Gaufrette\Adapter\MetadataSupporter');
}
function it_supports_sizecalculator()
{
$this->shouldHaveType('Gaufrette\Adapter\SizeCalculator');
}
function it_provides_mime_type()
{
$this->shouldHaveType(MimeTypeProvider::class);
}
}

View File

@@ -0,0 +1,43 @@
<?php
namespace spec\Gaufrette\Adapter;
use Aws\S3\S3Client;
use Gaufrette\Adapter\MimeTypeProvider;
use PhpSpec\ObjectBehavior;
class AwsS3Spec extends ObjectBehavior
{
/**
* @param \Aws\S3\S3Client $service
*/
function let(S3Client $service)
{
$this->beConstructedWith($service, 'bucketName');
}
function it_is_initializable()
{
$this->shouldHaveType('Gaufrette\Adapter\AwsS3');
}
function it_is_adapter()
{
$this->shouldHaveType('Gaufrette\Adapter');
}
function it_supports_metadata()
{
$this->shouldHaveType('Gaufrette\Adapter\MetadataSupporter');
}
function it_supports_sizecalculator()
{
$this->shouldHaveType('Gaufrette\Adapter\SizeCalculator');
}
function it_provides_mime_type()
{
$this->shouldHaveType(MimeTypeProvider::class);
}
}

View File

@@ -0,0 +1,505 @@
<?php
namespace spec\Gaufrette\Adapter;
use PhpSpec\ObjectBehavior;
use WindowsAzure\Blob\Models\Blob;
use WindowsAzure\Common\ServiceException;
class AzureBlobStorage extends ObjectBehavior
{
/**
* @param \Gaufrette\Adapter\AzureBlobStorage\BlobProxyFactoryInterface $blobProxyFactory
*/
function let($blobProxyFactory)
{
$this->beConstructedWith($blobProxyFactory, 'containerName');
}
function it_should_be_initializable()
{
$this->shouldHaveType('Gaufrette\Adapter\AzureBlobStorage');
$this->shouldHaveType('Gaufrette\Adapter');
$this->shouldHaveType('Gaufrette\Adapter\MetadataSupporter');
}
/**
* @param \Gaufrette\Adapter\AzureBlobStorage\BlobProxyFactoryInterface $blobProxyFactory
* @param \WindowsAzure\Blob\Internal\IBlob $blobProxy
* @param \WindowsAzure\Blob\Models\GetBlobResult $getBlobResult
*/
function it_should_read_file($blobProxyFactory, $blobProxy, $getBlobResult)
{
$getBlobResult
->getContentStream()
->shouldBeCalled()
//azure blob content is handled as stream so we need to fake it
->willReturn(fopen('data://text/plain,some content', 'r'));
$blobProxy
->getBlob('containerName', 'filename')
->shouldBeCalled()
->willReturn($getBlobResult);
$blobProxyFactory
->create()
->shouldBeCalled()
->willReturn($blobProxy);
$this->read('filename')->shouldReturn('some content');
}
/**
* @param \Gaufrette\Adapter\AzureBlobStorage\BlobProxyFactoryInterface $blobProxyFactory
* @param \WindowsAzure\Blob\Internal\IBlob $blobProxy
*/
function it_should_return_false_when_cannot_read($blobProxyFactory, $blobProxy)
{
$blobProxy
->getBlob('containerName', 'filename')
->shouldBeCalled()
->willThrow(new ServiceException(500));
$blobProxyFactory
->create()
->shouldBeCalled()
->willReturn($blobProxy);
$this->read('filename')->shouldReturn(false);
}
/**
* @param \Gaufrette\Adapter\AzureBlobStorage\BlobProxyFactoryInterface $blobProxyFactory
* @param \WindowsAzure\Blob\Internal\IBlob $blobProxy
*/
function it_should_not_mask_exception_when_read($blobProxyFactory, $blobProxy)
{
$blobProxy
->getBlob('containerName', 'filename')
->shouldBeCalled()
->willThrow(new \RuntimeException('read'));
$blobProxyFactory
->create()
->shouldBeCalled()
->willReturn($blobProxy);
$this->shouldThrow(new \RuntimeException('read'))->duringRead('filename');
}
/**
* @param \Gaufrette\Adapter\AzureBlobStorage\BlobProxyFactoryInterface $blobProxyFactory
* @param \WindowsAzure\Blob\Internal\IBlob $blobProxy
*/
function it_should_rename_file($blobProxyFactory, $blobProxy)
{
$blobProxy
->copyBlob('containerName', 'filename2', 'containerName', 'filename1')
->shouldBeCalled();
$blobProxy
->deleteBlob('containerName', 'filename1')
->shouldBeCalled();
$blobProxyFactory
->create()
->shouldBeCalled()
->willReturn($blobProxy);
$this->rename('filename1', 'filename2')->shouldReturn(true);
}
/**
* @param \Gaufrette\Adapter\AzureBlobStorage\BlobProxyFactoryInterface $blobProxyFactory
* @param \WindowsAzure\Blob\Internal\IBlob $blobProxy
*/
function it_should_return_false_when_cannot_rename($blobProxyFactory, $blobProxy)
{
$blobProxy
->copyBlob('containerName', 'filename2', 'containerName', 'filename1')
->shouldBeCalled()
->willThrow(new ServiceException(500));
$blobProxyFactory
->create()
->shouldBeCalled()
->willReturn($blobProxy);
$this->rename('filename1', 'filename2')->shouldReturn(false);
}
/**
* @param \Gaufrette\Adapter\AzureBlobStorage\BlobProxyFactoryInterface $blobProxyFactory
* @param \WindowsAzure\Blob\Internal\IBlob $blobProxy
*/
function it_should_not_mask_exception_when_rename($blobProxyFactory, $blobProxy)
{
$blobProxy
->copyBlob('containerName', 'filename2', 'containerName', 'filename1')
->shouldBeCalled()
->willThrow(new \RuntimeException('rename'));
$blobProxyFactory
->create()
->shouldBeCalled()
->willReturn($blobProxy);
$this->shouldThrow(new \RuntimeException('rename'))->duringRename('filename1', 'filename2');
}
/**
* @param \Gaufrette\Adapter\AzureBlobStorage\BlobProxyFactoryInterface $blobProxyFactory
* @param \WindowsAzure\Blob\Internal\IBlob $blobProxy
*/
function it_should_write_file($blobProxyFactory, $blobProxy)
{
$blobProxy
->createBlockBlob(
'containerName',
'filename',
'some content',
\Mockery::type('\WindowsAzure\Blob\Models\CreateBlobOptions')
)
->shouldBeCalled();
$blobProxyFactory
->create()
->shouldBeCalled()
->willReturn($blobProxy);
$this->write('filename', 'some content')->shouldReturn(12);
}
/**
* @param \Gaufrette\Adapter\AzureBlobStorage\BlobProxyFactoryInterface $blobProxyFactory
* @param \WindowsAzure\Blob\Internal\IBlob $blobProxy
*/
function it_should_return_false_when_cannot_write($blobProxyFactory, $blobProxy)
{
$blobProxy
->createBlockBlob(
'containerName',
'filename',
'some content',
\Mockery::type('\WindowsAzure\Blob\Models\CreateBlobOptions')
)
->willThrow(new ServiceException(500));
$blobProxyFactory
->create()
->shouldBeCalled()
->willReturn($blobProxy);
$this->write('filename', 'some content')->shouldReturn(false);
}
/**
* @param \Gaufrette\Adapter\AzureBlobStorage\BlobProxyFactoryInterface $blobProxyFactory
* @param \WindowsAzure\Blob\Internal\IBlob $blobProxy
*/
function it_should_not_mask_exception_when_write($blobProxyFactory, $blobProxy)
{
$blobProxy
->createBlockBlob(
'containerName',
'filename',
'some content',
\Mockery::type('\WindowsAzure\Blob\Models\CreateBlobOptions')
)
->willThrow(new \RuntimeException('write'));
$blobProxyFactory
->create()
->shouldBeCalled()
->willReturn($blobProxy);
$this->shouldThrow(new \RuntimeException('write'))->duringWrite('filename', 'some content');
}
/**
* @param \Gaufrette\Adapter\AzureBlobStorage\BlobProxyFactoryInterface $blobProxyFactory
* @param \WindowsAzure\Blob\Internal\IBlob $blobProxy
* @param \WindowsAzure\Blob\Models\GetBlobResult $getBlobResult
*/
function it_should_check_if_file_exists($blobProxyFactory, $blobProxy, $getBlobResult)
{
$blobProxyFactory
->create()
->shouldBeCalled()
->willReturn($blobProxy);
$blobProxy
->getBlob('containerName', 'filename')
->shouldBeCalled()
->willThrow(new ServiceException(404));
$this->exists('filename')->shouldReturn(false);
$blobProxy
->getBlob('containerName', 'filename2')
->shouldBeCalled()
->willReturn($getBlobResult);
$this->exists('filename2')->shouldReturn(true);
}
/**
* @param \Gaufrette\Adapter\AzureBlobStorage\BlobProxyFactoryInterface $blobProxyFactory
* @param \WindowsAzure\Blob\Internal\IBlob $blobProxy
*/
function it_should_not_mask_exception_when_check_if_file_exists($blobProxyFactory, $blobProxy)
{
$blobProxyFactory
->create()
->shouldBeCalled()
->willReturn($blobProxy);
$blobProxy
->getBlob('containerName', 'filename')
->shouldBeCalled()
->willThrow(new \RuntimeException('exists'));
$this->shouldThrow(new \RuntimeException('exists'))->duringExists('filename');
}
/**
* @param \Gaufrette\Adapter\AzureBlobStorage\BlobProxyFactoryInterface $blobProxyFactory
* @param \WindowsAzure\Blob\Internal\IBlob $blobProxy
* @param \WindowsAzure\Blob\Models\GetBlobPropertiesResult $getBlobPropertiesResult
* @param \WindowsAzure\Blob\Models\BlobProperties $blobProperties
*/
function it_should_get_file_mtime($blobProxyFactory, $blobProxy, $getBlobPropertiesResult, $blobProperties)
{
$blobProxyFactory
->create()
->shouldBeCalled()
->willReturn($blobProxy);
$blobProxy
->getBlobProperties('containerName', 'filename')
->shouldBeCalled()
->willReturn($getBlobPropertiesResult);
$getBlobPropertiesResult
->getProperties()
->shouldBeCalled()
->willReturn($blobProperties);
$blobProperties
->getLastModified()
->shouldBeCalled()
->willReturn(new \DateTime('1987-12-28 20:00:00'));
$this->mtime('filename')->shouldReturn(strtotime('1987-12-28 20:00:00'));
}
/**
* @param \Gaufrette\Adapter\AzureBlobStorage\BlobProxyFactoryInterface $blobProxyFactory
* @param \WindowsAzure\Blob\Internal\IBlob $blobProxy
*/
function it_should_return_false_when_cannot_mtime($blobProxyFactory, $blobProxy)
{
$blobProxyFactory
->create()
->shouldBeCalled()
->willReturn($blobProxy);
$blobProxy
->getBlobProperties('containerName', 'filename')
->shouldBeCalled()
->willThrow(new ServiceException(500));
$this->mtime('filename')->shouldReturn(false);
}
/**
* @param \Gaufrette\Adapter\AzureBlobStorage\BlobProxyFactoryInterface $blobProxyFactory
* @param \WindowsAzure\Blob\Internal\IBlob $blobProxy
*/
function it_should_not_mask_exception_when_get_mtime($blobProxyFactory, $blobProxy)
{
$blobProxyFactory
->create()
->shouldBeCalled()
->willReturn($blobProxy);
$blobProxy
->getBlobProperties('containerName', 'filename')
->shouldBeCalled()
->willThrow(new \RuntimeException('mtime'));
$this->shouldThrow(new \RuntimeException('mtime'))->duringMtime('filename');
}
/**
* @param \Gaufrette\Adapter\AzureBlobStorage\BlobProxyFactoryInterface $blobProxyFactory
* @param \WindowsAzure\Blob\Internal\IBlob $blobProxy
*/
function it_should_delete_file($blobProxyFactory, $blobProxy)
{
$blobProxyFactory
->create()
->shouldBeCalled()
->willReturn($blobProxy);
$blobProxy
->deleteBlob('containerName', 'filename')
->shouldBeCalled();
$this->delete('filename')->shouldReturn(true);
}
/**
* @param \Gaufrette\Adapter\AzureBlobStorage\BlobProxyFactoryInterface $blobProxyFactory
* @param \WindowsAzure\Blob\Internal\IBlob $blobProxy
*/
function it_should_return_false_when_cannot_delete_file($blobProxyFactory, $blobProxy)
{
$blobProxyFactory
->create()
->shouldBeCalled()
->willReturn($blobProxy);
$blobProxy
->deleteBlob('containerName', 'filename')
->shouldBeCalled()
->willThrow(new ServiceException(500));
$this->delete('filename')->shouldReturn(false);
}
/**
* @param \Gaufrette\Adapter\AzureBlobStorage\BlobProxyFactoryInterface $blobProxyFactory
* @param \WindowsAzure\Blob\Internal\IBlob $blobProxy
*/
function it_should_not_mask_exception_when_delete($blobProxyFactory, $blobProxy)
{
$blobProxyFactory
->create()
->shouldBeCalled()
->willReturn($blobProxy);
$blobProxy
->deleteBlob('containerName', 'filename')
->shouldBeCalled()
->willThrow(new \RuntimeException('delete'));
$this->shouldThrow(new \RuntimeException('delete'))->duringDelete('filename');
}
/**
* @param \Gaufrette\Adapter\AzureBlobStorage\BlobProxyFactoryInterface $blobProxyFactory
* @param \WindowsAzure\Blob\Internal\IBlob $blobProxy
* @param \WindowsAzure\Blob\Models\ListBlobsResult $listBlobResult
*/
function it_should_get_keys($blobProxyFactory, $blobProxy, $listBlobResult)
{
$fileNames = ['aaa', 'aaa/filename', 'filename1', 'filename2'];
$blobs = [];
foreach ($fileNames as $fileName) {
$blob = new Blob();
$blob->setName($fileName);
$blobs[] = $blob;
}
$blobProxyFactory
->create()
->shouldBeCalled()
->willReturn($blobProxy);
$blobProxy
->listBlobs('containerName')
->shouldBeCalled()
->willReturn($listBlobResult);
$listBlobResult
->getBlobs()
->shouldBeCalled()
->willReturn($blobs);
$this->keys()->shouldReturn(['aaa', 'aaa/filename', 'filename1', 'filename2']);
}
/**
* @param \Gaufrette\Adapter\AzureBlobStorage\BlobProxyFactoryInterface $blobProxyFactory
* @param \WindowsAzure\Blob\Internal\IBlob $blobProxy
*/
function it_should_not_mask_exception_when_get_keys($blobProxyFactory, $blobProxy)
{
$blobProxyFactory
->create()
->shouldBeCalled()
->willReturn($blobProxy);
$blobProxy
->listBlobs('containerName')
->shouldBeCalled()
->willThrow(new \RuntimeException('keys'));
$this->shouldThrow(new \RuntimeException('keys'))->duringKeys();
}
/**
* @param \Gaufrette\Adapter\AzureBlobStorage\BlobProxyFactoryInterface $blobProxyFactory
* @param \WindowsAzure\Blob\Internal\IBlob $blobProxy
*/
function it_should_handle_dirs($blobProxyFactory, $blobProxy)
{
$blobProxyFactory
->create()
->shouldBeCalled()
->willReturn($blobProxy);
$blobProxy
->getBlob('containerName', 'filename')
->shouldNotBeCalled();
$blobProxy
->getBlob('containerName', 'filename/')
->shouldBeCalled()
->willThrow(new ServiceException(404));
$blobProxy
->getBlob('containerName', 'dirname/')
->shouldBeCalled();
$this->isDirectory('filename')->shouldReturn(false);
$this->isDirectory('dirname')->shouldReturn(true);
}
/**
* @param \Gaufrette\Adapter\AzureBlobStorage\BlobProxyFactoryInterface $blobProxyFactory
* @param \WindowsAzure\Blob\Internal\IBlob $blobProxy
*/
function it_should_create_container($blobProxyFactory, $blobProxy)
{
$blobProxyFactory
->create()
->shouldBeCalled()
->willReturn($blobProxy);
$blobProxy
->createContainer('containerName', null)
->shouldBeCalled();
$this->createContainer('containerName');
}
/**
* @param \Gaufrette\Adapter\AzureBlobStorage\BlobProxyFactoryInterface $blobProxyFactory
* @param \WindowsAzure\Blob\Internal\IBlob $blobProxy
*/
function it_should_fail_when_cannot_create_container($blobProxyFactory, $blobProxy)
{
$blobProxyFactory
->create()
->shouldBeCalled()
->willReturn($blobProxy);
$blobProxy
->createContainer('containerName', null)
->shouldBeCalled()
->willThrow(new ServiceException(500));
$this->shouldThrow(new \RuntimeException('Failed to create the configured container "containerName": 0 ().', null))->duringCreateContainer('containerName');
}
}

View File

@@ -0,0 +1,22 @@
<?php
namespace spec\Gaufrette\Adapter\AzureBlobStorage;
use PhpSpec\ObjectBehavior;
class BlobProxyFactory extends ObjectBehavior
{
/**
* @param string $connectionString
*/
function let($connectionString)
{
$this->beConstructedWith($connectionString);
}
function it_should_be_initializable()
{
$this->shouldHaveType('Gaufrette\Adapter\AzureBlobStorage\BlobProxyFactory');
$this->shouldHaveType('Gaufrette\Adapter\AzureBlobStorage\BlobProxyFactoryInterface');
}
}

View File

@@ -0,0 +1,270 @@
<?php
namespace spec\Gaufrette\Adapter;
//hack - mock php built-in functions
require_once 'functions.php';
use Doctrine\DBAL\Connection;
use Doctrine\DBAL\Result;
use PhpSpec\ObjectBehavior;
use Prophecy\Argument;
class DoctrineDbalSpec extends ObjectBehavior
{
/**
* @param \Doctrine\DBAL\Connection $connection
*/
function let(Connection $connection)
{
$this->beConstructedWith($connection, 'someTableName');
}
function it_is_adapter()
{
$this->shouldHaveType('Gaufrette\Adapter');
}
function it_is_checksum_calculator()
{
$this->shouldHaveType('Gaufrette\Adapter\ChecksumCalculator');
}
function it_does_not_handle_directories()
{
$this->isDirectory('filename')->shouldReturn(false);
}
/**
* @param \Doctrine\DBAL\Connection $connection
*/
function it_checks_if_file_exists(Connection $connection)
{
$connection
->quoteIdentifier(Argument::any())
->will(function ($argument) {
return sprintf('"%s"', $argument[0]);
});
$method = 'fetchOne'; // dbal 3.x
if (!method_exists(Connection::class, 'fetchAllAssociative')) {
$method = 'fetchColumn'; // BC layer for dbal 2.x
}
$connection
->$method('SELECT COUNT("key") FROM "someTableName" WHERE "key" = :key', ['key' => 'filename'])
->willReturn(12);
$this->exists('filename')->shouldReturn(true);
$connection
->$method('SELECT COUNT("key") FROM "someTableName" WHERE "key" = :key', ['key' => 'filename'])
->willReturn(0);
$this->exists('filename')->shouldReturn(false);
}
/**
* @param \Doctrine\DBAL\Connection $connection
*/
function it_writes_to_new_file(Connection $connection)
{
$connection
->quoteIdentifier(Argument::any())
->will(function ($argument) {
return sprintf('"%s"', $argument[0]);
});
$method = 'fetchOne'; // dbal 3.x
if (!method_exists(Connection::class, 'fetchAllAssociative')) {
$method = 'fetchColumn'; // BC layer for dbal 2.x
}
$connection
->$method('SELECT COUNT("key") FROM "someTableName" WHERE "key" = :key', ['key' => 'filename'])
->willReturn(false);
$connection
->insert(
'someTableName',
[
'"content"' => 'some content',
'"mtime"' => strtotime('2012-10-10 23:10:10'),
'"checksum"' => '9893532233caff98cd083a116b013c0b',
'"key"' => 'filename',
]
)
->shouldBeCalled();
$this->write('filename', 'some content')->shouldReturn(12);
}
/**
* @param \Doctrine\DBAL\Connection $connection
*/
function it_write_file(Connection $connection)
{
$method = 'fetchOne'; // dbal 3.x
if (!method_exists(Connection::class, 'fetchAllAssociative')) {
$method = 'fetchColumn'; // BC layer for dbal 2.x
}
$connection
->quoteIdentifier(Argument::any())
->will(function ($argument) {
return sprintf('"%s"', $argument[0]);
});
$connection
->$method('SELECT COUNT("key") FROM "someTableName" WHERE "key" = :key', ['key' => 'filename'])
->willReturn(true);
$connection
->update(
'someTableName',
[
'"content"' => 'some content',
'"mtime"' => strtotime('2012-10-10 23:10:10'),
'"checksum"' => '9893532233caff98cd083a116b013c0b',
],
[
'"key"' => 'filename',
]
)
->shouldBeCalled();
$this->write('filename', 'some content')->shouldReturn(12);
}
/**
* @param \Doctrine\DBAL\Connection $connection
*/
function it_reads_file(Connection $connection)
{
$method = 'fetchOne'; // dbal 3.x
if (!method_exists(Connection::class, 'fetchAllAssociative')) {
$method = 'fetchColumn'; // BC layer for dbal 2.x
}
$connection
->quoteIdentifier(Argument::any())
->will(function ($argument) {
return sprintf('"%s"', $argument[0]);
});
$connection
->$method('SELECT "content" FROM "someTableName" WHERE "key" = :key', ['key' => 'filename'])
->willReturn('some content');
$this->read('filename')->shouldReturn('some content');
}
/**
* @param \Doctrine\DBAL\Connection $connection
*/
function it_calculates_checksum(Connection $connection)
{
$method = 'fetchOne'; // dbal 3.x
if (!method_exists(Connection::class, 'fetchAllAssociative')) {
$method = 'fetchColumn'; // BC layer for dbal 2.x
}
$connection
->quoteIdentifier(Argument::any())
->will(function ($argument) {
return sprintf('"%s"', $argument[0]);
});
$connection
->$method('SELECT "checksum" FROM "someTableName" WHERE "key" = :key', ['key' => 'filename'])
->willReturn(1234);
$this->checksum('filename')->shouldReturn(1234);
}
/**
* @param \Doctrine\DBAL\Connection $connection
*/
function it_gets_mtime(Connection $connection)
{
$method = 'fetchOne'; // dbal 3.x
if (!method_exists(Connection::class, 'fetchAllAssociative')) {
$method = 'fetchColumn'; // BC layer for dbal 2.x
}
$connection
->quoteIdentifier(Argument::any())
->will(function ($argument) {
return sprintf('"%s"', $argument[0]);
});
$connection
->$method('SELECT "mtime" FROM "someTableName" WHERE "key" = :key', ['key' => 'filename'])
->willReturn(1234);
$this->mtime('filename')->shouldReturn(1234);
}
/**
* @param \Doctrine\DBAL\Connection $connection
*/
function it_renames_file(Connection $connection)
{
$connection
->quoteIdentifier(Argument::any())
->will(function ($argument) {
return sprintf('"%s"', $argument[0]);
});
$connection
->update(
'someTableName',
[
'"key"' => 'newFile',
],
[
'"key"' => 'filename',
]
)
->shouldBeCalled()
->willReturn(1);
$this->rename('filename', 'newFile')->shouldReturn(true);
}
/**
* @param \Doctrine\DBAL\Connection $connection
*/
function it_get_keys(Connection $connection, $result)
{
if (class_exists(Result::class)) {
// dbal 3.x
$result->beADoubleOf(Result::class);
$result->fetchFirstColumn()->willReturn(['filename', 'filename1', 'filename2']);
} else {
// BC layer for dbal 2.x
$result->beADoubleOf(\Doctrine\DBAL\Statement::class);
$result->fetchAll(\PDO::FETCH_COLUMN)->willReturn(['filename', 'filename1', 'filename2']);
}
$connection
->quoteIdentifier(Argument::any())
->will(function ($argument) {
return sprintf('"%s"', $argument[0]);
});
$connection
->executeQuery('SELECT "key" FROM "someTableName"')
->willReturn($result);
$this->keys()->shouldReturn(['filename', 'filename1', 'filename2']);
}
/**
* @param \Doctrine\DBAL\Connection $connection
*/
function it_deletes_file(Connection $connection)
{
$connection
->quoteIdentifier(Argument::any())
->will(function ($argument) {
return sprintf('"%s"', $argument[0]);
});
$connection
->delete('someTableName', ['"key"' => 'filename'])
->shouldBeCalled()
->willReturn(1);
$this->delete('filename')->shouldReturn(true);
}
}

View File

@@ -0,0 +1,106 @@
<?php
namespace spec\Gaufrette\Adapter;
use PhpSpec\ObjectBehavior;
use League\Flysystem\AdapterInterface;
use League\Flysystem\Config;
class FlysystemSpec extends ObjectBehavior
{
function let(AdapterInterface $adapter, Config $config)
{
$this->beConstructedWith($adapter, $config);
}
function it_is_adapter()
{
$this->shouldImplement('Gaufrette\Adapter');
}
function it_is_list_keys_aware()
{
$this->shouldImplement('Gaufrette\Adapter\ListKeysAware');
}
function it_reads_file(AdapterInterface $adapter)
{
$adapter->read('filename')->willReturn(['contents' => 'Hello.']);
$this->read('filename')->shouldReturn('Hello.');
}
function it_writes_file(AdapterInterface $adapter, Config $config)
{
$adapter->write('filename', 'Hello.', $config)->willReturn([]);
$this->write('filename', 'Hello.')->shouldReturn([]);
}
function it_checks_if_file_exists(AdapterInterface $adapter)
{
$adapter->has('filename')->willReturn(true);
$this->exists('filename')->shouldReturn(true);
}
function it_checks_if_file_exists_when_flysystem_returns_array(AdapterInterface $adapter)
{
$adapter->has('filename')->willReturn(['type' => 'file']);
$this->exists('filename')->shouldReturn(true);
}
function it_fetches_keys(AdapterInterface $adapter)
{
$adapter->listContents()->willReturn([[
'path' => 'folder',
'timestamp' => 1457104978,
'size' => 22,
'type' => 'dir',
]]);
$this->keys()->shouldReturn(['folder']);
}
function it_lists_keys(AdapterInterface $adapter)
{
$adapter->listContents()->willReturn([[
'path' => 'folder',
'timestamp' => 1457104978,
'size' => 22,
'type' => 'dir',
]]);
$this->listKeys()->shouldReturn([
'keys' => [],
'dirs' => ['folder'],
]);
}
function it_fetches_mtime(AdapterInterface $adapter)
{
$adapter->getTimestamp('filename')->willReturn(1457104978);
$this->mtime('filename')->shouldReturn(1457104978);
}
function it_deletes_file(AdapterInterface $adapter)
{
$adapter->delete('filename')->willReturn(true);
$this->delete('filename')->shouldReturn(true);
}
function it_renames_file(AdapterInterface $adapter)
{
$adapter->rename('oldfilename', 'newfilename')->willReturn(true);
$this->rename('oldfilename', 'newfilename')->shouldReturn(true);
}
function it_does_not_support_is_directory(AdapterInterface $adapter)
{
$this->shouldThrow('Gaufrette\Exception\UnsupportedAdapterMethodException')->duringisDirectory('folder');
}
}

View File

@@ -0,0 +1,28 @@
<?php
namespace spec\Gaufrette\Adapter;
use PhpSpec\ObjectBehavior;
class GoogleCloudStorageSpec extends ObjectBehavior
{
function let(\Google_Service_Storage $service)
{
$this->beConstructedWith($service, 'bucketName');
}
function it_is_adapter()
{
$this->shouldHaveType('Gaufrette\Adapter');
}
function it_supports_metadata()
{
$this->shouldHaveType('Gaufrette\Adapter\MetadataSupporter');
}
function it_is_list_keys_aware()
{
$this->shouldHaveType('Gaufrette\Adapter\ListKeysAware');
}
}

View File

@@ -0,0 +1,169 @@
<?php
namespace spec\Gaufrette\Adapter;
use MongoDB\BSON\UTCDateTime;
use MongoDB\GridFS\Bucket;
use MongoDB\GridFS\Exception\FileNotFoundException;
use MongoDB\Model\BSONDocument;
use PhpSpec\ObjectBehavior;
class GridFSSpec extends ObjectBehavior
{
private $resources = [];
function let(Bucket $bucket)
{
$this->beConstructedWith($bucket);
}
function letGo()
{
array_map(function ($res) {
if (is_resource($res)) {
@fclose($res);
}
}, $this->resources);
}
function it_is_adapter()
{
$this->shouldHaveType('Gaufrette\Adapter');
}
function it_is_checksum_calculator()
{
$this->shouldHaveType('Gaufrette\Adapter\ChecksumCalculator');
}
function it_supports_metadata()
{
$this->shouldHaveType('Gaufrette\Adapter\MetadataSupporter');
}
function it_supports_native_list_keys()
{
$this->shouldHaveType('Gaufrette\Adapter\ListKeysAware');
}
function it_reads_file($bucket)
{
$this->resources[] = $readable = fopen('php://memory', 'rw');
fwrite($readable, 'some content');
fseek($readable, 0);
$bucket
->openDownloadStreamByName('filename')
->shouldBeCalled()
->willReturn($readable)
;
$this->read('filename')->shouldReturn('some content');
}
function it_does_not_fail_when_cannot_read($bucket)
{
$bucket->openDownloadStreamByName('filename')->willThrow(FileNotFoundException::class);
$this->read('filename')->shouldReturn(false);
}
function it_checks_if_file_exists($bucket, BSONDocument $file)
{
$bucket
->findOne(['filename' => 'filename'])
->willReturn($file)
;
$bucket
->findOne(['filename' => 'filename2'])
->willReturn(null)
;
$this->exists('filename')->shouldReturn(true);
$this->exists('filename2')->shouldReturn(false);
}
function it_deletes_file($bucket)
{
$bucket
->findOne(['filename' => 'filename'], ['projection' => ['_id' => 1]])
->willReturn($file = new BSONDocument(['_id' => 123]))
;
$bucket->delete(123)->shouldBeCalled();
$this->delete('filename')->shouldReturn(true);
}
function it_does_not_delete_file($bucket)
{
$bucket->findOne(['filename' => 'filename'], ['projection' => ['_id' => 1]])->willReturn(null);
$this->delete('filename')->shouldReturn(false);
}
function it_writes_file($bucket)
{
$this->resources[] = $writable = fopen('php://memory', 'rw');
$bucket
->openUploadStream('filename', ['metadata' => ['someother' => 'metadata']])
->willReturn($writable)
;
$this->setMetadata('filename', ['someother' => 'metadata']);
$this
->write('filename', 'some content')
->shouldReturn(12)
;
}
function it_renames_file($bucket)
{
$this->resources[] = $writable = fopen('php://memory', 'rw');
$this->resources[] = $readable = fopen('php://memory', 'rw');
fwrite($readable, 'some content');
fseek($readable, 0);
$bucket->openUploadStream('otherFilename', ['metadata' => ['some' => 'metadata']])->willReturn($writable);
$bucket->downloadToStreamByName('filename', $writable)->shouldBeCalled();
$bucket
->findOne(['filename' => 'filename'], ['projection' => ['_id' => 1]])
->willReturn($toDelete = new BSONDocument(['_id' => 1234]))
;
$bucket->delete(1234)->shouldBeCalled();
$this->setMetadata('filename', ['some' => 'metadata']);
$this->rename('filename', 'otherFilename')->shouldReturn(true);
}
function it_fetches_keys($bucket)
{
$bucket
->find([], ['projection' => ['filename' => 1]])
->willReturn([new BSONDocument(['filename' => 'filename']), new BSONDocument(['filename' => 'otherFilename'])])
;
$this->keys()->shouldReturn(['filename', 'otherFilename']);
}
function it_fetches_mtime($bucket)
{
$bucket
->findOne(['filename' => 'filename'], ['projection' => ['uploadDate' => 1]])
->willReturn(new BSONDocument(['uploadDate' => new UTCDateTime(12345000)]))
;
$this->mtime('filename')->shouldReturn(12345);
}
function it_calculates_checksum($bucket)
{
$bucket
->findOne(['filename' => 'filename'], ['projection' => ['md5' => 1]])
->willReturn(new BSONDocument(['md5' => 'md5123']))
;
$this->checksum('filename')->shouldReturn('md5123');
}
}

View File

@@ -0,0 +1,76 @@
<?php
namespace spec\Gaufrette\Adapter;
use PhpSpec\ObjectBehavior;
class InMemorySpec extends ObjectBehavior
{
function let()
{
$this->beConstructedWith([
'filename' => ['mtime' => 12345, 'content' => 'content'],
'filename2' => 'other content',
]);
}
function it_is_adapter()
{
$this->shouldHaveType('Gaufrette\Adapter');
}
function it_is_a_mime_type_provider()
{
$this->shouldHaveType('Gaufrette\Adapter\MimeTypeProvider');
}
function it_gets_the_file_mime_type()
{
$this->mimeType('filename')->shouldReturn('text/plain');
}
function it_reads_file()
{
$this->read('filename')->shouldReturn('content');
}
function it_writes_file()
{
$this->write('filename', 'some content')->shouldReturn(12);
}
function it_renames_file()
{
$this->rename('filename', 'aaa/filename2')->shouldReturn(true);
$this->exists('filename')->shouldReturn(false);
$this->exists('aaa/filename2')->shouldReturn(true);
}
function it_checks_if_file_exists()
{
$this->exists('filename')->shouldReturn(true);
$this->exists('filenameTest')->shouldReturn(false);
}
function it_fetches_keys()
{
$this->keys()->shouldReturn(['filename', 'filename2']);
}
function it_fetches_mtime()
{
$this->mtime('filename')->shouldReturn(12345);
}
function it_deletes_file()
{
$this->delete('filename')->shouldReturn(true);
$this->exists('filename')->shouldReturn(false);
}
function it_does_not_handle_dirs()
{
$this->isDirectory('filename')->shouldReturn(false);
$this->isDirectory('filename2')->shouldReturn(false);
}
}

View File

@@ -0,0 +1,166 @@
<?php
namespace spec\Gaufrette\Adapter;
use org\bovigo\vfs\vfsStream;
use PhpSpec\ObjectBehavior;
class LocalSpec extends ObjectBehavior
{
function let()
{
vfsStream::setup('test');
vfsStream::copyFromFileSystem(__DIR__ . '/MockFilesystem');
$this->beConstructedWith(vfsStream::url('test'));
}
function it_is_adapter()
{
$this->shouldHaveType('Gaufrette\Adapter');
}
function it_is_checksum_calculator()
{
$this->shouldHaveType('Gaufrette\Adapter\ChecksumCalculator');
}
function it_is_a_mime_type_provider()
{
$this->shouldHaveType('Gaufrette\Adapter\MimeTypeProvider');
}
function it_gets_the_file_mime_type()
{
$this->mimeType('filename')->shouldReturn('text/plain');
}
function it_is_stream_factory()
{
$this->shouldHaveType('Gaufrette\Adapter\StreamFactory');
}
function it_reads_file()
{
$this->read('filename')->shouldReturn("content\n");
}
function it_writes_file()
{
$this->write('filename', 'some content')->shouldReturn(12);
}
function it_renames_file()
{
$this->rename('filename', 'aaa/filename2')->shouldReturn(true);
}
function it_checks_if_file_exists()
{
$this->exists('filename')->shouldReturn(true);
$this->exists('filename1')->shouldReturn(false);
}
function it_fetches_keys()
{
$expectedKeys = ['filename', 'dir', 'dir/file'];
sort($expectedKeys);
$this->keys()->shouldReturn($expectedKeys);
}
function it_fetches_mtime()
{
$mtime = filemtime(vfsStream::url('test/filename'));
$this->mtime('filename')->shouldReturn($mtime);
}
function it_deletes_file()
{
$this->delete('filename')->shouldReturn(true);
$this->delete('filename1')->shouldReturn(false);
}
function it_deletes_dir()
{
$this->delete('dir')->shouldReturn(true);
}
function it_checks_if_given_key_is_directory()
{
$this->isDirectory('dir')->shouldReturn(true);
$this->isDirectory('filename')->shouldReturn(false);
}
function it_creates_local_stream()
{
$this->createStream('filename')->shouldReturnAnInstanceOf('Gaufrette\Stream\Local');
}
function it_does_not_allow_to_read_path_above_main_file_directory()
{
$this
->shouldThrow(new \OutOfBoundsException(sprintf('The path "%s" is out of the filesystem.', vfsStream::url('filename'))))
->duringRead('../filename')
;
$this
->shouldThrow(new \OutOfBoundsException(sprintf('The path "%s" is out of the filesystem.', vfsStream::url('filename'))))
->duringExists('../filename')
;
}
function it_fails_when_directory_does_not_exists()
{
$this->beConstructedWith(vfsStream::url('other'));
$this
->shouldThrow(new \RuntimeException(sprintf('The directory "%s" does not exist.', vfsStream::url('other'))))
->duringRead('filename')
;
$this
->shouldThrow(new \RuntimeException(sprintf('The directory "%s" does not exist.', vfsStream::url('other'))))
->duringWrite('filename', 'some content')
;
$this
->shouldThrow(new \RuntimeException(sprintf('The directory "%s" does not exist.', vfsStream::url('other'))))
->duringRename('filename', 'otherFilename')
;
$this
->shouldThrow(new \RuntimeException(sprintf('The directory "%s" does not exist.', vfsStream::url('other'))))
->duringExists('filename')
;
$this
->shouldThrow(new \RuntimeException(sprintf('The directory "%s" does not exist.', vfsStream::url('other'))))
->duringKeys()
;
$this
->shouldThrow(new \RuntimeException(sprintf('The directory "%s" does not exist.', vfsStream::url('other'))))
->duringMtime('filename')
;
$this
->shouldThrow(new \RuntimeException(sprintf('The directory "%s" does not exist.', vfsStream::url('other'))))
->duringDelete('filename')
;
$this
->shouldThrow(new \RuntimeException(sprintf('The directory "%s" does not exist.', vfsStream::url('other'))))
->duringIsDirectory('filename')
;
$this
->shouldThrow(new \RuntimeException(sprintf('The directory "%s" does not exist.', vfsStream::url('other'))))
->duringCreateStream('filename')
;
$this
->shouldThrow(new \RuntimeException(sprintf('The directory "%s" does not exist.', vfsStream::url('other'))))
->duringChecksum('filename')
;
$this
->shouldThrow(new \RuntimeException(sprintf('The directory "%s" does not exist.', vfsStream::url('other'))))
->duringMimeType('filename')
;
}
function it_creates_directory_when_does_not_exists()
{
$this->beConstructedWith(vfsStream::url('test/other'), true);
$this->isDirectory('/')->shouldReturn(true);
}
}

View File

@@ -0,0 +1 @@
content

View File

@@ -0,0 +1,157 @@
<?php
namespace spec\Gaufrette\Adapter;
if (!defined('NET_SFTP_TYPE_REGULAR')) {
define('NET_SFTP_TYPE_REGULAR', 1);
}
if (!defined('NET_SFTP_TYPE_DIRECTORY')) {
define('NET_SFTP_TYPE_DIRECTORY', 2);
}
use Gaufrette\Filesystem;
use phpseclib\Net\SFTP as Base;
use PhpSpec\ObjectBehavior;
class SFTP extends Base
{
public function __construct()
{
}
}
class PhpseclibSftpSpec extends ObjectBehavior
{
/**
* @param \spec\Gaufrette\Adapter\SFTP $sftp
*/
function let(SFTP $sftp)
{
$this->beConstructedWith($sftp, '/home/l3l0', false, 'l3lo', 'password');
}
function it_is_adapter()
{
$this->shouldHaveType('Gaufrette\Adapter');
}
function it_is_file_factory()
{
$this->shouldHaveType('Gaufrette\Adapter\FileFactory');
}
function it_supports_native_list_keys()
{
$this->shouldHaveType('Gaufrette\Adapter\ListKeysAware');
}
/**
* @param \spec\Gaufrette\Adapter\SFTP $sftp
*/
function it_fetches_keys(SFTP $sftp)
{
$sftp
->file_exists('/home/l3l0/')
->willReturn(true);
$sftp
->rawlist('/home/l3l0/')
->willReturn([
'filename' => ['type' => NET_SFTP_TYPE_REGULAR],
'filename1' => ['type' => NET_SFTP_TYPE_REGULAR],
'aaa' => ['type' => NET_SFTP_TYPE_DIRECTORY],
]);
$sftp
->file_exists('/home/l3l0/aaa')
->willReturn(true);
$sftp
->rawlist('/home/l3l0/aaa')
->willReturn([
'filename' => ['type' => NET_SFTP_TYPE_REGULAR],
]);
$this->keys()->shouldReturn(['filename', 'filename1', 'aaa', 'aaa/filename']);
}
/**
* @param \spec\Gaufrette\Adapter\SFTP $sftp
*/
function it_reads_file(SFTP $sftp)
{
$sftp->get('/home/l3l0/filename')->willReturn('some content');
$this->read('filename')->shouldReturn('some content');
}
/**
* @param \spec\Gaufrette\Adapter\SFTP $sftp
*/
function it_creates_and_writes_file(SFTP $sftp)
{
$sftp->pwd()->willReturn('/home/l3l0');
$sftp->chdir('/home/l3l0')->willReturn(true);
$sftp->put('/home/l3l0/filename', 'some content')->willReturn(true);
$sftp->size('/home/l3l0/filename')->willReturn(12);
$this->write('filename', 'some content')->shouldReturn(12);
}
/**
* @param \spec\Gaufrette\Adapter\SFTP $sftp
*/
function it_renames_file(SFTP $sftp)
{
$sftp->pwd()->willReturn('/home/l3l0');
$sftp->chdir('/home/l3l0')->willReturn(true);
$sftp
->rename('/home/l3l0/filename', '/home/l3l0/filename1')
->willReturn(true)
;
$this->rename('filename', 'filename1')->shouldReturn(true);
}
/**
* @param \spec\Gaufrette\Adapter\SFTP $sftp
*/
function it_should_check_if_file_exists(SFTP $sftp)
{
$sftp->pwd()->willReturn('/home/l3l0');
$sftp->chdir('/home/l3l0')->willReturn(true);
$sftp->stat('/home/l3l0/filename')->willReturn([
'name' => '/home/l3l0/filename',
]);
$sftp->stat('/home/l3l0/filename1')->willReturn(false);
$this->exists('filename')->shouldReturn(true);
$this->exists('filename1')->shouldReturn(false);
}
/**
* @param \spec\Gaufrette\Adapter\SFTP $sftp
*/
function it_should_check_is_directory(SFTP $sftp)
{
$sftp->pwd()->willReturn('/home/l3l0');
$sftp->chdir('/home/l3l0')->willReturn(true);
$sftp->chdir('/home/l3l0/aaa')->willReturn(true);
$sftp->chdir('/home/l3l0/filename')->willReturn(false);
$this->isDirectory('aaa')->shouldReturn(true);
$this->isDirectory('filename')->shouldReturn(false);
}
/**
* @param \spec\Gaufrette\Adapter\SFTP $sftp
* @param \Gaufrette\Filesystem $filesystem
*/
function it_should_create_file(SFTP $sftp, Filesystem $filesystem)
{
$sftp->stat('/home/l3l0/filename')->willReturn([
'name' => '/home/l3l0/filename',
'size' => '30',
]);
$this->createFile('filename', $filesystem)->beAnInstanceOf('Gaufrette\File');
}
}

View File

@@ -0,0 +1,32 @@
<?php
namespace spec\Gaufrette\Adapter;
use org\bovigo\vfs\vfsStream;
use PhpSpec\ObjectBehavior;
class SafeLocalSpec extends ObjectBehavior
{
function let()
{
vfsStream::setup('test');
vfsStream::copyFromFileSystem(__DIR__ . '/MockFilesystem');
$this->beConstructedWith(vfsStream::url('test'));
}
function it_is_local_adapter()
{
$this->shouldHaveType('Gaufrette\Adapter\Local');
}
function it_computes_path_using_base64()
{
rename(vfsStream::url('test/filename'), vfsStream::url('test/' . base64_encode('filename')));
$this->read('filename')->shouldReturn("content\n");
}
function it_computes_key_back_using_base64()
{
$this->keys()->shouldReturn([base64_decode('dir'), base64_decode('dir/file'), base64_decode('filename')]);
}
}

View File

@@ -0,0 +1,18 @@
<?php
namespace spec\Gaufrette\Adapter;
use PhpSpec\ObjectBehavior;
class ZipSpec extends ObjectBehavior
{
function let()
{
$this->beConstructedWith('somefile');
}
function it_is_adapter()
{
$this->shouldHaveType('Gaufrette\Adapter');
}
}

View File

@@ -0,0 +1,68 @@
<?php
namespace Gaufrette\Adapter;
global $createdDirectory;
function time()
{
return \strtotime('2012-10-10 23:10:10');
}
function file_exists($path)
{
//fake it for ssh+ssl: protocol for SFTP testing, otherwise delegate to global
if (strpos($path, 'ssh+ssl:') === 0) {
return in_array($path, ['/home/l3l0/filename', '/home/somedir/filename', 'ssh+ssl://localhost/home/l3l0/filename']) ? true : false;
}
return \file_exists($path);
}
function extension_loaded($name)
{
global $extensionLoaded;
if (is_null($extensionLoaded)) {
return true;
}
return $extensionLoaded;
}
function opendir($url)
{
return true;
}
function apc_fetch($path)
{
return sprintf('%s content', $path);
}
function apc_store($path, $content, $ttl)
{
if ('prefix-apc-test/invalid' === $path) {
return false;
}
return sprintf('%s content', $path);
}
function apc_delete($path)
{
if ('prefix-apc-test/invalid' === $path) {
return false;
}
return true;
}
function apc_exists($path)
{
if ('prefix-apc-test/invalid' === $path) {
return false;
}
return true;
}