Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PHPLIB-1525 Removes dependency to Symfony PHPUnit bridge #1413

Open
wants to merge 6 commits into
base: v1.x
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 7 additions & 7 deletions .evergreen/run-tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -83,30 +83,30 @@ export MONGODB_MULTI_MONGOS_LB_URI="${MONGODB_MULTI_MONGOS_LB_URI}"
# Run the tests, and store the results in a junit result file
case "$TESTS" in
atlas)
php vendor/bin/simple-phpunit $PHPUNIT_OPTS --group atlas
php vendor/bin/phpunit $PHPUNIT_OPTS --group atlas
;;

atlas-data-lake)
php vendor/bin/simple-phpunit $PHPUNIT_OPTS --group atlas-data-lake
php vendor/bin/phpunit $PHPUNIT_OPTS --group atlas-data-lake
;;

csfle)
php vendor/bin/simple-phpunit $PHPUNIT_OPTS --group csfle
php vendor/bin/phpunit $PHPUNIT_OPTS --group csfle
;;

csfle-without-aws-creds)
php vendor/bin/simple-phpunit $PHPUNIT_OPTS --group csfle-without-aws-creds
php vendor/bin/phpunit $PHPUNIT_OPTS --group csfle-without-aws-creds
;;

versioned-api)
php vendor/bin/simple-phpunit $PHPUNIT_OPTS --group versioned-api
php vendor/bin/phpunit $PHPUNIT_OPTS --group versioned-api
;;

serverless)
php vendor/bin/simple-phpunit $PHPUNIT_OPTS --group serverless
php vendor/bin/phpunit $PHPUNIT_OPTS --group serverless
;;

*)
php vendor/bin/simple-phpunit $PHPUNIT_OPTS
php vendor/bin/phpunit $PHPUNIT_OPTS
;;
esac
2 changes: 1 addition & 1 deletion .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ jobs:
php-ini-values: "zend.assertions=1"

- name: "Run PHPUnit"
run: "vendor/bin/simple-phpunit -v"
run: "vendor/bin/phpunit -v"
env:
SYMFONY_DEPRECATIONS_HELPER: 999999
MONGODB_URI: ${{ steps.setup-mongodb.outputs.cluster-uri }}
8 changes: 0 additions & 8 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,14 +43,6 @@ credentials in the connection string (i.e. `MONGODB_URI`) or set the
Note that `MONGODB_USERNAME` and `MONGODB_PASSWORD` will override any
credentials present in the connection string.

By default, the `simple-phpunit` binary chooses the correct PHPUnit version for
the PHP version you are running. To run tests against a specific PHPUnit
version, use the `SYMFONY_PHPUNIT_VERSION` environment variable:

```console
$ SYMFONY_PHPUNIT_VERSION=8.5 vendor/bin/simple-phpunit
```

### Environment Variables

The test suite references the following environment variables:
Expand Down
4 changes: 2 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@
},
"require-dev": {
"doctrine/coding-standard": "^12.0",
"phpunit/phpunit": "^9.6",
"rector/rector": "^1.1",
"squizlabs/php_codesniffer": "^3.7",
"symfony/phpunit-bridge": "^7.1",
"vimeo/psalm": "^5.13"
},
"replace": {
Expand Down Expand Up @@ -51,7 +51,7 @@
"fix:cs": "phpcbf",
"fix:psalm:baseline": "psalm --set-baseline=psalm-baseline.xml",
"fix:rector": "rector process --ansi",
"test": "simple-phpunit"
"test": "phpunit"
},
"extra": {
"branch-alias": {
Expand Down
6 changes: 0 additions & 6 deletions tests/GridFS/BucketFunctionalTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -871,7 +871,6 @@ public function testDanglingOpenWritableStream(): void
}

$code = <<<'PHP'
require '%s';
require '%s';
$client = MongoDB\Tests\FunctionalTestCase::createTestClient();
$database = $client->selectDatabase(getenv('MONGODB_DATABASE') ?: 'phplib_test');
Expand All @@ -888,8 +887,6 @@ public function testDanglingOpenWritableStream(): void
sprintf(
$code,
__DIR__ . '/../../vendor/autoload.php',
// Include the PHPUnit autoload file to ensure PHPUnit classes can be loaded
__DIR__ . '/../../vendor/bin/.phpunit/phpunit/vendor/autoload.php',
),
),
'2>&1',
Expand All @@ -914,7 +911,6 @@ public function testDanglingOpenWritableStreamWithGlobalStreamWrapperAlias(): vo
}

