Skip to content

[PhpUnitBridge] deprecate the testLegacy test name prefix #21140

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
merged 1 commit into from
Jan 6, 2017

Conversation

xabbuh
Copy link
Member

@xabbuh xabbuh commented Jan 2, 2017

Q A
Branch? master
Bug fix? no
New feature? no
BC breaks? no
Deprecations? yes
Tests pass? yes
Fixed tickets #18755
License MIT
Doc PR

@@ -197,6 +197,11 @@ public function endTest(\PHPUnit_Framework_Test $test, $time)
DnsMock::withMockedHosts(array());
}
}

if ($test instanceof \PHPUnit_Framework_TestCase && 0 === strpos($test->getName(), 'testLegacy') && empty($test->getTestResultObject()->warningCount())) {
Copy link
Member

Choose a reason for hiding this comment

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

when the annotation is in place, we should not trigger the warning. What about the other cases?
From DeprecationErrorHandler:

                } elseif (0 === strpos($method, 'testLegacy')
                    || 0 === strpos($method, 'provideLegacy')
                    || 0 === strpos($method, 'getLegacy')
                    || strpos($class, '\Legacy')

Copy link
Member Author

Choose a reason for hiding this comment

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

Adding the warning based on class/method names does work. I am looking into how to do that (if possible) based on the data transformer.

@xabbuh
Copy link
Member Author

xabbuh commented Jan 2, 2017

Status: Needs work

@nicolas-grekas nicolas-grekas added this to the 3.x milestone Jan 3, 2017
@@ -170,6 +172,13 @@ public function startTest(\PHPUnit_Framework_Test $test)
}
}

public function addWarning(\PHPUnit_Framework_Test $test, \PHPUnit_Framework_Warning $e, $time)
{
if ($test instanceof \PHPUnit_Framework_TestCase) {
Copy link
Contributor

Choose a reason for hiding this comment

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

why do we need this check here, we already typehint the parameter

Copy link
Member Author

Choose a reason for hiding this comment

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

The type hint is for \PHPUnit_Framework_Test, but not \PHPUnit_Framework_TestCase.

Copy link
Contributor

Choose a reason for hiding this comment

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

damn, you are right 👍

@xabbuh
Copy link
Member Author

xabbuh commented Jan 3, 2017

The provideLegacy and getLegacy prefixes are not used to make the test belong to the legacy group, but can be used if your data provider triggers deprecations itself. This is something that needs to be fixed in the documentation (see symfony/symfony-docs#7312 for the bug report). Thus, this PR is finished and ready to be reviewed.

Status: Needs review

@xabbuh
Copy link
Member Author

xabbuh commented Jan 3, 2017

After talking to @nicolas-grekas the warnings will now only be triggered if the @group annotation was not used. So you can get rid of the warnings simply by adding the group without the need to rename your test methods.

@xabbuh xabbuh force-pushed the issue-18755 branch 2 times, most recently from 693cf86 to 2448fbc Compare January 3, 2017 19:09
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.

👍 with minor comments

if (in_array('time-sensitive', $groups, true)) {
ClockMock::withClockMock(false);
}
if (in_array('dns-sensitive', $groups, true)) {
DnsMock::withMockedHosts(array());
}
}

if ($test instanceof \PHPUnit_Framework_TestCase && 0 === strpos($test->getName(), 'testLegacy') && !isset($this->testsWithWarnings[$test->getName()]) && !in_array('legacy', $groups, true)) {
$test->getTestResultObject()->addWarning($test, new \PHPUnit_Framework_Warning('Using the testLegacy prefix to mark tests as legacy is deprecated since version 3.3 and will be removed in 4.0. Use the "@group legacy" notation instead to add the test to the legacy group.'), $time);
Copy link
Member

Choose a reason for hiding this comment

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

quotes around "testLegacy"

Copy link
Member Author

Choose a reason for hiding this comment

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

quotes added in both places

}

if ($test instanceof \PHPUnit_Framework_TestCase && strpos($className, '\Legacy') && !isset($this->testsWithWarnings[$test->getName()]) && !in_array('legacy', $classGroups, true)) {
$test->getTestResultObject()->addWarning($test, new \PHPUnit_Framework_Warning('Using the Legacy prefix to mark all tests of a class as legacy is deprecated since version 3.3 and will be removed in 4.0. Use the "@group legacy" notation instead to add the test to the legacy group.'), $time);
Copy link
Member

Choose a reason for hiding this comment

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

quotes around "Legacy"

@nicolas-grekas
Copy link
Member

Thank you @xabbuh.

@nicolas-grekas nicolas-grekas merged commit 21b72dd into symfony:master Jan 6, 2017
nicolas-grekas added a commit that referenced this pull request Jan 6, 2017
…fix (xabbuh)

This PR was merged into the 3.3-dev branch.

Discussion
----------

[PhpUnitBridge] deprecate the testLegacy test name prefix

| Q             | A
| ------------- | ---
| Branch?       | master
| Bug fix?      | no
| New feature?  | no
| BC breaks?    | no
| Deprecations? | yes
| Tests pass?   | yes
| Fixed tickets | #18755
| License       | MIT
| Doc PR        |

Commits
-------

21b72dd deprecate the Legacy/testLegacy test name prefix
@xabbuh xabbuh deleted the issue-18755 branch January 6, 2017 11:34
@nicolas-grekas nicolas-grekas modified the milestones: 3.x, 3.3 Mar 24, 2017
javiereguiluz added a commit to symfony/symfony-docs that referenced this pull request Apr 24, 2017
…, javiereguiluz)

This PR was merged into the master branch.

Discussion
----------

Do not document deprecated legacy test mechanisms

see symfony/symfony#21140

Commits
-------

c2c680a Fixed a minor typo
6f546aa do not document deprecated legacy test mechanisms
@fabpot fabpot mentioned this pull request May 1, 2017
xabbuh added a commit to xabbuh/symfony that referenced this pull request May 21, 2017
fabpot added a commit that referenced this pull request May 21, 2017
This PR was merged into the 3.3 branch.

Discussion
----------

[PhpUnitBridge] add changelog entries for #21140

| Q             | A
| ------------- | ---
| Branch?       | 3.3
| Bug fix?      | no
| New feature?  | no
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets | #21140
| License       | MIT
| Doc PR        |

Commits
-------

c83c5bc [PhpUnitBridge] add changelog entries for #21140
nicolas-grekas added a commit that referenced this pull request May 22, 2017
* 3.3:
  [Serializer] Remove a useless legacy annotation
  Fixed extra semi-colon
  fix docblock position
  [DependencyInjection] remove unused variable
  [PhpUnitBridge] add changelog entries for #21140
  [DI] Remove dead service_container checks
nicolas-grekas added a commit that referenced this pull request May 22, 2017
* 3.4:
  [Serializer] Remove a useless legacy annotation
  Fixed extra semi-colon
  fix docblock position
  [DependencyInjection] remove unused variable
  [PhpUnitBridge] add changelog entries for #21140
  [DI] Remove dead service_container checks
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