@@ -160,6 +160,34 @@ public function testDeleteStillRemovesChunksIfFileDoesNotExist($input, $expected
160
160
$ this ->assertCollectionCount ($ this ->chunksCollection , 0 );
161
161
}
162
162
163
+ public function testDeleteByName (): void
164
+ {
165
+ $ this ->bucket ->uploadFromStream ('filename ' , self ::createStream ('foobar1 ' ));
166
+ $ this ->bucket ->uploadFromStream ('filename ' , self ::createStream ('foobar2 ' ));
167
+ $ this ->bucket ->uploadFromStream ('filename ' , self ::createStream ('foobar3 ' ));
168
+
169
+ $ this ->bucket ->uploadFromStream ('other ' , self ::createStream ('foobar ' ));
170
+
171
+ $ this ->assertCollectionCount ($ this ->filesCollection , 4 );
172
+ $ this ->assertCollectionCount ($ this ->chunksCollection , 4 );
173
+
174
+ $ this ->bucket ->deleteByName ('filename ' );
175
+
176
+ $ this ->assertCollectionCount ($ this ->filesCollection , 1 );
177
+ $ this ->assertCollectionCount ($ this ->chunksCollection , 1 );
178
+
179
+ $ this ->bucket ->deleteByName ('other ' );
180
+
181
+ $ this ->assertCollectionCount ($ this ->filesCollection , 0 );
182
+ $ this ->assertCollectionCount ($ this ->chunksCollection , 0 );
183
+ }
184
+
185
+ public function testDeleteByNameShouldRequireFileToExist (): void
186
+ {
187
+ $ this ->expectException (FileNotFoundException::class);
188
+ $ this ->bucket ->deleteByName ('nonexistent-name ' );
189
+ }
190
+
163
191
public function testDownloadingFileWithMissingChunk (): void
164
192
{
165
193
$ id = $ this ->bucket ->uploadFromStream ('filename ' , self ::createStream ('foobar ' ));
@@ -723,6 +751,24 @@ public function testRenameShouldRequireFileToExist(): void
723
751
$ this ->bucket ->rename ('nonexistent-id ' , 'b ' );
724
752
}
725
753
754
+ public function testRenameByName (): void
755
+ {
756
+ $ this ->bucket ->uploadFromStream ('filename ' , self ::createStream ('foo ' ));
757
+ $ this ->bucket ->uploadFromStream ('filename ' , self ::createStream ('foo ' ));
758
+ $ this ->bucket ->uploadFromStream ('filename ' , self ::createStream ('foo ' ));
759
+
760
+ $ this ->bucket ->renameByName ('filename ' , 'newname ' );
761
+
762
+ $ this ->assertNull ($ this ->bucket ->findOne (['filename ' => 'filename ' ]), 'No file has the old name ' );
763
+ $ this ->assertStreamContents ('foo ' , $ this ->bucket ->openDownloadStreamByName ('newname ' ));
764
+ }
765
+
766
+ public function testRenameByNameShouldRequireFileToExist (): void
767
+ {
768
+ $ this ->expectException (FileNotFoundException::class);
769
+ $ this ->bucket ->renameByName ('nonexistent-name ' , 'b ' );
770
+ }
771
+
726
772
public function testUploadFromStream (): void
727
773
{
728
774
$ options = [
0 commit comments