-
Notifications
You must be signed in to change notification settings - Fork 266
PHPLIB-462: ensure compatibility with PHP 7.4 #665
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
Changes from all commits
1c74f44
d7aed71
4fed85f
8241809
4f7986a
e0c6531
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,3 +6,4 @@ vendor/ | |
# PHPUnit | ||
phpunit.phar | ||
phpunit.xml | ||
.phpunit.result.cache |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -21,9 +21,6 @@ env: | |
- COMPOSER_OPTIONS= | ||
|
||
jobs: | ||
allow_failures: | ||
- php: "7.4snapshot" | ||
|
||
include: | ||
|
||
- stage: Smoke Testing | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,6 +11,7 @@ | |
use IteratorIterator; | ||
use LogicException; | ||
use MultipleIterator; | ||
use Symfony\Bridge\PhpUnit\SetUpTearDownTrait; | ||
|
||
/** | ||
* CRUD spec functional tests. | ||
|
@@ -19,9 +20,11 @@ | |
*/ | ||
class CrudSpecFunctionalTest extends FunctionalTestCase | ||
{ | ||
use SetUpTearDownTrait; | ||
|
||
private $expectedCollection; | ||
|
||
public function setUp() | ||
private function doSetUp() | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Just to confirm, can we still chain to There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, that is still possible. The There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I confirm: the trait has been designed so that only the signature of the method is changed, and not its body. |
||
{ | ||
parent::setUp(); | ||
|
||
|
@@ -297,7 +300,7 @@ private function executeAssertResult(array $operation, $expectedResult, $actualR | |
break; | ||
|
||
case 'bulkWrite': | ||
$this->assertInternalType('array', $expectedResult); | ||
$this->assertIsArray($expectedResult); | ||
$this->assertInstanceOf(\MongoDB\BulkWriteResult::class, $actualResult); | ||
|
||
if (isset($expectedResult['deletedCount'])) { | ||
|
@@ -354,7 +357,7 @@ private function executeAssertResult(array $operation, $expectedResult, $actualR | |
|
||
case 'deleteMany': | ||
case 'deleteOne': | ||
$this->assertInternalType('array', $expectedResult); | ||
$this->assertIsArray($expectedResult); | ||
$this->assertInstanceOf(\MongoDB\DeleteResult::class, $actualResult); | ||
|
||
if (isset($expectedResult['deletedCount'])) { | ||
|
@@ -372,7 +375,7 @@ private function executeAssertResult(array $operation, $expectedResult, $actualR | |
break; | ||
|
||
case 'insertMany': | ||
$this->assertInternalType('array', $expectedResult); | ||
$this->assertIsArray($expectedResult); | ||
$this->assertInstanceOf(\MongoDB\InsertManyResult::class, $actualResult); | ||
|
||
if (isset($expectedResult['insertedCount'])) { | ||
|
@@ -388,7 +391,7 @@ private function executeAssertResult(array $operation, $expectedResult, $actualR | |
break; | ||
|
||
case 'insertOne': | ||
$this->assertInternalType('array', $expectedResult); | ||
$this->assertIsArray($expectedResult); | ||
$this->assertInstanceOf(\MongoDB\InsertOneResult::class, $actualResult); | ||
|
||
if (isset($expectedResult['insertedCount'])) { | ||
|
@@ -406,7 +409,7 @@ private function executeAssertResult(array $operation, $expectedResult, $actualR | |
case 'replaceOne': | ||
case 'updateMany': | ||
case 'updateOne': | ||
$this->assertInternalType('array', $expectedResult); | ||
$this->assertIsArray($expectedResult); | ||
$this->assertInstanceOf(\MongoDB\UpdateResult::class, $actualResult); | ||
|
||
if (isset($expectedResult['matchedCount'])) { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
<?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; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is there a particular reason that Is that because it really is only relevant to older PHPUnit versions, so Symfony is careful not to use it in newer branches? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I talked to @nicolas-grekas about this. The assertion polypill is marked as In our case, I didn't want to patch PHPUnit code and with the PHPUnit versions we currently support, the single trait is good enough for us as all new assertion methods were added in or after PHPUnit 7. That's why we declare our own trait, which is empty if the PHPUnit version is new enough, as it allows us to always include our polyfill trait in the test classes. There is still a certain risk using internal code from Symfony, but given that they need to keep the trait around as long as they support PHPUnit < 7 I feel rather confident there: dropping older PHPUnit versions for them won't be possible until Symfony 4.4 is EOL, which will be in November 2023. I hope we'll be able to get rid of support for PHP 5 before then. However, if you'd rather not use an internal class we can always duplicate the polyfill to our library, of course keeping the original copyright intact. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Or you could use simple-phpunit :) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thanks for the deep explanation! I'm content with this. @nicolas-grekas: Thanks for chiming in. |
||
} | ||
} else { | ||
/** | ||
* @internal | ||
*/ | ||
trait PolyfillAssertTrait | ||
{ | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Am I correct that this option was introduced in 4.6 (see: blog post), even though it was never documented? I'm not sure about
beStrictAboutOutputDuringTests
, but there are some online references to that dating back to 2015 so I assume that's fine.Just wanted to confirm that these will apply to all PHPUnit versions we use for testing.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The XSD option was added in sebastianbergmann/phpunit@9101f51#diff-365e6053dce410a51198fc699549f0ae, which was first included in 4.0.0. The comments in the code indicate that the functionality itself was added in 3.8.0, so we should be safe here.
The reason this was added is that I regenerated a new configuration file using
phpunit --generate-configuration
to account for changes in the default configuration.