Skip to content

Navigation Menu

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

[PhpUnitBridge] Fix expectDeprecation() in isolation #37515

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

Merged

Conversation

alexpott
Copy link
Contributor

@alexpott alexpott commented Jul 7, 2020

Q A
Branch? 5.1
Bug fix? yes
New feature? no
Deprecations? no
Tickets Fix #...
License MIT
Doc PR symfony/symfony-docs#...

Tests like

    /**
     * Do not remove this test in the next major version.
     *
     * @group legacy
     * @runInSeparateProcess
     */
    public function testOneInIsolation()
    {
        $this->expectDeprecation('foo');
        @trigger_error('foo', E_USER_DEPRECATED);
    }

will fail due to:

Testing Symfony\Bridge\PhpUnit\Tests\ExpectDeprecationTraitTest
R                                                                   1 / 1 (100%)R

Time: 111 ms, Memory: 6.00 MB

There were 2 risky tests:

1) Symfony\Bridge\PhpUnit\Tests\ExpectDeprecationTraitTest::testOneInIsolation
This test did not perform any assertions

/Users/alex/dev/symfony/src/Symfony/Bridge/PhpUnit/Tests/ExpectDeprecationTraitTest.php:38

2) Symfony\Bridge\PhpUnit\Tests\ExpectDeprecationTraitTest::testOneInIsolation
This test did not perform any assertions

OK, but incomplete, skipped, or risky tests!
Tests: 1, Assertions: 0, Risky: 2.

@alexpott alexpott changed the base branch from 5.0 to master July 7, 2020 16:51
@alexpott
Copy link
Contributor Author

alexpott commented Jul 7, 2020

The problem with the fix is that now the assertion count is wrong for tests not run in a separate process.

For example:

./phpunit src/Symfony/Bridge/PhpUnit/Tests/ExpectDeprecationTraitTest.php --filter testOneWithAnnotation                                                                                                             
#!/usr/bin/env php
PHPUnit 8.3.5 by Sebastian Bergmann and contributors.

Testing Symfony\Bridge\PhpUnit\Tests\ExpectDeprecationTraitTest
.                                                                   1 / 1 (100%)

Time: 52 ms, Memory: 6.00 MB

OK (1 test, 3 assertions)

Before this change it was OK (1 test, 2 assertions)

@alexpott alexpott force-pushed the expect-deprecations-in-isolation branch from 0e1e77a to c781eeb Compare July 7, 2020 17:27
@alexpott alexpott changed the base branch from master to 5.1 July 7, 2020 17:28
@alexpott
Copy link
Contributor Author

alexpott commented Jul 7, 2020

Actually this has unearthed a significant but in the symfony expectDeprecation method in isolated tests - if you change the expectation to any value it'll still work because essentially the expectation is ignored.

    /**
     * Do not remove this test in the next major version.
     *
     * @group legacy
     * @runInSeparateProcess
     */
    public function testOneInIsolation()
    {
        $this->expectDeprecation('fdfdef2');
        @trigger_error('foo', E_USER_DEPRECATED);
    }

will happily pass.

@nicolas-grekas nicolas-grekas added this to the 5.1 milestone Jul 8, 2020
Copy link
Member

@nicolas-grekas nicolas-grekas left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks for working on this!

@alexpott alexpott requested review from nicolas-grekas and stof July 9, 2020 07:51
@nicolas-grekas nicolas-grekas changed the title Expect deprecations in isolation [PhpUnitBridge] Expect deprecations in isolation Jul 9, 2020
@nicolas-grekas nicolas-grekas changed the title [PhpUnitBridge] Expect deprecations in isolation [PhpUnitBridge] Fi expectDeprecation() in isolation Jul 9, 2020
@nicolas-grekas nicolas-grekas changed the title [PhpUnitBridge] Fi expectDeprecation() in isolation [PhpUnitBridge] Fix expectDeprecation() in isolation Jul 9, 2020
@nicolas-grekas
Copy link
Member

Thank you @alexpott.

@nicolas-grekas nicolas-grekas force-pushed the expect-deprecations-in-isolation branch from c6a5d7c to e7e2ee7 Compare July 9, 2020 08:07
@nicolas-grekas nicolas-grekas merged commit 5992bf0 into symfony:5.1 Jul 9, 2020
@fabpot fabpot mentioned this pull request Jul 24, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants
Morty Proxy This is a proxified and sanitized view of the page, visit original site.