Skip to content

Commit aba84f6

Browse files
committed
fork and upgrade vfs adapter dependencies for laravel 10
1 parent f3b4f12 commit aba84f6

10 files changed

+99
-128
lines changed

.coveralls.yml

Whitespace-only changes.

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,4 @@ vendor
22
.idea
33
build
44
composer.lock
5+
.phpunit.result.cache

.travis.yml

Lines changed: 0 additions & 22 deletions
This file was deleted.

composer.json

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -32,16 +32,16 @@
3232
},
3333
"minimum-stability": "stable",
3434
"require": {
35-
"php": ">=7.0.0",
36-
"league/flysystem": "^1.0",
37-
"illuminate/support": "^5.1 || ^6.0 || ^7.0",
35+
"php": "^8.0",
36+
"league/flysystem": "^3.0.0",
37+
"illuminate/support": "^5.1 || ^6.0 || ^7.0 || ^9.0 || ^10.0",
3838
"mikey179/vfsstream": "^1.6"
3939
},
4040
"require-dev": {
41-
"phpunit/phpunit": "~6.0",
41+
"phpunit/phpunit": "~9.0",
4242
"symfony/var-dumper": "^3",
4343
"ext-fileinfo": "*",
4444
"mockery/mockery": "~1.0",
45-
"phpspec/phpspec": "^2.2"
45+
"phpspec/phpspec": "^7.2"
4646
}
4747
}

phpunit.xml

Lines changed: 21 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,22 @@
11
<?xml version="1.0" encoding="UTF-8"?>
2-
<phpunit backupGlobals="false"
3-
backupStaticAttributes="false"
4-
bootstrap="tests/bootstrap.php"
5-
colors="true"
6-
convertErrorsToExceptions="true"
7-
convertNoticesToExceptions="true"
8-
convertWarningsToExceptions="true"
9-
processIsolation="false"
10-
stopOnFailure="false"
11-
syntaxCheck="false">
12-
<testsuites>
13-
<testsuite name="Library Test Suite">
14-
<directory suffix=".php">./tests/Adapter</directory>
15-
</testsuite>
16-
</testsuites>
17-
<filter>
18-
<blacklist>
19-
</blacklist>
20-
<whitelist>
21-
<directory suffix=".php">src/</directory>
22-
</whitelist>
23-
</filter>
24-
<php>
25-
<env name="APP_ENV" value="testing"/>
26-
</php>
27-
<logging>
28-
<log type="coverage-text" target="php://stdout" showUncoveredFiles="true"/>
29-
<log type="coverage-html" target="build/html/coverage" showUncoveredFiles="true"/>
30-
<log type="coverage-clover" target="build/logs/coverage.xml" showUncoveredFiles="true"/>
31-
</logging>
32-
<listeners>
33-
<listener class="Mockery\Adapter\Phpunit\TestListener" file="./vendor/mockery/mockery/library/Mockery/Adapter/Phpunit/TestListener.php"></listener>
34-
</listeners>
35-
</phpunit>
2+
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" backupGlobals="false" backupStaticAttributes="false" bootstrap="tests/bootstrap.php" colors="true" convertErrorsToExceptions="true" convertNoticesToExceptions="true" convertWarningsToExceptions="true" processIsolation="false" stopOnFailure="false" xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.3/phpunit.xsd">
3+
<coverage>
4+
<report>
5+
<clover outputFile="build/logs/coverage.xml"/>
6+
<html outputDirectory="build/html/coverage"/>
7+
<text outputFile="php://stdout" showUncoveredFiles="true"/>
8+
</report>
9+
</coverage>
10+
<testsuites>
11+
<testsuite name="Library Test Suite">
12+
<directory suffix=".php">./tests/Adapter</directory>
13+
</testsuite>
14+
</testsuites>
15+
<php>
16+
<env name="APP_ENV" value="testing"/>
17+
</php>
18+
<logging/>
19+
<listeners>
20+
<listener class="Mockery\Adapter\Phpunit\TestListener" file="./vendor/mockery/mockery/library/Mockery/Adapter/Phpunit/TestListener.php"/>
21+
</listeners>
22+
</phpunit>

src/VfsFilesystemServiceProvider.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
/**
88
* @codeCoverageIgnore
99
*/
10-
class VfsFilesystemServiceProvider extends ServiceProvider {
10+
class VfsFilesystemServiceProvider extends ServiceProvider {
1111

1212
//boot
1313
public function boot()
@@ -33,4 +33,4 @@ public function register()
3333
}
3434

3535

36-
}
36+
}

src/VirtualFilesystemAdapter.php

Lines changed: 23 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@
22

