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
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,13 @@

namespace Symfony\Bundle\FrameworkBundle\Tests\DependencyInjection\Compiler;

use PHPUnit\Framework\TestCase;
use Symfony\Bundle\FrameworkBundle\DependencyInjection\Compiler\DataCollectorTranslatorPass;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Reference;
use Symfony\Component\Translation\TranslatorInterface;

class DataCollectorTranslatorPassTest extends \PHPUnit_Framework_TestCase
class DataCollectorTranslatorPassTest extends TestCase
{
private $container;
private $dataCollectorTranslatorPass;
Expand Down
2 changes: 2 additions & 0 deletions src/Symfony/Component/DomCrawler/Tests/CrawlerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -886,6 +886,8 @@ public function testChildren()
$crawler = new Crawler('<p></p>');
$crawler->filter('p')->children();
$this->assertTrue(true, '->children() does not trigger a notice if the node has no children');
} catch (\PHPUnit\Framework\Error\Notice $e) {
$this->fail('->children() does not trigger a notice if the node has no children');
} catch (\PHPUnit_Framework_Error_Notice $e) {
$this->fail('->children() does not trigger a notice if the node has no children');
}
Expand Down
4 changes: 4 additions & 0 deletions src/Symfony/Component/Finder/Tests/FinderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -689,6 +689,10 @@ public function testAccessDeniedException()
$this->fail(sprintf("Expected exception:\n%s\nGot:\n%s\nWith comparison failure:\n%s", $expectedExceptionClass, 'PHPUnit_Framework_ExpectationFailedException', $e->getComparisonFailure()->getExpectedAsString()));
}

if ($e instanceof \PHPUnit\Framework\ExpectationFailedException) {
$this->fail(sprintf("Expected exception:\n%s\nGot:\n%s\nWith comparison failure:\n%s", $expectedExceptionClass, '\PHPUnit\Framework\ExpectationFailedException', $e->getComparisonFailure()->getExpectedAsString()));
}

$this->assertInstanceOf($expectedExceptionClass, $e);
}
}
Expand Down
6 changes: 5 additions & 1 deletion src/Symfony/Component/Form/Test/DeprecationErrorHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -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)

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).

}

public static function handleBC($errorNumber, $message, $file, $line, $context)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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')) {
\PHPUnit\Util\XML::loadfile($filePath, false, false, true);
} else {
\PHPUnit_Util_XML::loadfile($filePath, false, false, true);
}
}

public function provideTranslationFiles()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,8 @@ public function testHandleRestoresThePreviousRequestOnException($type)
try {
$kernel->handle($request, $type);
$this->fail('->handle() suppresses the controller exception');
} catch (\PHPUnit\Framework\Exception $e) {
throw $e;
} catch (\PHPUnit_Framework_Exception $e) {
throw $e;
} catch (\Exception $e) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -306,10 +306,15 @@ public function formatTypeDoubleWithCurrencyStyleProvider()

/**
* @dataProvider formatTypeCurrencyProvider
* @expectedException \PHPUnit_Framework_Error_Warning
*/
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

} else {
$this->setExpectedException('\PHPUnit\Framework\Error\Warning');
}

$formatter->format($value, NumberFormatter::TYPE_CURRENCY);
}

Expand Down Expand Up @@ -641,11 +646,13 @@ public function parseProvider()
);
}

/**
* @expectedException \PHPUnit_Framework_Error_Warning
*/
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?

} else {
$this->setExpectedException('\PHPUnit\Framework\Error\Warning');
}
$formatter = $this->getNumberFormatter('en', NumberFormatter::DECIMAL);
$formatter->parse('1', NumberFormatter::TYPE_DEFAULT);
}
Expand Down Expand Up @@ -782,11 +789,13 @@ public function parseTypeDoubleProvider()
);
}

/**
* @expectedException \PHPUnit_Framework_Error_Warning
*/
public function testParseTypeCurrency()
{
if (class_exists('\PHPUnit_Framework_Error_Warning')) {
$this->setExpectedException('\PHPUnit_Framework_Error_Warning');
} else {
$this->setExpectedException('\PHPUnit\Framework\Error\Warning');
}
$formatter = $this->getNumberFormatter('en', NumberFormatter::DECIMAL);
$formatter->parse('1', NumberFormatter::TYPE_CURRENCY);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public static function setUpBeforeClass()
try {
random_bytes(1);
} catch (\Exception $e) {
throw new \PHPUnit_Framework_SkippedTestError($e->getMessage());
self::markTestSkipped($e->getMessage());
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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')) {
\PHPUnit\Util\XML::loadfile($filePath, false, false, true);
} else {
\PHPUnit_Util_XML::loadfile($filePath, false, false, true);
}
}

public function provideTranslationFiles()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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')) {
\PHPUnit\Util\XML::loadfile($filePath, false, false, true);
} else {
\PHPUnit_Util_XML::loadfile($filePath, false, false, true);
}
}

public function provideTranslationFiles()
Expand Down
0