8000 Further refactorings to PHPUnit namespaces by peterrehm · Pull Request #21688 · symfony/symfony · GitHub
[go: up one dir, main page]

Skip to content

Further refactorings to PHPUnit namespaces #21688

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

Closed
wants to merge 6 commits into from
Closed

Further refactorings to PHPUnit namespaces #21688

wants to merge 6 commits into from

Conversation

peterrehm
Copy link
Contributor
Q A
Branch? 2.7
Bug fix? no
New feature? no
BC breaks? no
Deprecations? no
Tests pass? no
Fixed tickets -
License MIT
Doc PR -

Continued work to make Symfony PHPUnit 6 compatible

@peterrehm peterrehm changed the title Phpunit 2.7 Further refactorings to PHPUnit namespaces Feb 20, 2017
return \PHPUnit_Util_ErrorHandler::handleError($errorNumber, $message, $file, $line);
}

return \PHPUnit\Util\ErrorHandler::handleError($errorNumber, $message, $file, $line);
Copy link
Contributor

Choose a reason for hiding this comment

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

Should probably be using a use statement (same goes for the rest)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

You mean just for the namespaced versions? I was unsure about it and therefore kept it as is. I can easily update that if wanted.

Copy link
Member
@nicolas-grekas nicolas-grekas Feb 20, 2017

Choose a reason for hiding this comment

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

I personal have a preference to keep the FQCN inline with no use - makes things more readable (especially true on the other cases below).

@@ -24,7 +24,11 @@ public static function handle($errorNumber, $message, $file, $line, $context)
return true;
}

return \PHPUnit_Util_ErrorHandler::handleError($errorNumber, $message, $file, $line);
if (class_exists('\PHPUnit_Util_ErrorHandler')) {
Copy link
Member
@nicolas-grekas nicolas-grekas Feb 20, 2017

Choose a reason for hiding this comment

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

the leading backslash should be removed in all strings (this one and below)

@peterrehm
Copy link
Contributor Author

@nicolas-grekas Updated. One concern is left as setExpectedException is deprecated. I could also check if a class not in the FC layer exists and therefore conditionally use setException or expectException?

@peterrehm
Copy link
Contributor Author

If needed I think I would use PHPUnit\Framework\Exception.

@@ -20,7 +20,11 @@ class TranslationFilesTest extends TestCase
*/
public function testTranslationFileIsValid($filePath)
{
\PHPUnit_Util_XML::loadfile($filePath, false, false, true);
if (class_exists('PHPUnit\Util\XML')) {
Copy link
Member

Choose a reason for hiding this comment

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

to prevent any issue with the BC layer, we should check for the underscore version here

*/
public function testFormatTypeCurrency($formatter, $value)
{
if (class_exists('PHPUnit_Framework_Error_Warning')) {
$this->setExpectedException('\PHPUnit_Framework_Error_Warning');
Copy link
Member

Choose a reason for hiding this comment

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

leading backslash

@@ -20,7 +20,11 @@ class TranslationFilesTest extends TestCase
*/
public function testTranslationFileIsValid($filePath)
{
\PHPUnit_Util_XML::loadfile($filePath, false, false, true);
if (class_exists('PHPUnit\Util\XML')) {
Copy link
Member

Choose a reason for hiding this comment

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

check underscore version

@@ -20,7 +20,11 @@ class TranslationFilesTest extends TestCase
*/
public function testTranslationFileIsValid($filePath)
{
\PHPUnit_Util_XML::loadfile($filePath, false, false, true);
if (class_exists('PHPUnit\Util\XML')) {
Copy link
Member

Choose a reason for hiding this comment

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

underscore version

public function testParseTypeDefault()
{
if (class_exists('PHPUnit_Framework_Error_Warning')) {
$this->setExpectedException('\PHPUnit_Framework_Error_Warning');
Copy link
Member

Choose a reason for hiding this comment

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

you said this method is deprecated? should be do a method_exists check and use the new way when possible?

@peterrehm
Copy link
Contributor Author

Updated.

@@ -789,13 +780,24 @@ public function parseTypeDoubleProvider()
);
}

public function testParseTypeCurrency()
private function handleExpectedWarningException()
Copy link
Member

Choose a reason for hiding this comment

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

because the test suite is full of "setExpectedException", I think we should remove this method and do the check inline instead (unfortunately...).

the most concise way I can think of is:
$this->{method_exists($this, $_ = 'expectException') ? $_ : 'setExpectedException'}(...)

can you update the test suite in the same PR also please?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That was quit some work... 😄 Now it should be okay. On to the next one I would say...

@@ -46,7 +46,13 @@ public function testUnknownFragmentRenderer()
;
$renderer = new FragmentHandler(array(), false, $context);

$this->setExpectedException('InvalidArgumentException', 'The "inline" renderer does not exist.');
if (method_exists($this, 'expectException')) {
$this->expectException('InvalidArgumentException');
Copy link
Member

Choose a reason for hiding this comment

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

Possible to use annotation instead here? That's the last thing remaining, thanks for the work.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That could work in the cases where we dont need any parameters but this is then more in line with new PHPUnit prefered way. I would prefer to keep it as this but your call.

Copy link
Member

Choose a reason for hiding this comment

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

For reference: https://thephp.cc/news/2016/02/questioning-phpunit-best-practices
Let's keep it this way then.

@nicolas-grekas
Copy link
Member

Thank you @peterrehm.

nicolas-grekas added a commit that referenced this pull request Feb 21, 2017
This PR was squashed before being merged into the 2.7 branch (closes #21688).

Discussion
----------

Further refactorings to PHPUnit namespaces

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

Continued work to make Symfony PHPUnit 6 compatible

Commits
-------

de8106f Further refactorings to PHPUnit namespaces
@peterrehm peterrehm deleted the phpunit-2.7 branch February 21, 2017 10:10
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
0