Skip to content

Commit 3a2f35d

Browse files
committed
Don't recreate collections and indexes on each test for performance
1 parent 4689540 commit 3a2f35d

File tree

2 files changed

+26
-3
lines changed

2 files changed

+26
-3
lines changed

tests/GridFS/BucketFunctionalTest.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -688,6 +688,10 @@ public function testUploadingFirstFileCreatesIndexes(): void
688688

689689
public function testExistingIndexIsReused(): void
690690
{
691+
// The collections may exist from other tests, ensure they are removed before and after the test
692+
$this->dropCollection($this->getDatabaseName(), 'fs.chunks');
693+
$this->dropCollection($this->getDatabaseName(), 'fs.files');
694+
691695
$this->filesCollection->createIndex(['filename' => 1.0, 'uploadDate' => 1], ['name' => 'test']);
692696
$this->chunksCollection->createIndex(['files_id' => 1.0, 'n' => 1], ['name' => 'test', 'unique' => true]);
693697

tests/GridFS/FunctionalTestCase.php

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
namespace MongoDB\Tests\GridFS;
44

55
use MongoDB\Collection;
6+
use MongoDB\Driver\Command;
67
use MongoDB\GridFS\Bucket;
78
use MongoDB\Tests\FunctionalTestCase as BaseFunctionalTestCase;
89

@@ -28,10 +29,28 @@ 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+
$this->chunksCollection->deleteMany([]);
36+
$this->filesCollection->deleteMany([]);
37+
}
38+
39+
public function tearDown(): void
40+
{
41+
$this->chunksCollection->deleteMany([]);
42+
$this->filesCollection->deleteMany([]);
43+
44+
parent::tearDown();
45+
}
46+
47+
public static function tearDownAfterClass(): void
48+
{
49+
$manager = static::createTestManager();
50+
$manager->executeCommand(self::getDatabaseName(), new Command(['drop' => 'fs.chunks']));
51+
$manager->executeCommand(self::getDatabaseName(), new Command(['drop' => 'fs.files']));
52+
53+
parent::tearDownAfterClass();
3554
}
3655

3756
/**

0 commit comments

Comments
 (0)