Skip to content

Commit

Permalink
Issue #12 Upgrade to PHP 8.1
Browse files Browse the repository at this point in the history
Still Flysystem 1.x but with a minimum PHP version 8.1
  • Loading branch information
judgej committed May 26, 2022
1 parent f734f88 commit e40f9be
Show file tree
Hide file tree
Showing 6 changed files with 118 additions and 73 deletions.
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
vendor/
/vendor
bin
coverage
coverage.xml
composer.lock
/.idea
/.phpunit.result.cache
/.env
9 changes: 7 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -83,5 +83,10 @@ $url = $filesystem->getAdapter()->getUrl('path/to/my/foo.bar');

## Testing

There are no tests yet.
These will be added when time permits.
Set up `.env` and run live tests:

composer install
vendor/bin/phpunit --testsuite flysystem-azure-live-tests

These will create/delete a few test files and directories in the root
of the Azure file share.
9 changes: 5 additions & 4 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,14 @@
}
],
"require": {
"php": ">=7.2.0",
"php": ">=8.1.0",
"league/flysystem": "^1.0.50",
"microsoft/azure-storage-file": "^1.0"
"microsoft/azure-storage-file": "^1.2.5"
},
"require-dev": {
"phpunit/phpunit": "^5.7.25",
"mockery/mockery": "0.9.*"
"phpunit/phpunit": "^9.0",
"mockery/mockery": "^1.5",
"vlucas/phpdotenv": "^5.4"
},
"autoload": {
"psr-4": {
Expand Down
6 changes: 0 additions & 6 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
convertWarningsToExceptions="true"
processIsolation="false"
stopOnFailure="true"
syntaxCheck="true"
defaultTestSuite="flysystem-azure-tests"
>
<testsuites>
Expand All @@ -18,11 +17,6 @@
<file>tests/AzureFileStorageAdapterLiveTest.php</file>
</testsuite>
</testsuites>
<filter>
<whitelist>
<directory suffix=".php">./src/</directory>
</whitelist>
</filter>
<listeners>
<listener class="Mockery\Adapter\Phpunit\TestListener" file="./vendor/mockery/mockery/library/Mockery/Adapter/Phpunit/TestListener.php"></listener>
</listeners>
Expand Down
83 changes: 63 additions & 20 deletions tests/AzureFileStorageAdapterLiveTest.php
Original file line number Diff line number Diff line change
@@ -1,14 +1,17 @@
<?php

use League\Flysystem\Filesystem;
use League\Flysystem\FilesystemInterface;
use Consilience\Flysystem\Azure\AzureFileAdapter;
use Dotenv\Dotenv;
use LogicException;
use phpseclib\System\SSH\Agent;
use PHPUnit\Framework\TestCase;
use League\Flysystem\Filesystem;
use Psr\Http\Message\ResponseInterface;

use MicrosoftAzure\Storage\File\Internal\IFile;
use League\Flysystem\FileExistsException;
use League\Flysystem\FilesystemInterface;
use League\Flysystem\FileNotFoundException;
use MicrosoftAzure\Storage\File\FileRestProxy;
use MicrosoftAzure\Storage\File\Internal\IFile;
use Consilience\Flysystem\Azure\AzureFileAdapter;
use MicrosoftAzure\Storage\Common\Exceptions\ServiceException;

class AzureFileStorageAdapterLiveTest extends TestCase
Expand All @@ -22,6 +25,17 @@ class AzureFileStorageAdapterLiveTest extends TestCase
public const SUBDIR_TWO = 'test-subdir1/test-subdir2';
public const SUBDIR_THREE = 'test-subdir3';

/**
* @fixme does not work here; seems to get reset each test
*/
// public function setUp(): void
// {
// parent::setUp();

// $dotenv = Dotenv::createUnsafeImmutable(__DIR__ . '/..');
// $dotenv->load();
// }

/**
* Provides a live adapter based on config.
* There are three adapters - one with no prefex, one with a single level
Expand All @@ -30,6 +44,13 @@ class AzureFileStorageAdapterLiveTest extends TestCase
*/
public function adapterProvider()
{
// @fixme why does this work here, but not in the setup?
// It's like the environment is cleared after every iteration of a test
// but only set up prior to the first iteration.

$dotenv = Dotenv::createUnsafeImmutable(__DIR__ . '/..');
$dotenv->load();

// Assert that required environment variables are set.
// Will be bool (false) if not set at all.

Expand Down Expand Up @@ -194,33 +215,39 @@ public function testHasFail($filesystem)

/**
* @dataProvider adapterProvider
* @expectedException League\Flysystem\FileExistsException
* @expectedException \League\Flysystem\FileExistsException
*/
public function testWrite($filesystem)
{
// write() will only create new files.
// Try writing again and we get an exception.
// It is unclear what condition triggers a `false` return.

$this->expectException(FileExistsException::class);

foreach ([1, 2] as $attempt) {
$this->assertTrue($filesystem->write(
$this->filename(5),
'content',
['visibility' => 'public'])
);
['visibility' => 'public'],
));
}

$filesystem->delete($this->filename(5));
}

/**
* @dataProvider adapterProvider
* @expectedException League\Flysystem\FileExistsException
* @expectedException \League\Flysystem\FileExistsException
*/
public function testWriteDir($filesystem)
{
// write() will only create new files.
// Try writing again and we get an exception.
// It is unclear what condition triggers a `false` return.

$this->expectException(FileExistsException::class);

foreach ([1, 2] as $attempt) {
$this->assertTrue(
$filesystem->write(
Expand All @@ -242,6 +269,8 @@ public function testWriteDirTwo($filesystem)
// Try writing again and we get an exception.
// It is unclear what condition triggers a `false` return.

$this->expectException(FileExistsException::class);

foreach ([1, 2] as $attempt) {
$this->assertTrue(
$filesystem->write(
Expand All @@ -259,6 +288,8 @@ public function testWriteDirTwo($filesystem)
*/
public function testWriteStream($filesystem)
{
$this->expectException(FileExistsException::class);

foreach ([1, 2] as $attempt) {
$this->assertTrue(
$filesystem->writeStream(
Expand All @@ -281,6 +312,8 @@ public function testWriteStream($filesystem)
*/
public function testWriteStreamDirOne($filesystem)
{
$this->expectException(FileExistsException::class);

foreach ([1, 2] as $attempt) {
$this->assertTrue(
$filesystem->writeStream(
Expand Down Expand Up @@ -310,13 +343,15 @@ public function testDeleteFile($filesystem)

/**
* @dataProvider adapterProvider
* @expectedException League\Flysystem\FileNotFoundException
* @expectedException \League\Flysystem\FileNotFoundException
*/
public function testDeleteFileFail($filesystem)
{
// Deleting again will thow an exception.
// It is flysystem core that does that.

$this->expectException(FileNotFoundException::class);

$this->assertTrue($filesystem->delete($this->filename(8)));
}

Expand All @@ -329,6 +364,8 @@ public function testDeleteFileFailDirOne($filesystem)
// Deleting again will thow an exception.
// It is flysystem core that does that.

$this->expectException(FileNotFoundException::class);

$this->assertTrue($filesystem->delete($this->filename(8, self::SUBDIR_ONE)));
}

Expand Down Expand Up @@ -359,6 +396,8 @@ public function testUpdateFail($filesystem)
// Updating a file that does not exist will throw an exception.
// It is flysystem core that does that.

$this->expectException(FileNotFoundException::class);

$filesystem->update($this->filename(15), 'foobar15');
}

Expand Down Expand Up @@ -391,6 +430,8 @@ public function testSetVisibility($filesystem)
{
// Visibility is not supported by this driver.

$this->expectException(LogicException::class);

$filesystem->setVisibility($this->filename(5), 'public');
}

Expand All @@ -405,6 +446,8 @@ public function testGetVisibility($filesystem)
{
// Visibility is not supported by this driver.

$this->expectException(LogicException::class);

$filesystem->getVisibility($this->filename(5));
}

Expand Down Expand Up @@ -470,10 +513,10 @@ public function testRename($filesystem)
/**
* @dataProvider adapterProvider
*/
public function testDeleteDir($filesystem)
{
// TBC
}
// public function testDeleteDir($filesystem)
// {
// // TBC
// }

/**
* @dataProvider adapterProvider
Expand All @@ -482,7 +525,7 @@ public function testListContents($filesystem)
{
$allContents = $filesystem->listContents('', true);

$this->assertInternalType('array', $allContents);
$this->assertIsArray($allContents);

// Look for the directories and files we have created.

Expand Down Expand Up @@ -521,8 +564,8 @@ public function testListContents($filesystem)
$directory = dirname($this->filename(3, self::SUBDIR_ONE));

$this->assertContains([
'type' => 'dir',
'path' => $directory,
'type' => 'dir',
'dirname' => (dirname($directory) === '.' ? '' : dirname($directory)),
'basename' => basename($directory),
'filename' => basename($directory),
Expand All @@ -531,8 +574,8 @@ public function testListContents($filesystem)
$directory = dirname($this->filename(3, self::SUBDIR_TWO));

$this->assertContains([
'type' => 'dir',
'path' => $directory,
'type' => 'dir',
'dirname' => dirname($directory),
'basename' => basename($directory),
'filename' => basename($directory),
Expand All @@ -542,7 +585,7 @@ public function testListContents($filesystem)

$subdirContents = $filesystem->listContents(self::SUBDIR_TWO, true);

$this->assertInternalType('array', $subdirContents);
$this->assertIsArray($subdirContents);

// The full paths are as for the recursive list, but only comntain the
// two files in the selected direectory.
Expand Down Expand Up @@ -579,7 +622,7 @@ public function testGetMeta($filesystem)
// Note that minetype is the mimetype of the API endpoint, and not
// of the actual file. Some further research may be needed there.

$this->assertInternalType('int', $filesystem->getTimestamp($this->filename(1))); // Unix timetamp
$this->assertIsInt($filesystem->getTimestamp($this->filename(1))); // Unix timetamp
$this->assertSame(7, $filesystem->getSize($this->filename(1))); // "content"
}

Expand All @@ -606,7 +649,7 @@ public function testReadStream($filesystem)
{
$stream = $filesystem->readStream($this->filename(1));

$this->assertInternalType('resource', $stream);
$this->assertIsResource($stream);

$this->assertSame(
'content',
Expand Down
Loading

0 comments on commit e40f9be

Please sign in to comment.