-
Notifications
You must be signed in to change notification settings - Fork 821
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
[WIP] API Upgrade SapphireTest to work with phpunit 9 #10028
[WIP] API Upgrade SapphireTest to work with phpunit 9 #10028
Conversation
32377d9
to
bcb2104
Compare
eb91ac6
to
5d0e761
Compare
69b824e
to
e53c6de
Compare
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.
We'll need to validate how our API doc process the dual classes.
We probably need to have some migration guide somewhere. But that can probably be another task.
de7a2b2
to
b7f71b3
Compare
src/Dev/SapphireTest.php
Outdated
} | ||
|
||
public static function assertNotContains( | ||
public static function assertNotStringContainsString( |
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.
Why change signatures of legacy methods?
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.
You should not be changing the legacy class
src/Dev/SapphireTest.php
Outdated
@@ -639,7 +1963,7 @@ public static function assertNotContains( | |||
if ($haystack instanceof DBField) { | |||
$haystack = (string)$haystack; | |||
} | |||
parent::assertNotContains($needle, $haystack, $message, $ignoreCase, $checkForObjectIdentity, $checkForNonObjectIdentity); | |||
parent::assertNotStringContainsString($needle, $haystack, $message, $ignoreCase, $checkForObjectIdentity, $checkForNonObjectIdentity); |
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.
Why change signatures of legacy methods?
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.
You should not be changing the legacy class
src/Dev/SapphireTest.php
Outdated
@@ -993,7 +2317,7 @@ public static function assertSQLNotContains( | |||
$needleSQL = static::normaliseSQL($needleSQL); | |||
$haystackSQL = static::normaliseSQL($haystackSQL); | |||
|
|||
static::assertNotContains($needleSQL, $haystackSQL, $message, $ignoreCase, $checkForObjectIdentity); | |||
static::assertNotStringContainsString($needleSQL, $haystackSQL, $message, $ignoreCase, $checkForObjectIdentity); |
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.
Why change signatures of legacy methods?
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.
You should not be changing the legacy class
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.
There's still some legacy classes that are seeing needless signature changes.
The current set up will allow you to install any version of PHPUnit. Still think need to address that in some way.
There's also a few comments that got miss. But nothing major.
af3c355
to
bd3d6a8
Compare
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.
Some of the legacy class implementation still differ from the original ... that's the only thing I want fix before we merge this.
We should have a follow up task to:
- Disallow PHPUnit 6, 7 and 8
- Add some sort of CI to make sure everything still works with when you run test with Sam's PHPUnit 5.7 fork.
src/Dev/SapphireTest.php
Outdated
@@ -614,7 +1938,7 @@ protected function tearDown() | |||
static::$state->tearDown($this); | |||
} | |||
|
|||
public static function assertContains( | |||
public static function assertStringContainsString( |
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.
You should not be changing the legacy class
src/Dev/SapphireTest.php
Outdated
@@ -625,10 +1949,10 @@ public static function assertContains( | |||
if ($haystack instanceof DBField) { | |||
$haystack = (string)$haystack; | |||
} | |||
parent::assertContains($needle, $haystack, $message, $ignoreCase, $checkForObjectIdentity, $checkForNonObjectIdentity); | |||
parent::assertStringContainsString($needle, $haystack, $message, $ignoreCase, $checkForObjectIdentity, $checkForNonObjectIdentity); |
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.
You should not be changing the legacy class
src/Dev/SapphireTest.php
Outdated
} | ||
|
||
public static function assertNotContains( | ||
public static function assertNotStringContainsString( |
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.
You should not be changing the legacy class
src/Dev/SapphireTest.php
Outdated
@@ -639,7 +1963,7 @@ public static function assertNotContains( | |||
if ($haystack instanceof DBField) { | |||
$haystack = (string)$haystack; | |||
} | |||
parent::assertNotContains($needle, $haystack, $message, $ignoreCase, $checkForObjectIdentity, $checkForNonObjectIdentity); | |||
parent::assertNotStringContainsString($needle, $haystack, $message, $ignoreCase, $checkForObjectIdentity, $checkForNonObjectIdentity); |
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.
You should not be changing the legacy class
src/Dev/SapphireTest.php
Outdated
@@ -971,7 +2295,7 @@ public static function assertSQLContains( | |||
$needleSQL = static::normaliseSQL($needleSQL); | |||
$haystackSQL = static::normaliseSQL($haystackSQL); | |||
|
|||
static::assertContains($needleSQL, $haystackSQL, $message, $ignoreCase, $checkForObjectIdentity); | |||
static::assertStringContainsString($needleSQL, $haystackSQL, $message, $ignoreCase, $checkForObjectIdentity); |
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.
You should not be changing the legacy class
src/Dev/SapphireTest.php
Outdated
@@ -993,7 +2317,7 @@ public static function assertSQLNotContains( | |||
$needleSQL = static::normaliseSQL($needleSQL); | |||
$haystackSQL = static::normaliseSQL($haystackSQL); | |||
|
|||
static::assertNotContains($needleSQL, $haystackSQL, $message, $ignoreCase, $checkForObjectIdentity); | |||
static::assertNotStringContainsString($needleSQL, $haystackSQL, $message, $ignoreCase, $checkForObjectIdentity); |
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.
You should not be changing the legacy class
tests/php/ORM/ArrayListTest.php
Outdated
public function testZeroLimit() | ||
{ | ||
$this->markTestIncomplete(); |
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.
I would rather merge the test broken or remove the test altogether.
Leaving a comment like that is just a way of saying we will never fix the issue.
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.
Removed
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.
Removed
@maxime-rainville I've added a composer conflict for phpunit 6 7 and 8 Have implemented all other peer review feedback |
bd3d6a8
to
fa5f7cc
Compare
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.
Good enough ... let's merge it and see what breaks!
Issue #10019
Just a POC at this point
Notes:
: void
return typeif (!class_exists(PHPUnit_Framework_TestCase::class)) {
on_legacy/SapphireTest
andif (class_exists(TestCase::class)) {
so that_legacy/SapphireTest
is what's used for function signature validation by IDE's and also php itself. This is because return types support covariance (become more specific) but not contravariance (become more abstract). Amissing
return type (_legacy style) can be made more specific with:void
, but not vice versa.This is handy to get composer to install
Migration notes:
Running the following regex find and replaces
Require the most work, as non-iterable haystacks (strings) now need to be called with assertStringContainsString/assertNotStringContainsString. Iterable haystacks (arrays, etc) stay as are. You'll need to find all instance and manually assess whether they should be changed or not.
Since there's probably going to be way more string haystacks than iterable haystacks, do the string replace then search for the replacement and revert the ones with an iterable haystack
Any
<testsuite>
in a phpunit.xml.dist file now needs to wrapped in<testsuites>
@expectedException
docblock annotation no longer work. They need to be replaced with the following:PHPUnit exceptions - forwards compatible version has been added to _legacy/SapphireTest.php if still using phpunit5
PHPUnit_Framework_Error
=>$this->expectError()
PHPUnit_Framework_Error_Warning
=>$this->expectWarning()
PHPUnit_Framework_Error_Notice
=>$this->expectNotice()
PHPUnit_Framework_Error_Deprecated
=>$this->expectDeprecated()
Asserting warnings for phpunit exceptions are handled with
$this->expectWarningMessage()
and$this->expectWarningMessageMatches()
All other exceptions are handled with
$this->expectException(LogicException::class);
@expectedExceptionMessage
=>$this->expectExceptionMessage($message)
@expectedExceptionMessageRegExp
=>$this->expectExceptionMessageMatches($regex)
@expectedExceptionCode
=>$this->expectExceptionCode($code)
The following searches will find the things
@expectedException PHPUnit_Framework_
Followed by
@expectedException
assertArraySubset()
has been removed. It can be polyfiled for backwards compatibility on individual SapphireTest classes with a trait in a module:$this->assertArraySubset
composer require --dev dms/phpunit-arraysubset-asserts
"dms/phpunit-arraysubset-asserts": "^0.3.0",
Have added as a dev dependency to framework
Decided not to put this trait on SapphireTest for Semver. This way gives us the ability to later migrate off using this function and remove the requirement. In patch notes we could just say re-require it on your project if needed.
MessageRegExp(
=>MessageMatches(
assertRegExp(
=>assertMatchesRegularExpression(
assertNotRegExp(
=>assertDoesNotMatchRegularExpression(
Update composer
Still need to update
docs/en/02_Developer_Guides/06_Testing/00_Unit_Testing.md