33
use Illuminate\Support\Collection;
44
use Illuminate\Support\Str;
5-
use League\Flysystem\Adapter\Local;
5+
use League\Flysystem\Local\LocalFilesystemAdapter;
6+
use League\Flysystem\UnixVisibility\PortableVisibilityConverter;
67
use org\bovigo\vfs\vfsStream;
78
use org\bovigo\vfs\vfsStreamDirectory;
89
use SplFileInfo;
@@ -20,7 +21,8 @@
2021
* @property int $link_handling
2122
* @property array $dirStructure
2223
*/
23-
class VirtualFilesystemAdapter extends Local {
24+
class VirtualFilesystemAdapter extends LocalFilesystemAdapter
25+
{
2426

2527
/**
2628
* This adapters configuration
@@ -33,21 +35,21 @@ class VirtualFilesystemAdapter extends Local {
3335
* @var array
3436
*/
3537
protected $defaultConfig = [
36-
'dir_name' => 'root',
38+
'dir_name' => 'root',
3739
'dir_permissions' => 0755,
38-
'dir_structure' => [],
39-
'write_flags' => LOCK_EX,
40-
'link_handling' => self::DISALLOW_LINKS,
41-
'permissions' => [
40+
'dir_structure' => [],
41+
'write_flags' => 0, //LOCAK_EX doesn't work in this scenario
42+
'link_handling' => self::DISALLOW_LINKS,
43+
'permissions' => [
4244
'file' => [
43-
'public' => 0644,
45+
'public' => 0644,
4446
'private' => 0600,
4547
],
46-
'dir' => [
47-
'public' => 0755,
48+
'dir' => [
49+
'public' => 0755,
4850
'private' => 0700,
49-
]
50-
]
51+
],
52+
],
5153
];
5254

5355
/**
@@ -63,7 +65,8 @@ public function __construct(array $config = [])
6365
{
6466
$this->config = collect(array_replace_recursive($this->defaultConfig, $config));
6567
$this->vfsStreamDir = vfsStream::setup($this->dirName, $this->dirPermissions, $this->dirStructure);
66-
parent::__construct($this->vfsStreamDir->url(), $this->writeFlags, $this->linkHandling, $this->permissions);
68+
69+
parent::__construct($this->vfsStreamDir->url(), PortableVisibilityConverter::fromArray($this->permissions), $this->writeFlags, $this->linkHandling);
6770
}
6871

6972
/**
@@ -93,7 +96,7 @@ public function __get($name)
9396
{
9497
$response = $this->config->get(Str::snake($name));
9598

96-
if (is_null($response)){
99+
if (is_null($response)) {
97100
throw new \InvalidArgumentException(sprintf('%s is not a valid field.', $name));
98101
}
99102

@@ -116,29 +119,27 @@ public function getVfsStreamDir()
116119
* @return void
117120
* @throws \Exception in case the root directory can not be created
118121
*/
119-
protected function ensureDirectory($path)
122+
protected function ensureDirectoryExists(string $dirname, int $visibility): void
120123
{
121-
if ($path === $this->dirName){
124+
if ($dirname === $this->dirName) {
122125
// @codeCoverageIgnoreStart
123126
return;
124127
// @codeCoverageIgnoreEnd
125128
}
126-
parent::ensureDirectory($path);
129+
parent::ensureDirectoryExists($dirname, $visibility);
127130
}
128131

129132
/**
130133
* vfsStream has issues with SplFileInfo::getRealPath(), so we will just use
131134
* SplFileInfo::getPathname()
132135
* @param SplFileInfo $file
133136
*/
134-
protected function deleteFileInfoObject(SplFileInfo $file)
137+
protected function deleteFileInfoObject(SplFileInfo $file): bool
135138
{
136139
if ($file->getType() === 'dir') {
137-
rmdir($file->getPathname());
138-
139-
return;
140+
return @rmdir($file->getPathname());
140141
}
141142

142-
unlink($file->getPathname());
143+
return @unlink($file->getPathname());
143144
}
144145
}

tests/Adapter/BasicTest.php

Lines changed: 22 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
<?php namespace STS\Filesystem;
22

33
use Illuminate\Support\Str;
4-
use League\Flysystem\Adapter\Local;
4+
use League\Flysystem\FileAttributes;
5+
use League\Flysystem\Local\LocalFilesystemAdapter;
56
use League\Flysystem\Filesystem;
7+
use League\Flysystem\StorageAttributes;
68
use org\bovigo\vfs\vfsStream;
79
use PHPUnit\Framework\TestCase;
810

@@ -13,7 +15,7 @@ class BasicTest extends TestCase {
1315
'dir_permissions' => 0700,
1416
'dir_structure' => [],
1517
'write_flags' => 0,
16-
'link_handling' => Local::DISALLOW_LINKS,
18+
'link_handling' => LocalFilesystemAdapter::DISALLOW_LINKS,
1719
'permissions' => [
1820
'file' => [
1921
'public' => 0660,
@@ -71,26 +73,27 @@ public function throws_exception_on_bad_parameter(){
7173

7274
/** @test */
7375
public function setup_new_vfs_directory_structure(){
74-
$filesystem = new Filesystem(new VirtualFilesystemAdapter());
75-
$filesystem->put('foo/bar/tile1.txt', 'FooBar');
76+
$filesystem = new Filesystem($adapter = new VirtualFilesystemAdapter());
77+
$filesystem->write('foo/bar/tile1.txt', 'FooBar');
7678

7779
$expected_1 = [
7880
"type" => "file",
7981
"path" => "foo/bar/tile1.txt",
8082
"timestamp" => 1488331955,
81-
"size" => 6,
82-
"dirname" => "foo/bar",
83-
"basename" => "tile1.txt",
84-
"extension" => "txt",
85-
"filename" => "tile1",
83+
"file_size" => 6,
84+
//"dirname" => "foo/bar",
85+
//"basename" => "tile1.txt",
86+
//"extension" => "txt",
87+
//"filename" => "tile1",
8688
];
87-
$actual_1 = $filesystem->listContents('foo/bar')[0];
89+
$actual_1 = $filesystem->listContents('foo/bar')->toArray()[0];
8890

8991
collect($expected_1)->each(
9092
function ($value, $key) use ($actual_1) {
9193
if ($key === 'timestamp'){
9294
return;
9395
}
96+
/** @var FileAttributes $actual_1 */
9497
$this->assertEquals($value, $actual_1[$key]);
9598
}
9699
);
@@ -107,26 +110,26 @@ function ($value, $key) use ($actual_1) {
107110
]
108111
];
109112

110-
$config = $filesystem->getAdapter()->getConfig();
113+
$config = $adapter->getConfig();
111114
$config['dir_structure'] = $newStructure;
112115
vfsStream::setup($config['dir_name'], $config['dir_permissions'], $config['dir_structure']);
113116
// Ensure the old file system is gone.
114-
$this->assertFalse($filesystem->has('foo/bar'));
117+
$this->assertFalse($filesystem->fileExists('foo/bar'));
115118

116-
$this->assertTrue($filesystem->has('Core/AbstractFactory/test.php'));
119+
$this->assertTrue($filesystem->fileExists('Core/AbstractFactory/test.php'));
117120
$this->assertEquals('some other text content', $filesystem->read('Core/AbstractFactory/other.php'));
118121
$this->assertEquals('some bad voodoo', $filesystem->read('Core/somethingwicked.php'));
119122
}
120123

121124
/** @test */
122125
public function setup_new_vfs_from_local_filesystem()
123126
{
124-
$filesystem = new Filesystem(new VirtualFilesystemAdapter());
125-
vfsStream::copyFromFileSystem(__DIR__ . '/../resources/filesystemcopy', $filesystem->getAdapter()->getVfsStreamDir(), 3145728);
127+
$filesystem = new Filesystem($adapter = new VirtualFilesystemAdapter());
128+
vfsStream::copyFromFileSystem(__DIR__ . '/../resources/filesystemcopy', $adapter->getVfsStreamDir(), 3145728);
126129

127-
$this->assertTrue($filesystem->has('withSubfolders/subfolder2/multipage2.pdf'));
128-
$this->assertEquals('application/pdf', $filesystem->getMimetype('withSubfolders/subfolder2/multipage2.pdf'));
129-
$this->assertEquals('image/tiff', $filesystem->getMimetype('withSubfolders/subfolder2/one.TIF'));
130-
$this->assertEquals('571382', $filesystem->getSize('withSubfolders/subfolder2/singlepage1.pdf'));
130+
$this->assertTrue($filesystem->fileExists('withSubfolders/subfolder2/multipage2.pdf'));
131+
$this->assertEquals('application/pdf', $filesystem->mimetype('withSubfolders/subfolder2/multipage2.pdf'));
132+
$this->assertEquals('image/tiff', $filesystem->mimetype('withSubfolders/subfolder2/one.TIF'));
133+
$this->assertEquals('571382', $filesystem->fileSize('withSubfolders/subfolder2/singlepage1.pdf'));
131134
}
132135
}

tests/Adapter/FailTests.php renamed to tests/STS/Filesystem/FailTests.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,17 @@
44
{
55
function file_put_contents($name)
66
{
7-
if (strpos($name, 'pleasefail') !== false) {
7+
if (str_contains($name, 'pleasefail')) {
88
return false;
99
}
10-
return call_user_func_array('file_put_contents', func_get_args());
10+
return file_put_contents(...func_get_args());
1111
}
1212
function file_get_contents($name)
1313
{
14-
if (strpos($name, 'pleasefail') !== false) {
14+
if (str_contains($name, 'pleasefail')) {
1515
return false;
1616
}
17-
return call_user_func_array('file_get_contents', func_get_args());
17+
return file_get_contents(...func_get_args());
1818
}
1919
}
2020

@@ -30,7 +30,7 @@ public function ensure_we_fail_on_all_of_these()
3030
{
3131
$adapter = new VirtualFilesystemAdapter();
3232
$this->assertFalse($adapter->write('pleasefail.txt', 'content', new Config()));
33-
$this->assertFalse($adapter->update('pleasefail.txt', 'content', new Config()));
33+
$this->assertFalse($adapter->write('pleasefail.txt', 'content', new Config()));
3434
$this->assertFalse($adapter->read('pleasefail.txt'));
3535
$this->assertFalse($adapter->deleteDir('non-existing'));
3636
}

0 commit comments

Comments
 (0)