Skip to content

BrainMonkey/TestCase: bug fix for test double creation#45

Merged
jrfnl merged 1 commit intodevelopfrom
feature/change-doubling-mechanism
Nov 17, 2022
Merged

BrainMonkey/TestCase: bug fix for test double creation#45
jrfnl merged 1 commit intodevelopfrom
feature/change-doubling-mechanism

Conversation

@jrfnl
Copy link
Copy Markdown
Collaborator

@jrfnl jrfnl commented Nov 17, 2022

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:

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.

@jrfnl jrfnl added bug Something isn't working yoastcs/qa labels Nov 17, 2022
@jrfnl jrfnl added this to the 1.x Next Release milestone Nov 17, 2022
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.
@jrfnl jrfnl force-pushed the feature/change-doubling-mechanism branch from d6278b7 to d2653c5 Compare November 17, 2022 13:40
@jrfnl jrfnl merged commit 64f94c6 into develop Nov 17, 2022
@jrfnl jrfnl deleted the feature/change-doubling-mechanism branch November 17, 2022 14:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working yoastcs/qa

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants