FunctionalTestCase.php 939 Bytes
Newer Older
1 2 3 4 5
<?php

namespace MongoDB\Tests\Collection;

use MongoDB\Collection;
6
use MongoDB\Driver\WriteConcern;
7 8 9 10 11 12 13 14 15 16 17 18 19
use MongoDB\Tests\FunctionalTestCase as BaseFunctionalTestCase;

/**
 * Base class for Collection functional tests.
 */
abstract class FunctionalTestCase extends BaseFunctionalTestCase
{
    protected $collection;

    public function setUp()
    {
        parent::setUp();

20
        $this->collection = new Collection($this->manager, $this->getDatabaseName(), $this->getCollectionName());
21 22

        $this->dropCollection();
23 24
    }

25 26 27 28 29 30
    public function tearDown()
    {
        if ($this->hasFailed()) {
            return;
        }

31 32 33 34 35 36 37 38 39 40
        $this->dropCollection();
    }

    private function dropCollection()
    {
        $options = version_compare($this->getServerVersion(), '3.4.0', '>=')
            ? ['writeConcern' => new WriteConcern(WriteConcern::MAJORITY)]
            : [];

        $this->collection->drop($options);
41 42
    }
}