4
4
5
5
use MongoDB \Collection ;
6
6
use MongoDB \GridFS \Bucket ;
7
+ use MongoDB \Operation \DropCollection ;
7
8
use MongoDB \Tests \FunctionalTestCase as BaseFunctionalTestCase ;
8
9
9
10
use function fopen ;
@@ -28,10 +29,33 @@ public function setUp(): void
28
29
parent ::setUp ();
29
30
30
31
$ this ->bucket = new Bucket ($ this ->manager , $ this ->getDatabaseName ());
31
- $ this ->bucket ->drop ();
32
32
33
- $ this ->chunksCollection = $ this ->createCollection ($ this ->getDatabaseName (), 'fs.chunks ' );
34
- $ this ->filesCollection = $ this ->createCollection ($ this ->getDatabaseName (), 'fs.files ' );
33
+ $ this ->chunksCollection = new Collection ($ this ->manager , $ this ->getDatabaseName (), 'fs.chunks ' );
34
+ $ this ->filesCollection = new Collection ($ this ->manager , $ this ->getDatabaseName (), 'fs.files ' );
35
+ }
36
+
37
+ public function tearDown (): void
38
+ {
39
+ $ this ->chunksCollection ->deleteMany ([]);
40
+ $ this ->filesCollection ->deleteMany ([]);
41
+
42
+ parent ::tearDown ();
43
+ }
44
+
45
+ /**
46
+ * The bucket's collections are created by the first test that runs and
47
+ * kept for all subsequent tests. This is done to avoid creating the
48
+ * collections and their indexes for each test, which would be slow.
49
+ *
50
+ * @beforeClass
51
+ * @afterClass
52
+ */
53
+ public static function dropCollectionsBeforeAfterClass (): void
54
+ {
55
+ $ manager = static ::createTestManager ();
56
+
57
+ (new DropCollection (self ::getDatabaseName (), 'fs.chunks ' ))->execute ($ manager ->selectServer ());
58
+ (new DropCollection (self ::getDatabaseName (), 'fs.files ' ))->execute ($ manager ->selectServer ());
35
59
}
36
60
37
61
/**
0 commit comments