44
55use MongoDB \Collection ;
66use MongoDB \GridFS \Bucket ;
7+ use MongoDB \Operation \DropCollection ;
78use MongoDB \Tests \FunctionalTestCase as BaseFunctionalTestCase ;
89
910use function fopen ;
@@ -28,10 +29,33 @@ public function setUp(): void
2829 parent ::setUp ();
2930
3031 $ this ->bucket = new Bucket ($ this ->manager , $ this ->getDatabaseName ());
31- $ this ->bucket ->drop ();
3232
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 ());
3559 }
3660
3761 /**
0 commit comments