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