Unverified Commit 7880bcd1 authored by Andreas Braun's avatar Andreas Braun

Merge pull request #665

parents 90748471 e0c65314
...@@ -6,3 +6,4 @@ vendor/ ...@@ -6,3 +6,4 @@ vendor/
# PHPUnit # PHPUnit
phpunit.phar phpunit.phar
phpunit.xml phpunit.xml
.phpunit.result.cache
...@@ -21,9 +21,6 @@ env: ...@@ -21,9 +21,6 @@ env:
- COMPOSER_OPTIONS= - COMPOSER_OPTIONS=
jobs: jobs:
allow_failures:
- php: "7.4snapshot"
include: include:
- stage: Smoke Testing - stage: Smoke Testing
......
...@@ -16,7 +16,8 @@ ...@@ -16,7 +16,8 @@
"ext-mongodb": "^1.6" "ext-mongodb": "^1.6"
}, },
"require-dev": { "require-dev": {
"phpunit/phpunit": "^5.7.27 || ^6.4" "phpunit/phpunit": "^5.7.27 || ^6.4 || ^8.3",
"symfony/phpunit-bridge": "^4.4@dev"
}, },
"autoload": { "autoload": {
"psr-4": { "MongoDB\\": "src/" }, "psr-4": { "MongoDB\\": "src/" },
......
...@@ -2,15 +2,10 @@ ...@@ -2,15 +2,10 @@
<phpunit <phpunit
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="http://schema.phpunit.de/4.3/phpunit.xsd" xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/8.3/phpunit.xsd"
backupGlobals="false" beStrictAboutOutputDuringTests="true"
backupStaticAttributes="false" beStrictAboutChangesToGlobalState="true"
colors="true" colors="true"
convertErrorsToExceptions="true"
convertNoticesToExceptions="true"
convertWarningsToExceptions="true"
stopOnFailure="false"
syntaxCheck="false"
bootstrap="tests/bootstrap.php" bootstrap="tests/bootstrap.php"
> >
......
...@@ -6,15 +6,18 @@ use MongoDB\Client; ...@@ -6,15 +6,18 @@ use MongoDB\Client;
use MongoDB\Driver\BulkWrite; use MongoDB\Driver\BulkWrite;
use MongoDB\Driver\Command; use MongoDB\Driver\Command;
use MongoDB\Model\DatabaseInfo; use MongoDB\Model\DatabaseInfo;
use Symfony\Bridge\PhpUnit\SetUpTearDownTrait;
/** /**
* Functional tests for the Client class. * Functional tests for the Client class.
*/ */
class ClientFunctionalTest extends FunctionalTestCase class ClientFunctionalTest extends FunctionalTestCase
{ {
use SetUpTearDownTrait;
private $client; private $client;
public function setUp() private function doSetUp()
{ {
parent::setUp(); parent::setUp();
......
...@@ -67,7 +67,7 @@ class ClientTest extends TestCase ...@@ -67,7 +67,7 @@ class ClientTest extends TestCase
$this->assertSame(ReadConcern::LOCAL, $debug['readConcern']->getLevel()); $this->assertSame(ReadConcern::LOCAL, $debug['readConcern']->getLevel());
$this->assertInstanceOf(\MongoDB\Driver\ReadPreference::class, $debug['readPreference']); $this->assertInstanceOf(\MongoDB\Driver\ReadPreference::class, $debug['readPreference']);
$this->assertSame(ReadPreference::RP_SECONDARY_PREFERRED, $debug['readPreference']->getMode()); $this->assertSame(ReadPreference::RP_SECONDARY_PREFERRED, $debug['readPreference']->getMode());
$this->assertInternalType('array', $debug['typeMap']); $this->assertIsArray($debug['typeMap']);
$this->assertSame(['root' => 'array'], $debug['typeMap']); $this->assertSame(['root' => 'array'], $debug['typeMap']);
$this->assertInstanceOf(\MongoDB\Driver\WriteConcern::class, $debug['writeConcern']); $this->assertInstanceOf(\MongoDB\Driver\WriteConcern::class, $debug['writeConcern']);
$this->assertSame(WriteConcern::MAJORITY, $debug['writeConcern']->getW()); $this->assertSame(WriteConcern::MAJORITY, $debug['writeConcern']->getW());
...@@ -90,7 +90,7 @@ class ClientTest extends TestCase ...@@ -90,7 +90,7 @@ class ClientTest extends TestCase
$this->assertSame(ReadConcern::LOCAL, $debug['readConcern']->getLevel()); $this->assertSame(ReadConcern::LOCAL, $debug['readConcern']->getLevel());
$this->assertInstanceOf(\MongoDB\Driver\ReadPreference::class, $debug['readPreference']); $this->assertInstanceOf(\MongoDB\Driver\ReadPreference::class, $debug['readPreference']);
$this->assertSame(ReadPreference::RP_SECONDARY_PREFERRED, $debug['readPreference']->getMode()); $this->assertSame(ReadPreference::RP_SECONDARY_PREFERRED, $debug['readPreference']->getMode());
$this->assertInternalType('array', $debug['typeMap']); $this->assertIsArray($debug['typeMap']);
$this->assertSame(['root' => 'array'], $debug['typeMap']); $this->assertSame(['root' => 'array'], $debug['typeMap']);
$this->assertInstanceOf(\MongoDB\Driver\WriteConcern::class, $debug['writeConcern']); $this->assertInstanceOf(\MongoDB\Driver\WriteConcern::class, $debug['writeConcern']);
$this->assertSame(WriteConcern::MAJORITY, $debug['writeConcern']->getW()); $this->assertSame(WriteConcern::MAJORITY, $debug['writeConcern']->getW());
...@@ -129,7 +129,7 @@ class ClientTest extends TestCase ...@@ -129,7 +129,7 @@ class ClientTest extends TestCase
$this->assertSame(ReadConcern::LOCAL, $debug['readConcern']->getLevel()); $this->assertSame(ReadConcern::LOCAL, $debug['readConcern']->getLevel());
$this->assertInstanceOf(\MongoDB\Driver\ReadPreference::class, $debug['readPreference']); $this->assertInstanceOf(\MongoDB\Driver\ReadPreference::class, $debug['readPreference']);
$this->assertSame(ReadPreference::RP_SECONDARY_PREFERRED, $debug['readPreference']->getMode()); $this->assertSame(ReadPreference::RP_SECONDARY_PREFERRED, $debug['readPreference']->getMode());
$this->assertInternalType('array', $debug['typeMap']); $this->assertIsArray($debug['typeMap']);
$this->assertSame(['root' => 'array'], $debug['typeMap']); $this->assertSame(['root' => 'array'], $debug['typeMap']);
$this->assertInstanceOf(\MongoDB\Driver\WriteConcern::class, $debug['writeConcern']); $this->assertInstanceOf(\MongoDB\Driver\WriteConcern::class, $debug['writeConcern']);
$this->assertSame(WriteConcern::MAJORITY, $debug['writeConcern']->getW()); $this->assertSame(WriteConcern::MAJORITY, $debug['writeConcern']->getW());
...@@ -152,7 +152,7 @@ class ClientTest extends TestCase ...@@ -152,7 +152,7 @@ class ClientTest extends TestCase
$this->assertSame(ReadConcern::LOCAL, $debug['readConcern']->getLevel()); $this->assertSame(ReadConcern::LOCAL, $debug['readConcern']->getLevel());
$this->assertInstanceOf(\MongoDB\Driver\ReadPreference::class, $debug['readPreference']); $this->assertInstanceOf(\MongoDB\Driver\ReadPreference::class, $debug['readPreference']);
$this->assertSame(ReadPreference::RP_SECONDARY_PREFERRED, $debug['readPreference']->getMode()); $this->assertSame(ReadPreference::RP_SECONDARY_PREFERRED, $debug['readPreference']->getMode());
$this->assertInternalType('array', $debug['typeMap']); $this->assertIsArray($debug['typeMap']);
$this->assertSame(['root' => 'array'], $debug['typeMap']); $this->assertSame(['root' => 'array'], $debug['typeMap']);
$this->assertInstanceOf(\MongoDB\Driver\WriteConcern::class, $debug['writeConcern']); $this->assertInstanceOf(\MongoDB\Driver\WriteConcern::class, $debug['writeConcern']);
$this->assertSame(WriteConcern::MAJORITY, $debug['writeConcern']->getW()); $this->assertSame(WriteConcern::MAJORITY, $debug['writeConcern']->getW());
......
...@@ -262,7 +262,7 @@ class CollectionFunctionalTest extends FunctionalTestCase ...@@ -262,7 +262,7 @@ class CollectionFunctionalTest extends FunctionalTestCase
$this->assertSame(ReadConcern::LOCAL, $debug['readConcern']->getLevel()); $this->assertSame(ReadConcern::LOCAL, $debug['readConcern']->getLevel());
$this->assertInstanceOf(\MongoDB\Driver\ReadPreference::class, $debug['readPreference']); $this->assertInstanceOf(\MongoDB\Driver\ReadPreference::class, $debug['readPreference']);
$this->assertSame(ReadPreference::RP_SECONDARY_PREFERRED, $debug['readPreference']->getMode()); $this->assertSame(ReadPreference::RP_SECONDARY_PREFERRED, $debug['readPreference']->getMode());
$this->assertInternalType('array', $debug['typeMap']); $this->assertIsArray($debug['typeMap']);
$this->assertSame(['root' => 'array'], $debug['typeMap']); $this->assertSame(['root' => 'array'], $debug['typeMap']);
$this->assertInstanceOf(\MongoDB\Driver\WriteConcern::class, $debug['writeConcern']); $this->assertInstanceOf(\MongoDB\Driver\WriteConcern::class, $debug['writeConcern']);
$this->assertSame(WriteConcern::MAJORITY, $debug['writeConcern']->getW()); $this->assertSame(WriteConcern::MAJORITY, $debug['writeConcern']->getW());
...@@ -284,7 +284,7 @@ class CollectionFunctionalTest extends FunctionalTestCase ...@@ -284,7 +284,7 @@ class CollectionFunctionalTest extends FunctionalTestCase
$this->assertSame(ReadConcern::LOCAL, $debug['readConcern']->getLevel()); $this->assertSame(ReadConcern::LOCAL, $debug['readConcern']->getLevel());
$this->assertInstanceOf(\MongoDB\Driver\ReadPreference::class, $debug['readPreference']); $this->assertInstanceOf(\MongoDB\Driver\ReadPreference::class, $debug['readPreference']);
$this->assertSame(ReadPreference::RP_SECONDARY_PREFERRED, $debug['readPreference']->getMode()); $this->assertSame(ReadPreference::RP_SECONDARY_PREFERRED, $debug['readPreference']->getMode());
$this->assertInternalType('array', $debug['typeMap']); $this->assertIsArray($debug['typeMap']);
$this->assertSame(['root' => 'array'], $debug['typeMap']); $this->assertSame(['root' => 'array'], $debug['typeMap']);
$this->assertInstanceOf(\MongoDB\Driver\WriteConcern::class, $debug['writeConcern']); $this->assertInstanceOf(\MongoDB\Driver\WriteConcern::class, $debug['writeConcern']);
$this->assertSame(WriteConcern::MAJORITY, $debug['writeConcern']->getW()); $this->assertSame(WriteConcern::MAJORITY, $debug['writeConcern']->getW());
......
...@@ -11,6 +11,7 @@ use MongoDB\Operation\FindOneAndReplace; ...@@ -11,6 +11,7 @@ use MongoDB\Operation\FindOneAndReplace;
use IteratorIterator; use IteratorIterator;
use LogicException; use LogicException;
use MultipleIterator; use MultipleIterator;
use Symfony\Bridge\PhpUnit\SetUpTearDownTrait;
/** /**
* CRUD spec functional tests. * CRUD spec functional tests.
...@@ -19,9 +20,11 @@ use MultipleIterator; ...@@ -19,9 +20,11 @@ use MultipleIterator;
*/ */
class CrudSpecFunctionalTest extends FunctionalTestCase class CrudSpecFunctionalTest extends FunctionalTestCase
{ {
use SetUpTearDownTrait;
private $expectedCollection; private $expectedCollection;
public function setUp() private function doSetUp()
{ {
parent::setUp(); parent::setUp();
...@@ -297,7 +300,7 @@ class CrudSpecFunctionalTest extends FunctionalTestCase ...@@ -297,7 +300,7 @@ class CrudSpecFunctionalTest extends FunctionalTestCase
break; break;
case 'bulkWrite': case 'bulkWrite':
$this->assertInternalType('array', $expectedResult); $this->assertIsArray($expectedResult);
$this->assertInstanceOf(\MongoDB\BulkWriteResult::class, $actualResult); $this->assertInstanceOf(\MongoDB\BulkWriteResult::class, $actualResult);
if (isset($expectedResult['deletedCount'])) { if (isset($expectedResult['deletedCount'])) {
...@@ -354,7 +357,7 @@ class CrudSpecFunctionalTest extends FunctionalTestCase ...@@ -354,7 +357,7 @@ class CrudSpecFunctionalTest extends FunctionalTestCase
case 'deleteMany': case 'deleteMany':
case 'deleteOne': case 'deleteOne':
$this->assertInternalType('array', $expectedResult); $this->assertIsArray($expectedResult);
$this->assertInstanceOf(\MongoDB\DeleteResult::class, $actualResult); $this->assertInstanceOf(\MongoDB\DeleteResult::class, $actualResult);
if (isset($expectedResult['deletedCount'])) { if (isset($expectedResult['deletedCount'])) {
...@@ -372,7 +375,7 @@ class CrudSpecFunctionalTest extends FunctionalTestCase ...@@ -372,7 +375,7 @@ class CrudSpecFunctionalTest extends FunctionalTestCase
break; break;
case 'insertMany': case 'insertMany':
$this->assertInternalType('array', $expectedResult); $this->assertIsArray($expectedResult);
$this->assertInstanceOf(\MongoDB\InsertManyResult::class, $actualResult); $this->assertInstanceOf(\MongoDB\InsertManyResult::class, $actualResult);
if (isset($expectedResult['insertedCount'])) { if (isset($expectedResult['insertedCount'])) {
...@@ -388,7 +391,7 @@ class CrudSpecFunctionalTest extends FunctionalTestCase ...@@ -388,7 +391,7 @@ class CrudSpecFunctionalTest extends FunctionalTestCase
break; break;
case 'insertOne': case 'insertOne':
$this->assertInternalType('array', $expectedResult); $this->assertIsArray($expectedResult);
$this->assertInstanceOf(\MongoDB\InsertOneResult::class, $actualResult); $this->assertInstanceOf(\MongoDB\InsertOneResult::class, $actualResult);
if (isset($expectedResult['insertedCount'])) { if (isset($expectedResult['insertedCount'])) {
...@@ -406,7 +409,7 @@ class CrudSpecFunctionalTest extends FunctionalTestCase ...@@ -406,7 +409,7 @@ class CrudSpecFunctionalTest extends FunctionalTestCase
case 'replaceOne': case 'replaceOne':
case 'updateMany': case 'updateMany':
case 'updateOne': case 'updateOne':
$this->assertInternalType('array', $expectedResult); $this->assertIsArray($expectedResult);
$this->assertInstanceOf(\MongoDB\UpdateResult::class, $actualResult); $this->assertInstanceOf(\MongoDB\UpdateResult::class, $actualResult);
if (isset($expectedResult['matchedCount'])) { if (isset($expectedResult['matchedCount'])) {
......
...@@ -5,15 +5,18 @@ namespace MongoDB\Tests\Collection; ...@@ -5,15 +5,18 @@ namespace MongoDB\Tests\Collection;
use MongoDB\Collection; use MongoDB\Collection;
use MongoDB\Driver\WriteConcern; use MongoDB\Driver\WriteConcern;
use MongoDB\Tests\FunctionalTestCase as BaseFunctionalTestCase; use MongoDB\Tests\FunctionalTestCase as BaseFunctionalTestCase;
use Symfony\Bridge\PhpUnit\SetUpTearDownTrait;
/** /**
* Base class for Collection functional tests. * Base class for Collection functional tests.
*/ */
abstract class FunctionalTestCase extends BaseFunctionalTestCase abstract class FunctionalTestCase extends BaseFunctionalTestCase
{ {
use SetUpTearDownTrait;
protected $collection; protected $collection;
public function setUp() private function doSetUp()
{ {
parent::setUp(); parent::setUp();
...@@ -22,7 +25,7 @@ abstract class FunctionalTestCase extends BaseFunctionalTestCase ...@@ -22,7 +25,7 @@ abstract class FunctionalTestCase extends BaseFunctionalTestCase
$this->dropCollection(); $this->dropCollection();
} }
public function tearDown() private function doTearDown()
{ {
if ($this->hasFailed()) { if ($this->hasFailed()) {
return; return;
......
<?php
namespace MongoDB\Tests\Compat;
use PHPUnit\Framework\Assert;
use ReflectionClass;
use Symfony\Bridge\PhpUnit\Legacy\PolyfillAssertTrait as SymfonyPolyfillAssertTrait;
$r = new ReflectionClass(Assert::class);
if (! $r->hasMethod('assertEqualsWithDelta')) {
/**
* @internal
*/
trait PolyfillAssertTrait
{
use SymfonyPolyfillAssertTrait;
}
} else {
/**
* @internal
*/
trait PolyfillAssertTrait
{
}
}
...@@ -111,7 +111,7 @@ class DatabaseFunctionalTest extends FunctionalTestCase ...@@ -111,7 +111,7 @@ class DatabaseFunctionalTest extends FunctionalTestCase
$commandResult = current($cursor->toArray()); $commandResult = current($cursor->toArray());
$this->assertCommandSucceeded($commandResult); $this->assertCommandSucceeded($commandResult);
$this->assertInternalType('array', $commandResult); $this->assertIsArray($commandResult);
$this->assertArrayHasKey('ismaster', $commandResult); $this->assertArrayHasKey('ismaster', $commandResult);
$this->assertTrue($commandResult['ismaster']); $this->assertTrue($commandResult['ismaster']);
} }
...@@ -207,7 +207,7 @@ class DatabaseFunctionalTest extends FunctionalTestCase ...@@ -207,7 +207,7 @@ class DatabaseFunctionalTest extends FunctionalTestCase
$this->assertSame(ReadConcern::LOCAL, $debug['readConcern']->getLevel()); $this->assertSame(ReadConcern::LOCAL, $debug['readConcern']->getLevel());
$this->assertInstanceOf(\MongoDB\Driver\ReadPreference::class, $debug['readPreference']); $this->assertInstanceOf(\MongoDB\Driver\ReadPreference::class, $debug['readPreference']);
$this->assertSame(ReadPreference::RP_SECONDARY_PREFERRED, $debug['readPreference']->getMode()); $this->assertSame(ReadPreference::RP_SECONDARY_PREFERRED, $debug['readPreference']->getMode());
$this->assertInternalType('array', $debug['typeMap']); $this->assertIsArray($debug['typeMap']);
$this->assertSame(['root' => 'array'], $debug['typeMap']); $this->assertSame(['root' => 'array'], $debug['typeMap']);
$this->assertInstanceOf(\MongoDB\Driver\WriteConcern::class, $debug['writeConcern']); $this->assertInstanceOf(\MongoDB\Driver\WriteConcern::class, $debug['writeConcern']);
$this->assertSame(WriteConcern::MAJORITY, $debug['writeConcern']->getW()); $this->assertSame(WriteConcern::MAJORITY, $debug['writeConcern']->getW());
...@@ -229,7 +229,7 @@ class DatabaseFunctionalTest extends FunctionalTestCase ...@@ -229,7 +229,7 @@ class DatabaseFunctionalTest extends FunctionalTestCase
$this->assertSame(ReadConcern::LOCAL, $debug['readConcern']->getLevel()); $this->assertSame(ReadConcern::LOCAL, $debug['readConcern']->getLevel());
$this->assertInstanceOf(\MongoDB\Driver\ReadPreference::class, $debug['readPreference']); $this->assertInstanceOf(\MongoDB\Driver\ReadPreference::class, $debug['readPreference']);
$this->assertSame(ReadPreference::RP_SECONDARY_PREFERRED, $debug['readPreference']->getMode()); $this->assertSame(ReadPreference::RP_SECONDARY_PREFERRED, $debug['readPreference']->getMode());
$this->assertInternalType('array', $debug['typeMap']); $this->assertIsArray($debug['typeMap']);
$this->assertSame(['root' => 'array'], $debug['typeMap']); $this->assertSame(['root' => 'array'], $debug['typeMap']);
$this->assertInstanceOf(\MongoDB\Driver\WriteConcern::class, $debug['writeConcern']); $this->assertInstanceOf(\MongoDB\Driver\WriteConcern::class, $debug['writeConcern']);
$this->assertSame(WriteConcern::MAJORITY, $debug['writeConcern']->getW()); $this->assertSame(WriteConcern::MAJORITY, $debug['writeConcern']->getW());
...@@ -303,7 +303,7 @@ class DatabaseFunctionalTest extends FunctionalTestCase ...@@ -303,7 +303,7 @@ class DatabaseFunctionalTest extends FunctionalTestCase
$this->assertSame(ReadConcern::LOCAL, $debug['readConcern']->getLevel()); $this->assertSame(ReadConcern::LOCAL, $debug['readConcern']->getLevel());
$this->assertInstanceOf(\MongoDB\Driver\ReadPreference::class, $debug['readPreference']); $this->assertInstanceOf(\MongoDB\Driver\ReadPreference::class, $debug['readPreference']);
$this->assertSame(ReadPreference::RP_SECONDARY_PREFERRED, $debug['readPreference']->getMode()); $this->assertSame(ReadPreference::RP_SECONDARY_PREFERRED, $debug['readPreference']->getMode());
$this->assertInternalType('array', $debug['typeMap']); $this->assertIsArray($debug['typeMap']);
$this->assertSame(['root' => 'array'], $debug['typeMap']); $this->assertSame(['root' => 'array'], $debug['typeMap']);
$this->assertInstanceOf(\MongoDB\Driver\WriteConcern::class, $debug['writeConcern']); $this->assertInstanceOf(\MongoDB\Driver\WriteConcern::class, $debug['writeConcern']);
$this->assertSame(WriteConcern::MAJORITY, $debug['writeConcern']->getW()); $this->assertSame(WriteConcern::MAJORITY, $debug['writeConcern']->getW());
...@@ -325,7 +325,7 @@ class DatabaseFunctionalTest extends FunctionalTestCase ...@@ -325,7 +325,7 @@ class DatabaseFunctionalTest extends FunctionalTestCase
$this->assertSame(ReadConcern::LOCAL, $debug['readConcern']->getLevel()); $this->assertSame(ReadConcern::LOCAL, $debug['readConcern']->getLevel());
$this->assertInstanceOf(\MongoDB\Driver\ReadPreference::class, $debug['readPreference']); $this->assertInstanceOf(\MongoDB\Driver\ReadPreference::class, $debug['readPreference']);
$this->assertSame(ReadPreference::RP_SECONDARY_PREFERRED, $debug['readPreference']->getMode()); $this->assertSame(ReadPreference::RP_SECONDARY_PREFERRED, $debug['readPreference']->getMode());
$this->assertInternalType('array', $debug['typeMap']); $this->assertIsArray($debug['typeMap']);
$this->assertSame(['root' => 'array'], $debug['typeMap']); $this->assertSame(['root' => 'array'], $debug['typeMap']);
$this->assertInstanceOf(\MongoDB\Driver\WriteConcern::class, $debug['writeConcern']); $this->assertInstanceOf(\MongoDB\Driver\WriteConcern::class, $debug['writeConcern']);
$this->assertSame(WriteConcern::MAJORITY, $debug['writeConcern']->getW()); $this->assertSame(WriteConcern::MAJORITY, $debug['writeConcern']->getW());
......
...@@ -4,15 +4,18 @@ namespace MongoDB\Tests\Database; ...@@ -4,15 +4,18 @@ namespace MongoDB\Tests\Database;
use MongoDB\Database; use MongoDB\Database;
use MongoDB\Tests\FunctionalTestCase as BaseFunctionalTestCase; use MongoDB\Tests\FunctionalTestCase as BaseFunctionalTestCase;
use Symfony\Bridge\PhpUnit\SetUpTearDownTrait;
/** /**
* Base class for Database functional tests. * Base class for Database functional tests.
*/ */
abstract class FunctionalTestCase extends BaseFunctionalTestCase abstract class FunctionalTestCase extends BaseFunctionalTestCase
{ {
use SetUpTearDownTrait;
protected $database; protected $database;
public function setUp() private function doSetUp()
{ {
parent::setUp(); parent::setUp();
......
...@@ -11,6 +11,7 @@ use MongoDB\Driver\Server; ...@@ -11,6 +11,7 @@ use MongoDB\Driver\Server;
use MongoDB\Driver\WriteConcern; use MongoDB\Driver\WriteConcern;
use MongoDB\Driver\Exception\ConnectionTimeoutException; use MongoDB\Driver\Exception\ConnectionTimeoutException;
use MongoDB\Operation\DropCollection; use MongoDB\Operation\DropCollection;
use Symfony\Bridge\PhpUnit\SetUpTearDownTrait;
/** /**
* Documentation examples to be parsed for inclusion in the MongoDB manual. * Documentation examples to be parsed for inclusion in the MongoDB manual.
...@@ -21,14 +22,16 @@ use MongoDB\Operation\DropCollection; ...@@ -21,14 +22,16 @@ use MongoDB\Operation\DropCollection;
*/ */
class DocumentationExamplesTest extends FunctionalTestCase class DocumentationExamplesTest extends FunctionalTestCase
{ {
public function setUp() use SetUpTearDownTrait;
private function doSetUp()
{ {
parent::setUp(); parent::setUp();
$this->dropCollection(); $this->dropCollection();
} }
public function tearDown() private function doTearDown()
{ {
if ($this->hasFailed()) { if ($this->hasFailed()) {
return; return;
...@@ -495,7 +498,7 @@ class DocumentationExamplesTest extends FunctionalTestCase ...@@ -495,7 +498,7 @@ class DocumentationExamplesTest extends FunctionalTestCase
$this->assertSame(2, $insertManyResult->getInsertedCount()); $this->assertSame(2, $insertManyResult->getInsertedCount());
foreach ($insertManyResult->getInsertedIds() as $id) { foreach ($insertManyResult->getInsertedIds() as $id) {
$this->assertInternalType('int', $id); $this->assertIsInt($id);
} }
$this->assertInventoryCount(2); $this->assertInventoryCount(2);
......
...@@ -15,15 +15,18 @@ use MongoDB\Operation\DatabaseCommand; ...@@ -15,15 +15,18 @@ use MongoDB\Operation\DatabaseCommand;
use MongoDB\Operation\DropCollection; use MongoDB\Operation\DropCollection;
use InvalidArgumentException; use InvalidArgumentException;
use stdClass; use stdClass;
use Symfony\Bridge\PhpUnit\SetUpTearDownTrait;
use UnexpectedValueException; use UnexpectedValueException;
abstract class FunctionalTestCase extends TestCase abstract class FunctionalTestCase extends TestCase
{ {
use SetUpTearDownTrait;
protected $manager; protected $manager;
private $configuredFailPoints = []; private $configuredFailPoints = [];
public function setUp() private function doSetUp()
{ {
parent::setUp(); parent::setUp();
...@@ -31,7 +34,7 @@ abstract class FunctionalTestCase extends TestCase ...@@ -31,7 +34,7 @@ abstract class FunctionalTestCase extends TestCase
$this->configuredFailPoints = []; $this->configuredFailPoints = [];
} }
public function tearDown() private function doTearDown()
{ {
$this->disableFailPoints(); $this->disableFailPoints();
......
...@@ -502,7 +502,7 @@ class BucketFunctionalTest extends FunctionalTestCase ...@@ -502,7 +502,7 @@ class BucketFunctionalTest extends FunctionalTestCase
$expectedReadLength = min(4096, strlen($input) - strlen($buffer)); $expectedReadLength = min(4096, strlen($input) - strlen($buffer));
$buffer .= $read = fread($stream, 4096); $buffer .= $read = fread($stream, 4096);
$this->assertInternalType('string', $read); $this->assertIsString($read);
$this->assertEquals($expectedReadLength, strlen($read)); $this->assertEquals($expectedReadLength, strlen($read));
} }
......
...@@ -5,17 +5,20 @@ namespace MongoDB\Tests\GridFS; ...@@ -5,17 +5,20 @@ namespace MongoDB\Tests\GridFS;
use MongoDB\Collection; use MongoDB\Collection;
use MongoDB\GridFS\Bucket; use MongoDB\GridFS\Bucket;
use MongoDB\Tests\FunctionalTestCase as BaseFunctionalTestCase; use MongoDB\Tests\FunctionalTestCase as BaseFunctionalTestCase;
use Symfony\Bridge\PhpUnit\SetUpTearDownTrait;
/** /**
* Base class for GridFS functional tests. * Base class for GridFS functional tests.
*/ */
abstract class FunctionalTestCase extends BaseFunctionalTestCase abstract class FunctionalTestCase extends BaseFunctionalTestCase
{ {
use SetUpTearDownTrait;
protected $bucket; protected $bucket;
protected $chunksCollection; protected $chunksCollection;
protected $filesCollection; protected $filesCollection;
public function setUp() private function doSetUp()
{ {
parent::setUp(); parent::setUp();
...@@ -36,7 +39,7 @@ abstract class FunctionalTestCase extends BaseFunctionalTestCase ...@@ -36,7 +39,7 @@ abstract class FunctionalTestCase extends BaseFunctionalTestCase
*/ */
protected function assertStreamContents($expectedContents, $stream) protected function assertStreamContents($expectedContents, $stream)
{ {
$this->assertInternalType('resource', $stream); $this->assertIsResource($stream);
$this->assertSame('stream', get_resource_type($stream)); $this->assertSame('stream', get_resource_type($stream));
$this->assertEquals($expectedContents, stream_get_contents($stream, -1, 0)); $this->assertEquals($expectedContents, stream_get_contents($stream, -1, 0));
} }
......
...@@ -9,15 +9,18 @@ use MongoDB\GridFS\ReadableStream; ...@@ -9,15 +9,18 @@ use MongoDB\GridFS\ReadableStream;
use MongoDB\GridFS\Exception\CorruptFileException; use MongoDB\GridFS\Exception\CorruptFileException;
use MongoDB\Tests\CommandObserver; use MongoDB\Tests\CommandObserver;
use stdClass; use stdClass;
use Symfony\Bridge\PhpUnit\SetUpTearDownTrait;
/** /**
* Functional tests for the internal ReadableStream class. * Functional tests for the internal ReadableStream class.
*/ */
class ReadableStreamFunctionalTest extends FunctionalTestCase class ReadableStreamFunctionalTest extends FunctionalTestCase
{ {
use SetUpTearDownTrait;
private $collectionWrapper; private $collectionWrapper;
public function setUp() private function doSetUp()
{ {
parent::setUp(); parent::setUp();
......
...@@ -13,6 +13,7 @@ use Exception; ...@@ -13,6 +13,7 @@ use Exception;
use IteratorIterator; use IteratorIterator;
use LogicException; use LogicException;
use MultipleIterator; use MultipleIterator;
use Symfony\Bridge\PhpUnit\SetUpTearDownTrait;
/** /**
* GridFS spec functional tests. * GridFS spec functional tests.
...@@ -21,10 +22,12 @@ use MultipleIterator; ...@@ -21,10 +22,12 @@ use MultipleIterator;
*/ */
class SpecFunctionalTest extends FunctionalTestCase class SpecFunctionalTest extends FunctionalTestCase
{ {
use SetUpTearDownTrait;
private $expectedChunksCollection; private $expectedChunksCollection;
private $expectedFilesCollection; private $expectedFilesCollection;
public function setUp() private function doSetUp()
{ {
parent::setUp(); parent::setUp();
......
...@@ -4,13 +4,16 @@ namespace MongoDB\Tests\GridFS; ...@@ -4,13 +4,16 @@ namespace MongoDB\Tests\GridFS;
use MongoDB\BSON\Binary; use MongoDB\BSON\Binary;
use MongoDB\BSON\UTCDateTime; use MongoDB\BSON\UTCDateTime;
use Symfony\Bridge\PhpUnit\SetUpTearDownTrait;
/** /**
* Functional tests for the internal StreamWrapper class. * Functional tests for the internal StreamWrapper class.
*/ */
class StreamWrapperFunctionalTest extends FunctionalTestCase class StreamWrapperFunctionalTest extends FunctionalTestCase
{ {
public function setUp() use SetUpTearDownTrait;
private function doSetUp()
{ {
parent::setUp(); parent::setUp();
......
...@@ -5,15 +5,18 @@ namespace MongoDB\Tests\GridFS; ...@@ -5,15 +5,18 @@ namespace MongoDB\Tests\GridFS;
use MongoDB\Exception\InvalidArgumentException; use MongoDB\Exception\InvalidArgumentException;
use MongoDB\GridFS\CollectionWrapper; use MongoDB\GridFS\CollectionWrapper;
use MongoDB\GridFS\WritableStream; use MongoDB\GridFS\WritableStream;
use Symfony\Bridge\PhpUnit\SetUpTearDownTrait;
/** /**
* Functional tests for the internal WritableStream class. * Functional tests for the internal WritableStream class.
*/ */
class WritableStreamFunctionalTest extends FunctionalTestCase class WritableStreamFunctionalTest extends FunctionalTestCase
{ {
use SetUpTearDownTrait;
private $collectionWrapper; private $collectionWrapper;
public function setUp() private function doSetUp()
{ {
parent::setUp(); parent::setUp();
......
...@@ -11,12 +11,15 @@ use MongoDB\Operation\CreateCollection; ...@@ -11,12 +11,15 @@ use MongoDB\Operation\CreateCollection;
use MongoDB\Operation\DropCollection; use MongoDB\Operation\DropCollection;
use MongoDB\Tests\CommandObserver; use MongoDB\Tests\CommandObserver;
use MongoDB\Tests\FunctionalTestCase; use MongoDB\Tests\FunctionalTestCase;
use Symfony\Bridge\PhpUnit\SetUpTearDownTrait;
class ChangeStreamIteratorTest extends FunctionalTestCase class ChangeStreamIteratorTest extends FunctionalTestCase
{ {
use SetUpTearDownTrait;
private $collection; private $collection;
public function setUp() private function doSetUp()
{ {
parent::setUp(); parent::setUp();
......
...@@ -4,12 +4,15 @@ namespace MongoDB\Tests\Model; ...@@ -4,12 +4,15 @@ namespace MongoDB\Tests\Model;
use MongoDB\Collection; use MongoDB\Collection;
use MongoDB\Tests\FunctionalTestCase; use MongoDB\Tests\FunctionalTestCase;
use Symfony\Bridge\PhpUnit\SetUpTearDownTrait;
class IndexInfoFunctionalTest extends FunctionalTestCase class IndexInfoFunctionalTest extends FunctionalTestCase
{ {
use SetUpTearDownTrait;
private $collection; private $collection;
public function setUp() private function doSetUp()
{ {
parent::setUp(); parent::setUp();
...@@ -17,7 +20,7 @@ class IndexInfoFunctionalTest extends FunctionalTestCase ...@@ -17,7 +20,7 @@ class IndexInfoFunctionalTest extends FunctionalTestCase
$this->collection->drop(); $this->collection->drop();
} }
public function tearDown() private function doTearDown()
{ {
if ($this->hasFailed()) { if ($this->hasFailed()) {
return; return;
......
...@@ -12,12 +12,15 @@ use MongoDB\Model\BSONDocument; ...@@ -12,12 +12,15 @@ use MongoDB\Model\BSONDocument;
use MongoDB\Operation\BulkWrite; use MongoDB\Operation\BulkWrite;
use MongoDB\Tests\CommandObserver; use MongoDB\Tests\CommandObserver;
use stdClass; use stdClass;
use Symfony\Bridge\PhpUnit\SetUpTearDownTrait;
class BulkWriteFunctionalTest extends FunctionalTestCase class BulkWriteFunctionalTest extends FunctionalTestCase
{ {
use SetUpTearDownTrait;
private $collection; private $collection;
public function setUp() private function doSetUp()
{ {
parent::setUp(); parent::setUp();
......
...@@ -10,12 +10,15 @@ use MongoDB\Exception\BadMethodCallException; ...@@ -10,12 +10,15 @@ use MongoDB\Exception\BadMethodCallException;
use MongoDB\Operation\Delete; use MongoDB\Operation\Delete;
use MongoDB\Tests\CommandObserver; use MongoDB\Tests\CommandObserver;
use stdClass; use stdClass;
use Symfony\Bridge\PhpUnit\SetUpTearDownTrait;
class DeleteFunctionalTest extends FunctionalTestCase class DeleteFunctionalTest extends FunctionalTestCase
{ {
use SetUpTearDownTrait;
private $collection; private $collection;
public function setUp() private function doSetUp()
{ {
parent::setUp(); parent::setUp();
......
...@@ -8,20 +8,23 @@ use MongoDB\Driver\ReadPreference; ...@@ -8,20 +8,23 @@ use MongoDB\Driver\ReadPreference;
use MongoDB\Driver\WriteConcern; use MongoDB\Driver\WriteConcern;
use MongoDB\Operation\DropCollection; use MongoDB\Operation\DropCollection;
use MongoDB\Tests\FunctionalTestCase as BaseFunctionalTestCase; use MongoDB\Tests\FunctionalTestCase as BaseFunctionalTestCase;
use Symfony\Bridge\PhpUnit\SetUpTearDownTrait;
/** /**
* Base class for Operation functional tests. * Base class for Operation functional tests.
*/ */
abstract class FunctionalTestCase extends BaseFunctionalTestCase abstract class FunctionalTestCase extends BaseFunctionalTestCase
{ {
public function setUp() use SetUpTearDownTrait;
private function doSetUp()
{ {
parent::setUp(); parent::setUp();
$this->dropCollection(); $this->dropCollection();
} }
public function tearDown() private function doTearDown()
{ {
if ($this->hasFailed()) { if ($this->hasFailed()) {
return; return;
......
...@@ -10,12 +10,15 @@ use MongoDB\Model\BSONDocument; ...@@ -10,12 +10,15 @@ use MongoDB\Model\BSONDocument;
use MongoDB\Operation\InsertMany; use MongoDB\Operation\InsertMany;
use MongoDB\Tests\CommandObserver; use MongoDB\Tests\CommandObserver;
use stdClass; use stdClass;
use Symfony\Bridge\PhpUnit\SetUpTearDownTrait;
class InsertManyFunctionalTest extends FunctionalTestCase class InsertManyFunctionalTest extends FunctionalTestCase
{ {
use SetUpTearDownTrait;
private $collection; private $collection;
public function setUp() private function doSetUp()
{ {
parent::setUp(); parent::setUp();
......
...@@ -10,12 +10,15 @@ use MongoDB\Model\BSONDocument; ...@@ -10,12 +10,15 @@ use MongoDB\Model\BSONDocument;
use MongoDB\Operation\InsertOne; use MongoDB\Operation\InsertOne;
use MongoDB\Tests\CommandObserver; use MongoDB\Tests\CommandObserver;
use stdClass; use stdClass;
use Symfony\Bridge\PhpUnit\SetUpTearDownTrait;
class InsertOneFunctionalTest extends FunctionalTestCase class InsertOneFunctionalTest extends FunctionalTestCase
{ {
use SetUpTearDownTrait;
private $collection; private $collection;
public function setUp() private function doSetUp()
{ {
parent::setUp(); parent::setUp();
......
...@@ -10,12 +10,15 @@ use MongoDB\Exception\BadMethodCallException; ...@@ -10,12 +10,15 @@ use MongoDB\Exception\BadMethodCallException;
use MongoDB\Operation\Update; use MongoDB\Operation\Update;
use MongoDB\Tests\CommandObserver; use MongoDB\Tests\CommandObserver;
use stdClass; use stdClass;
use Symfony\Bridge\PhpUnit\SetUpTearDownTrait;
class UpdateFunctionalTest extends FunctionalTestCase class UpdateFunctionalTest extends FunctionalTestCase
{ {
use SetUpTearDownTrait;
private $collection; private $collection;
public function setUp() private function doSetUp()
{ {
parent::setUp(); parent::setUp();
......
...@@ -19,14 +19,17 @@ use MongoDB\Operation\Watch; ...@@ -19,14 +19,17 @@ use MongoDB\Operation\Watch;
use MongoDB\Tests\CommandObserver; use MongoDB\Tests\CommandObserver;
use stdClass; use stdClass;
use ReflectionClass; use ReflectionClass;
use Symfony\Bridge\PhpUnit\SetUpTearDownTrait;
class WatchFunctionalTest extends FunctionalTestCase class WatchFunctionalTest extends FunctionalTestCase
{ {
use SetUpTearDownTrait;
private static $wireVersionForStartAtOperationTime = 7; private static $wireVersionForStartAtOperationTime = 7;
private $defaultOptions = ['maxAwaitTimeMS' => 500]; private $defaultOptions = ['maxAwaitTimeMS' => 500];
public function setUp() private function doSetUp()
{ {
parent::setUp(); parent::setUp();
...@@ -274,7 +277,7 @@ class WatchFunctionalTest extends FunctionalTestCase ...@@ -274,7 +277,7 @@ class WatchFunctionalTest extends FunctionalTestCase
private function assertResumeAfter($expectedResumeToken, stdClass $command) private function assertResumeAfter($expectedResumeToken, stdClass $command)
{ {
$this->assertObjectHasAttribute('pipeline', $command); $this->assertObjectHasAttribute('pipeline', $command);
$this->assertInternalType('array', $command->pipeline); $this->assertIsArray($command->pipeline);
$this->assertArrayHasKey(0, $command->pipeline); $this->assertArrayHasKey(0, $command->pipeline);
$this->assertObjectHasAttribute('$changeStream', $command->pipeline[0]); $this->assertObjectHasAttribute('$changeStream', $command->pipeline[0]);
$this->assertObjectHasAttribute('resumeAfter', $command->pipeline[0]->{'$changeStream'}); $this->assertObjectHasAttribute('resumeAfter', $command->pipeline[0]->{'$changeStream'});
...@@ -351,7 +354,7 @@ class WatchFunctionalTest extends FunctionalTestCase ...@@ -351,7 +354,7 @@ class WatchFunctionalTest extends FunctionalTestCase
private function assertStartAtOperationTime(TimestampInterface $expectedOperationTime, stdClass $command) private function assertStartAtOperationTime(TimestampInterface $expectedOperationTime, stdClass $command)
{ {
$this->assertObjectHasAttribute('pipeline', $command); $this->assertObjectHasAttribute('pipeline', $command);
$this->assertInternalType('array', $command->pipeline); $this->assertIsArray($command->pipeline);
$this->assertArrayHasKey(0, $command->pipeline); $this->assertArrayHasKey(0, $command->pipeline);
$this->assertObjectHasAttribute('$changeStream', $command->pipeline[0]); $this->assertObjectHasAttribute('$changeStream', $command->pipeline[0]);
$this->assertObjectHasAttribute('startAtOperationTime', $command->pipeline[0]->{'$changeStream'}); $this->assertObjectHasAttribute('startAtOperationTime', $command->pipeline[0]->{'$changeStream'});
...@@ -1180,7 +1183,7 @@ class WatchFunctionalTest extends FunctionalTestCase ...@@ -1180,7 +1183,7 @@ class WatchFunctionalTest extends FunctionalTestCase
$rp = $rc->getProperty('resumeCallable'); $rp = $rc->getProperty('resumeCallable');
$rp->setAccessible(true); $rp->setAccessible(true);
$this->assertInternalType('callable', $rp->getValue($changeStream)); $this->assertIsCallable($rp->getValue($changeStream));
// Invalidate the cursor to verify that resumeCallable is unset when the cursor is exhausted. // Invalidate the cursor to verify that resumeCallable is unset when the cursor is exhausted.
$this->dropCollection(); $this->dropCollection();
...@@ -1207,9 +1210,9 @@ class WatchFunctionalTest extends FunctionalTestCase ...@@ -1207,9 +1210,9 @@ class WatchFunctionalTest extends FunctionalTestCase
private function getPostBatchResumeTokenFromReply(stdClass $reply) private function getPostBatchResumeTokenFromReply(stdClass $reply)
{ {
$this->assertObjectHasAttribute('cursor', $reply); $this->assertObjectHasAttribute('cursor', $reply);
$this->assertInternalType('object', $reply->cursor); $this->assertIsObject($reply->cursor);
$this->assertObjectHasAttribute('postBatchResumeToken', $reply->cursor); $this->assertObjectHasAttribute('postBatchResumeToken', $reply->cursor);
$this->assertInternalType('object', $reply->cursor->postBatchResumeToken); $this->assertIsObject($reply->cursor->postBatchResumeToken);
return $reply->cursor->postBatchResumeToken; return $reply->cursor->postBatchResumeToken;
} }
......
...@@ -32,7 +32,7 @@ class CommandMonitoringSpecTest extends FunctionalTestCase ...@@ -32,7 +32,7 @@ class CommandMonitoringSpecTest extends FunctionalTestCase
if (isset($expected->killCursors) && isset($expected->cursors) && is_array($expected->cursors)) { if (isset($expected->killCursors) && isset($expected->cursors) && is_array($expected->cursors)) {
static::assertObjectHasAttribute('cursors', $actual); static::assertObjectHasAttribute('cursors', $actual);
static::assertInternalType('array', $actual->cursors); static::assertIsArray($actual->cursors);
foreach ($expected->cursors as $i => $cursorId) { foreach ($expected->cursors as $i => $cursorId) {
static::assertArrayHasKey($i, $actual->cursors); static::assertArrayHasKey($i, $actual->cursors);
...@@ -63,7 +63,7 @@ class CommandMonitoringSpecTest extends FunctionalTestCase ...@@ -63,7 +63,7 @@ class CommandMonitoringSpecTest extends FunctionalTestCase
{ {
if (isset($expected->cursor->id) && $expected->cursor->id === 42) { if (isset($expected->cursor->id) && $expected->cursor->id === 42) {
static::assertObjectHasAttribute('cursor', $actual); static::assertObjectHasAttribute('cursor', $actual);
static::assertInternalType('object', $actual->cursor); static::assertIsObject($actual->cursor);
static::assertObjectHasAttribute('id', $actual->cursor); static::assertObjectHasAttribute('id', $actual->cursor);
static::assertThat($actual->cursor->id, static::logicalOr( static::assertThat($actual->cursor->id, static::logicalOr(
static::isInstanceOf(Int64::class), static::isInstanceOf(Int64::class),
...@@ -74,7 +74,7 @@ class CommandMonitoringSpecTest extends FunctionalTestCase ...@@ -74,7 +74,7 @@ class CommandMonitoringSpecTest extends FunctionalTestCase
if (isset($expected->cursorsUnknown) && is_array($expected->cursorsUnknown)) { if (isset($expected->cursorsUnknown) && is_array($expected->cursorsUnknown)) {
static::assertObjectHasAttribute('cursorsUnknown', $actual); static::assertObjectHasAttribute('cursorsUnknown', $actual);
static::assertInternalType('array', $actual->cursorsUnknown); static::assertIsArray($actual->cursorsUnknown);
foreach ($expected->cursorsUnknown as $i => $cursorId) { foreach ($expected->cursorsUnknown as $i => $cursorId) {
static::assertArrayHasKey($i, $actual->cursorsUnknown); static::assertArrayHasKey($i, $actual->cursorsUnknown);
...@@ -92,14 +92,14 @@ class CommandMonitoringSpecTest extends FunctionalTestCase ...@@ -92,14 +92,14 @@ class CommandMonitoringSpecTest extends FunctionalTestCase
if (isset($expected->ok) && is_numeric($expected->ok)) { if (isset($expected->ok) && is_numeric($expected->ok)) {
static::assertObjectHasAttribute('ok', $actual); static::assertObjectHasAttribute('ok', $actual);
static::assertInternalType('numeric', $actual->ok); static::assertIsNumeric($actual->ok);
static::assertEquals($expected->ok, $actual->ok); static::assertEquals($expected->ok, $actual->ok);
unset($expected->ok); unset($expected->ok);
} }
if (isset($expected->writeErrors) && is_array($expected->writeErrors)) { if (isset($expected->writeErrors) && is_array($expected->writeErrors)) {
static::assertObjectHasAttribute('writeErrors', $actual); static::assertObjectHasAttribute('writeErrors', $actual);
static::assertInternalType('array', $actual->writeErrors); static::assertIsArray($actual->writeErrors);
foreach ($expected->writeErrors as $i => $expectedWriteError) { foreach ($expected->writeErrors as $i => $expectedWriteError) {
static::assertArrayHasKey($i, $actual->writeErrors); static::assertArrayHasKey($i, $actual->writeErrors);
...@@ -116,7 +116,7 @@ class CommandMonitoringSpecTest extends FunctionalTestCase ...@@ -116,7 +116,7 @@ class CommandMonitoringSpecTest extends FunctionalTestCase
if (isset($expectedWriteError->errmsg) && $expectedWriteError->errmsg === '') { if (isset($expectedWriteError->errmsg) && $expectedWriteError->errmsg === '') {
static::assertObjectHasAttribute('errmsg', $actualWriteError); static::assertObjectHasAttribute('errmsg', $actualWriteError);
static::assertInternalType('string', $actualWriteError->errmsg); static::assertIsString($actualWriteError->errmsg);
static::assertNotEmpty($actualWriteError->errmsg); static::assertNotEmpty($actualWriteError->errmsg);
unset($expected->writeErrors[$i]->errmsg); unset($expected->writeErrors[$i]->errmsg);
} }
......
...@@ -9,6 +9,7 @@ use ArrayObject; ...@@ -9,6 +9,7 @@ use ArrayObject;
use InvalidArgumentException; use InvalidArgumentException;
use RuntimeException; use RuntimeException;
use stdClass; use stdClass;
use Symfony\Bridge\PhpUnit\ConstraintTrait;
/** /**
* Constraint that checks if one document matches another. * Constraint that checks if one document matches another.
...@@ -17,6 +18,8 @@ use stdClass; ...@@ -17,6 +18,8 @@ use stdClass;
*/ */
class DocumentsMatchConstraint extends Constraint class DocumentsMatchConstraint extends Constraint
{ {
use ConstraintTrait;
private $ignoreExtraKeysInRoot = false; private $ignoreExtraKeysInRoot = false;
private $ignoreExtraKeysInEmbedded = false; private $ignoreExtraKeysInEmbedded = false;
private $placeholders = []; private $placeholders = [];
...@@ -38,50 +41,12 @@ class DocumentsMatchConstraint extends Constraint ...@@ -38,50 +41,12 @@ class DocumentsMatchConstraint extends Constraint
*/ */
public function __construct($value, $ignoreExtraKeysInRoot = false, $ignoreExtraKeysInEmbedded = false, array $placeholders = []) public function __construct($value, $ignoreExtraKeysInRoot = false, $ignoreExtraKeysInEmbedded = false, array $placeholders = [])
{ {
parent::__construct();
$this->value = $this->prepareBSON($value, true, $this->sortKeys); $this->value = $this->prepareBSON($value, true, $this->sortKeys);
$this->ignoreExtraKeysInRoot = $ignoreExtraKeysInRoot; $this->ignoreExtraKeysInRoot = $ignoreExtraKeysInRoot;
$this->ignoreExtraKeysInEmbedded = $ignoreExtraKeysInEmbedded; $this->ignoreExtraKeysInEmbedded = $ignoreExtraKeysInEmbedded;
$this->placeholders = $placeholders; $this->placeholders = $placeholders;
} }
/**
* Returns a string representation of the constraint.
*
* @return string
*/
public function toString()
{
return 'matches ' . json_encode($this->value);
}
/**
* Evaluates the constraint for parameter $other. Returns true if the
* constraint is met, false otherwise.
*
* @param mixed $other
* @return boolean
*/
protected function matches($other)
{
/* TODO: If ignoreExtraKeys and sortKeys are both false, then we may be
* able to skip preparation, convert both documents to extended JSON,
* and compare strings.
*
* If ignoreExtraKeys is false and sortKeys is true, we still be able to
* compare JSON strings but will still require preparation to sort keys
* in all documents and sub-documents. */
$other = $this->prepareBSON($other, true, $this->sortKeys);
try {
$this->assertEquals($this->value, $other, $this->ignoreExtraKeysInRoot);
} catch (RuntimeException $e) {
return false;
}
return true;
}
/** /**
* Compares two documents recursively. * Compares two documents recursively.
* *
...@@ -131,6 +96,31 @@ class DocumentsMatchConstraint extends Constraint ...@@ -131,6 +96,31 @@ class DocumentsMatchConstraint extends Constraint
} }
} }
private function doMatches($other)
{
/* TODO: If ignoreExtraKeys and sortKeys are both false, then we may be
* able to skip preparation, convert both documents to extended JSON,
* and compare strings.
*
* If ignoreExtraKeys is false and sortKeys is true, we still be able to
* compare JSON strings but will still require preparation to sort keys
* in all documents and sub-documents. */
$other = $this->prepareBSON($other, true, $this->sortKeys);
try {
$this->assertEquals($this->value, $other, $this->ignoreExtraKeysInRoot);
} catch (RuntimeException $e) {
return false;
}
return true;
}
private function doToString()
{
return 'matches ' . json_encode($this->value);
}
/** /**
* Prepare a BSON document or array for comparison. * Prepare a BSON document or array for comparison.
* *
......
...@@ -17,6 +17,7 @@ use IteratorIterator; ...@@ -17,6 +17,7 @@ use IteratorIterator;
use LogicException; use LogicException;
use MultipleIterator; use MultipleIterator;
use stdClass; use stdClass;
use Symfony\Bridge\PhpUnit\SetUpTearDownTrait;
use UnexpectedValueException; use UnexpectedValueException;
/** /**
...@@ -26,20 +27,22 @@ use UnexpectedValueException; ...@@ -26,20 +27,22 @@ use UnexpectedValueException;
*/ */
class FunctionalTestCase extends BaseFunctionalTestCase class FunctionalTestCase extends BaseFunctionalTestCase
{ {
use SetUpTearDownTrait;
const TOPOLOGY_SINGLE = 'single'; const TOPOLOGY_SINGLE = 'single';
const TOPOLOGY_REPLICASET = 'replicaset'; const TOPOLOGY_REPLICASET = 'replicaset';
const TOPOLOGY_SHARDED = 'sharded'; const TOPOLOGY_SHARDED = 'sharded';
private $context; private $context;
public function setUp() private function doSetUp()
{ {
parent::setUp(); parent::setUp();
$this->context = null; $this->context = null;
} }
public function tearDown() private function doTearDown()
{ {
$this->context = null; $this->context = null;
......
...@@ -216,7 +216,7 @@ final class ResultExpectation ...@@ -216,7 +216,7 @@ final class ResultExpectation
break; break;
case self::ASSERT_MATCHES_DOCUMENT: case self::ASSERT_MATCHES_DOCUMENT:
$test->assertInternalType('object', $expected); $test->assertIsObject($expected);
$test->assertThat($actual, $test->logicalOr( $test->assertThat($actual, $test->logicalOr(
$test->isType('array'), $test->isType('array'),
$test->isType('object') $test->isType('object')
...@@ -236,7 +236,7 @@ final class ResultExpectation ...@@ -236,7 +236,7 @@ final class ResultExpectation
break; break;
case self::ASSERT_SAME_DOCUMENT: case self::ASSERT_SAME_DOCUMENT:
$test->assertInternalType('object', $expected); $test->assertIsObject($expected);
$test->assertThat($actual, $test->logicalOr( $test->assertThat($actual, $test->logicalOr(
$test->isType('array'), $test->isType('array'),
$test->isType('object') $test->isType('object')
......
...@@ -12,6 +12,7 @@ use MongoDB\Driver\Server; ...@@ -12,6 +12,7 @@ use MongoDB\Driver\Server;
use MongoDB\Driver\WriteConcern; use MongoDB\Driver\WriteConcern;
use MongoDB\Driver\Exception\ServerException; use MongoDB\Driver\Exception\ServerException;
use stdClass; use stdClass;
use Symfony\Bridge\PhpUnit\SetUpTearDownTrait;
/** /**
* Transactions spec tests. * Transactions spec tests.
...@@ -20,6 +21,8 @@ use stdClass; ...@@ -20,6 +21,8 @@ use stdClass;
*/ */
class TransactionsSpecTest extends FunctionalTestCase class TransactionsSpecTest extends FunctionalTestCase
{ {
use SetUpTearDownTrait;
const INTERRUPTED = 11601; const INTERRUPTED = 11601;
/* In addition to the useMultipleMongoses tests, these should all pass /* In addition to the useMultipleMongoses tests, these should all pass
...@@ -38,14 +41,14 @@ class TransactionsSpecTest extends FunctionalTestCase ...@@ -38,14 +41,14 @@ class TransactionsSpecTest extends FunctionalTestCase
'transaction-options: readConcern snapshot in startTransaction options' => 'PHPLIB does not properly inherit readConcern for transactions', 'transaction-options: readConcern snapshot in startTransaction options' => 'PHPLIB does not properly inherit readConcern for transactions',
]; ];
public static function setUpBeforeClass() private static function doSetUpBeforeClass()
{ {
parent::setUpBeforeClass(); parent::setUpBeforeClass();
static::killAllSessions(); static::killAllSessions();
} }
public function tearDown() private function doTearDown()
{ {
if ($this->hasFailed()) { if ($this->hasFailed()) {
static::killAllSessions(); static::killAllSessions();
...@@ -75,13 +78,13 @@ class TransactionsSpecTest extends FunctionalTestCase ...@@ -75,13 +78,13 @@ class TransactionsSpecTest extends FunctionalTestCase
if (isset($expected->recoveryToken) && $expected->recoveryToken === 42) { if (isset($expected->recoveryToken) && $expected->recoveryToken === 42) {
static::assertObjectHasAttribute('recoveryToken', $actual); static::assertObjectHasAttribute('recoveryToken', $actual);
static::assertInternalType('object', $actual->recoveryToken); static::assertIsObject($actual->recoveryToken);
unset($expected->recoveryToken); unset($expected->recoveryToken);
} }
if (isset($expected->readConcern->afterClusterTime) && $expected->readConcern->afterClusterTime === 42) { if (isset($expected->readConcern->afterClusterTime) && $expected->readConcern->afterClusterTime === 42) {
static::assertObjectHasAttribute('readConcern', $actual); static::assertObjectHasAttribute('readConcern', $actual);
static::assertInternalType('object', $actual->readConcern); static::assertIsObject($actual->readConcern);
static::assertObjectHasAttribute('afterClusterTime', $actual->readConcern); static::assertObjectHasAttribute('afterClusterTime', $actual->readConcern);
static::assertInstanceOf(Timestamp::class, $actual->readConcern->afterClusterTime); static::assertInstanceOf(Timestamp::class, $actual->readConcern->afterClusterTime);
unset($expected->readConcern->afterClusterTime); unset($expected->readConcern->afterClusterTime);
......
...@@ -7,6 +7,7 @@ use MongoDB\Driver\ReadPreference; ...@@ -7,6 +7,7 @@ use MongoDB\Driver\ReadPreference;
use MongoDB\Driver\WriteConcern; use MongoDB\Driver\WriteConcern;
use MongoDB\Model\BSONArray; use MongoDB\Model\BSONArray;
use MongoDB\Model\BSONDocument; use MongoDB\Model\BSONDocument;
use MongoDB\Tests\Compat\PolyfillAssertTrait;
use PHPUnit\Framework\TestCase as BaseTestCase; use PHPUnit\Framework\TestCase as BaseTestCase;
use InvalidArgumentException; use InvalidArgumentException;
use ReflectionClass; use ReflectionClass;
...@@ -15,6 +16,8 @@ use Traversable; ...@@ -15,6 +16,8 @@ use Traversable;
abstract class TestCase extends BaseTestCase abstract class TestCase extends BaseTestCase
{ {
use PolyfillAssertTrait;
/** /**
* Return the connection URI. * Return the connection URI.
* *
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment