6
6
use Cake \TestSuite \TestCase ;
7
7
use Josegonzalez \Upload \File \Writer \DefaultWriter ;
8
8
use Laminas \Diactoros \UploadedFile ;
9
- use League \Flysystem \Adapter \NullAdapter ;
10
- use League \Flysystem \Vfs \VfsAdapter ;
9
+ use League \Flysystem \InMemory \InMemoryFilesystemAdapter ;
10
+ use League \Flysystem \UnableToDeleteFile ;
11
+ use League \Flysystem \UnableToMoveFile ;
12
+ use League \Flysystem \UnableToWriteFile ;
11
13
use VirtualFileSystem \FileSystem as Vfs ;
12
14
13
15
class DefaultWriterTest extends TestCase
@@ -29,7 +31,7 @@ public function setUp(): void
29
31
$ this ->settings = [
30
32
'filesystem ' => [
31
33
'adapter ' => function () {
32
- return new VfsAdapter ( new Vfs () );
34
+ return new InMemoryFilesystemAdapter ( );
33
35
},
34
36
],
35
37
];
@@ -65,9 +67,9 @@ public function testInvoke()
65
67
66
68
public function testDelete ()
67
69
{
68
- $ filesystem = $ this ->getMockBuilder ('League\Flysystem\FilesystemInterface ' )->getMock ();
69
- $ filesystem ->expects ($ this ->at (0 ))->method ('delete ' )-> will ( $ this -> returnValue ( true )) ;
70
- $ filesystem ->expects ($ this ->at (1 ))->method ('delete ' )->will ($ this ->returnValue ( false ));
70
+ $ filesystem = $ this ->getMockBuilder ('League\Flysystem\FilesystemOperator ' )->getMock ();
71
+ $ filesystem ->expects ($ this ->at (0 ))->method ('delete ' );
72
+ $ filesystem ->expects ($ this ->at (1 ))->method ('delete ' )->will ($ this ->throwException ( new UnableToDeleteFile () ));
71
73
$ writer = $ this ->getMockBuilder ('Josegonzalez\Upload\File\Writer\DefaultWriter ' )
72
74
->setMethods (['getFilesystem ' ])
73
75
->setConstructorArgs ([$ this ->table , $ this ->entity , $ this ->data , $ this ->field , $ this ->settings ])
@@ -86,51 +88,51 @@ public function testDelete()
86
88
87
89
public function testWriteFile ()
88
90
{
89
- $ filesystem = $ this ->getMockBuilder ('League\Flysystem\FilesystemInterface ' )->getMock ();
90
- $ filesystem ->expects ($ this ->once ())->method ('writeStream ' )-> will ( $ this -> returnValue ( true )) ;
91
- $ filesystem ->expects ($ this ->exactly (3 ))->method ('delete ' )-> will ( $ this -> returnValue ( true )) ;
92
- $ filesystem ->expects ($ this ->once ())->method ('rename ' )-> will ( $ this -> returnValue ( true ) );
91
+ $ filesystem = $ this ->getMockBuilder ('League\Flysystem\FilesystemOperator ' )->getMock ();
92
+ $ filesystem ->expects ($ this ->once ())->method ('writeStream ' );
93
+ $ filesystem ->expects ($ this ->exactly (3 ))->method ('delete ' );
94
+ $ filesystem ->expects ($ this ->once ())->method ('move ' );
93
95
$ this ->assertTrue ($ this ->writer ->writeFile ($ filesystem , $ this ->vfs ->path ('/tmp/tempfile ' ), 'path ' ));
94
96
95
- $ filesystem = $ this ->getMockBuilder ('League\Flysystem\FilesystemInterface ' )->getMock ();
96
- $ filesystem ->expects ($ this ->once ())->method ('writeStream ' )->will ($ this ->returnValue ( false ));
97
- $ filesystem ->expects ($ this ->exactly (2 ))->method ('delete ' )-> will ( $ this -> returnValue ( true )) ;
98
- $ filesystem ->expects ($ this ->never ())->method ('rename ' );
97
+ $ filesystem = $ this ->getMockBuilder ('League\Flysystem\FilesystemOperator ' )->getMock ();
98
+ $ filesystem ->expects ($ this ->once ())->method ('writeStream ' )->will ($ this ->throwException ( new UnableToWriteFile () ));
99
+ $ filesystem ->expects ($ this ->exactly (2 ))->method ('delete ' );
100
+ $ filesystem ->expects ($ this ->never ())->method ('move ' );
99
101
$ this ->assertFalse ($ this ->writer ->writeFile ($ filesystem , $ this ->vfs ->path ('/tmp/tempfile ' ), 'path ' ));
100
102
101
- $ filesystem = $ this ->getMockBuilder ('League\Flysystem\FilesystemInterface ' )->getMock ();
102
- $ filesystem ->expects ($ this ->once ())->method ('writeStream ' )-> will ( $ this -> returnValue ( true )) ;
103
- $ filesystem ->expects ($ this ->exactly (3 ))->method ('delete ' )-> will ( $ this -> returnValue ( true )) ;
104
- $ filesystem ->expects ($ this ->once ())->method ('rename ' )->will ($ this ->returnValue ( false ));
103
+ $ filesystem = $ this ->getMockBuilder ('League\Flysystem\FilesystemOperator ' )->getMock ();
104
+ $ filesystem ->expects ($ this ->once ())->method ('writeStream ' );
105
+ $ filesystem ->expects ($ this ->exactly (3 ))->method ('delete ' );
106
+ $ filesystem ->expects ($ this ->once ())->method ('move ' )->will ($ this ->throwException ( new UnableToMoveFile () ));
105
107
$ this ->assertFalse ($ this ->writer ->writeFile ($ filesystem , $ this ->vfs ->path ('/tmp/tempfile ' ), 'path ' ));
106
108
}
107
109
108
110
public function testDeletePath ()
109
111
{
110
- $ filesystem = $ this ->getMockBuilder ('League\Flysystem\FilesystemInterface ' )->getMock ();
111
- $ filesystem ->expects ($ this ->any ())->method ('delete ' )-> will ( $ this -> returnValue ( true )) ;
112
+ $ filesystem = $ this ->getMockBuilder ('League\Flysystem\FilesystemOperator ' )->getMock ();
113
+ $ filesystem ->expects ($ this ->any ())->method ('delete ' );
112
114
$ this ->assertTrue ($ this ->writer ->deletePath ($ filesystem , 'path ' ));
113
115
114
- $ filesystem = $ this ->getMockBuilder ('League\Flysystem\FilesystemInterface ' )->getMock ();
115
- $ filesystem ->expects ($ this ->any ())->method ('delete ' )->will ($ this ->returnValue ( false ));
116
+ $ filesystem = $ this ->getMockBuilder ('League\Flysystem\FilesystemOperator ' )->getMock ();
117
+ $ filesystem ->expects ($ this ->any ())->method ('delete ' )->will ($ this ->throwException ( new UnableToDeleteFile () ));
116
118
$ this ->assertFalse ($ this ->writer ->deletePath ($ filesystem , 'path ' ));
117
119
}
118
120
119
121
public function testGetFilesystem ()
120
122
{
121
- $ this ->assertInstanceOf ('League\Flysystem\FilesystemInterface ' , $ this ->writer ->getFilesystem ('field ' , []));
122
- $ this ->assertInstanceOf ('League\Flysystem\FilesystemInterface ' , $ this ->writer ->getFilesystem ('field ' , [
123
+ $ this ->assertInstanceOf ('League\Flysystem\FilesystemOperator ' , $ this ->writer ->getFilesystem ('field ' , []));
124
+ $ this ->assertInstanceOf ('League\Flysystem\FilesystemOperator ' , $ this ->writer ->getFilesystem ('field ' , [
123
125
'key ' => 'value ' ,
124
126
]));
125
- $ this ->assertInstanceOf ('League\Flysystem\FilesystemInterface ' , $ this ->writer ->getFilesystem ('field ' , [
127
+ $ this ->assertInstanceOf ('League\Flysystem\FilesystemOperator ' , $ this ->writer ->getFilesystem ('field ' , [
126
128
'filesystem ' => [
127
- 'adapter ' => new NullAdapter (),
129
+ 'adapter ' => new InMemoryFilesystemAdapter (),
128
130
],
129
131
]));
130
- $ this ->assertInstanceOf ('League\Flysystem\FilesystemInterface ' , $ this ->writer ->getFilesystem ('field ' , [
132
+ $ this ->assertInstanceOf ('League\Flysystem\FilesystemOperator ' , $ this ->writer ->getFilesystem ('field ' , [
131
133
'filesystem ' => [
132
134
'adapter ' => function () {
133
- return new NullAdapter ();
135
+ return new InMemoryFilesystemAdapter ();
134
136
},
135
137
],
136
138
]));
0 commit comments