$code = <<<'PHP'
require '%s';
require '%s';
$client = MongoDB\Tests\FunctionalTestCase::createTestClient();
$database = $client->selectDatabase(getenv('MONGODB_DATABASE') ?: 'phplib_test');
Expand All @@ -931,8 +927,6 @@ public function testDanglingOpenWritableStreamWithGlobalStreamWrapperAlias(): vo
sprintf(
$code,
__DIR__ . '/../../vendor/autoload.php',
// Include the PHPUnit autoload file to ensure PHPUnit classes can be loaded
__DIR__ . '/../../vendor/bin/.phpunit/phpunit/vendor/autoload.php',
),
),
'2>&1',
Expand Down
7 changes: 5 additions & 2 deletions tests/Model/CodecCursorFunctionalTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,12 +55,15 @@ function (...$args) use (&$previousErrorHandler, &$deprecations) {
E_USER_DEPRECATED | E_DEPRECATED,
);

$cursorId = $codecCursor->getId();
$cursorId = $codecCursor->getId(true);
} finally {
restore_error_handler();
}

self::assertInstanceOf(CursorId::class, $cursorId);
self::logicalOr(
self::isInstanceOf(Int64::class),
self::isInstanceOf(CursorId::class),
)->matches($cursorId);

// Expect 2 deprecations: 1 from CodecCursor, one from Cursor
self::assertCount(2, $deprecations);
Expand Down
6 changes: 3 additions & 3 deletions tests/Operation/WatchFunctionalTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -720,7 +720,7 @@ public function testInitialCursorIsNotClosed(): void
* reports the cursor as alive. While the cursor ID is accessed through
* ChangeStream, we'll need to use reflection to access the internal
* Cursor and call isDead(). */
$this->assertNotEquals('0', (string) $changeStream->getCursorId());
$this->assertNotEquals('0', (string) $changeStream->getCursorId(true));

$rc = new ReflectionClass(ChangeStream::class);
$rp = $rc->getProperty('iterator');
Expand Down Expand Up @@ -1370,11 +1370,11 @@ public function testOriginalReadPreferenceIsPreservedOnResume(): void
}

$changeStream = $operation->execute($secondary);
$previousCursorId = $changeStream->getCursorId();
$previousCursorId = $changeStream->getCursorId(true);
$this->forceChangeStreamResume();

$changeStream->next();
$this->assertNotSame($previousCursorId, $changeStream->getCursorId());
$this->assertNotSame($previousCursorId, $changeStream->getCursorId(true));

