BrainMonkey/TestCase: bug fix for test double creation#45
Merged
Conversation
The "on-the-fly" created test doubles would identify as the same class, which could influence whether tests would actually test what they should be testing and could lead to test failures.
In code:
```php
function underTest( $obj ) {
if ($obj instanceof MyClass) {
return true;
}
return false;
}
function testIt() {
$this->makeDoublesForUnavailableClasses( [ 'MyClass', 'NotMyClass' ] );
$this->assertTrue( underTest( new MyClass() ) ); // This passes.
$this->assertFalse( underTest( new NotMyClass() ) ); // This fails as `NotMyClass` was seen as the same class as `MyClass`.
}
```
The implementation details of the "on-the-fly test double creation" feature have now been changed to prevent this situation.
This includes removing the `Yoast\WPTestUtils\BrainMonkey\Doubles\DummyTestDouble` class which was only intended for internal use in the double creation anyway and is now no longer used.
Includes updated documentation.
Includes additional unit tests to safeguard against the bug + verify the new code.
Includes changelog to release version 1.1.1 straight away.
d6278b7 to
d2653c5
Compare
diedexx
approved these changes
Nov 17, 2022
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The "on-the-fly" created test doubles would identify as the same class, which could influence whether tests would actually test what they should be testing and could lead to test failures.
In code:
The implementation details of the "on-the-fly test double creation" feature have now been changed to prevent this situation. This includes removing the
Yoast\WPTestUtils\BrainMonkey\Doubles\DummyTestDoubleclass which was only intended for internal use in the double creation anyway and is now no longer used.Includes updated documentation.
Includes additional unit tests to safeguard against the bug + verify the new code.
Includes changelog to release version 1.1.1 straight away.