$getCursor = Closure::bind(
fn () => $this->iterator->getInnerIterator(),
Expand Down
15 changes: 7 additions & 8 deletions tests/SpecTests/DocumentsMatchConstraint.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
use SebastianBergmann\Comparator\ComparisonFailure;
use SebastianBergmann\Comparator\Factory;
use stdClass;
use Symfony\Bridge\PhpUnit\ConstraintTrait;

use function array_values;
use function get_debug_type;
Expand All @@ -36,8 +35,6 @@
*/
class DocumentsMatchConstraint extends Constraint
{
use ConstraintTrait;

/**
* TODO: This is not currently used, but was preserved from the design of
* TestCase::assertMatchesDocument(), which would sort keys and then compare
Expand Down Expand Up @@ -65,7 +62,7 @@ public function __construct(array|object $value, private bool $ignoreExtraKeysIn
$this->comparatorFactory = Factory::getInstance();
}

private function doEvaluate($other, $description = '', $returnResult = false)
public function evaluate($other, string $description = '', bool $returnResult = false): ?bool
{
/* TODO: If ignoreExtraKeys and sortKeys are both false, then we may be
* able to skip preparation, convert both documents to extended JSON,
Expand Down Expand Up @@ -100,6 +97,8 @@ private function doEvaluate($other, $description = '', $returnResult = false)
if (! $success) {
$this->fail($other, $description, $this->lastFailure);
}

return null;
}

/** @param string|BSONArray[] $expectedType */
Expand Down Expand Up @@ -198,7 +197,7 @@ private function assertEquals(ArrayObject $expected, ArrayObject $actual, bool $
}
}

private function doAdditionalFailureDescription($other)
protected function additionalFailureDescription($other): string
{
if ($this->lastFailure === null) {
return '';
Expand All @@ -207,12 +206,12 @@ private function doAdditionalFailureDescription($other)
return $this->lastFailure->getMessage();
}

private function doFailureDescription($other)
protected function failureDescription($other): string
{
return 'two BSON objects are equal';
}

private function doMatches($other)
protected function matches($other): bool
{
/* TODO: If ignoreExtraKeys and sortKeys are both false, then we may be
* able to skip preparation, convert both documents to extended JSON,
Expand All @@ -232,7 +231,7 @@ private function doMatches($other)
return true;
}

private function doToString()
public function toString(): string
{
return 'matches ' . $this->exporter()->export($this->value);
}
Expand Down
7 changes: 2 additions & 5 deletions tests/UnifiedSpecTests/Constraint/IsBsonType.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
use PHPUnit\Framework\Constraint\Constraint;
use PHPUnit\Framework\Constraint\LogicalOr;
use RuntimeException;
use Symfony\Bridge\PhpUnit\ConstraintTrait;

use function array_keys;
use function array_map;
Expand All @@ -40,8 +39,6 @@

final class IsBsonType extends Constraint
{
use ConstraintTrait;

private static array $types = [
'double',
'string',
Expand Down Expand Up @@ -88,7 +85,7 @@ public static function anyOf(string ...$types): Constraint
return LogicalOr::fromConstraints(...array_map(fn ($type) => new self($type), $types));
}

private function doMatches($other): bool
protected function matches($other): bool
{
return match ($this->type) {
'double' => is_float($other),
Expand Down Expand Up @@ -118,7 +115,7 @@ private function doMatches($other): bool
};
}

private function doToString(): string
public function toString(): string
{
return sprintf('is of BSON type "%s"', $this->type);
}
Expand Down
19 changes: 7 additions & 12 deletions tests/UnifiedSpecTests/Constraint/Matches.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
use RuntimeException;
use SebastianBergmann\Comparator\ComparisonFailure;
use SebastianBergmann\Comparator\Factory;
use Symfony\Bridge\PhpUnit\ConstraintTrait;

use function array_keys;
use function count;
Expand Down Expand Up @@ -49,8 +48,6 @@
*/
class Matches extends Constraint
{
use ConstraintTrait;

private mixed $value;

private bool $allowExtraRootKeys;
Expand All @@ -69,7 +66,7 @@ public function __construct($value, private ?EntityMap $entityMap = null, $allow
$this->comparatorFactory = Factory::getInstance();
}

private function doEvaluate($other, $description = '', $returnResult = false)
public function evaluate($other, $description = '', $returnResult = false): ?bool
{
$other = self::prepare($other);
$success = false;
Expand Down Expand Up @@ -104,6 +101,8 @@ private function doEvaluate($other, $description = '', $returnResult = false)
if (! $success) {
$this->fail($other, $description, $this->lastFailure);
}

return null;
}

private function assertEquals($expected, $actual, string $keyPath): void
Expand Down Expand Up @@ -321,8 +320,7 @@ private function assertMatchesOperator(BSONDocument $operator, $actual, string $
throw new LogicException('unsupported operator: ' . $name);
}

/** @see ConstraintTrait */
private function doAdditionalFailureDescription($other)
protected function additionalFailureDescription($other): string
{
if ($this->lastFailure === null) {
return '';
Expand All @@ -331,14 +329,12 @@ private function doAdditionalFailureDescription($other)
return $this->lastFailure->getMessage();
}

/** @see ConstraintTrait */
private function doFailureDescription($other)
protected function failureDescription($other): string
{
return 'expected value matches actual value';
}

/** @see ConstraintTrait */
private function doMatches($other)
protected function matches($other): bool
{
$other = self::prepare($other);

Expand All @@ -351,8 +347,7 @@ private function doMatches($other)
return true;
}

/** @see ConstraintTrait */
private function doToString()
public function toString(): string
{
return 'matches ' . $this->exporter()->export($this->value);
}
Expand Down
Loading