Skip to content

Commit

Permalink
[tests] Use @requires annotation when possible
Browse files Browse the repository at this point in the history
  • Loading branch information
nicolas-grekas committed Oct 10, 2015
1 parent 5206086 commit 4061d37
Show file tree
Hide file tree
Showing 42 changed files with 145 additions and 258 deletions.
4 changes: 2 additions & 2 deletions src/Symfony/Bridge/Doctrine/Test/DoctrineTestHelper.php
Expand Up @@ -29,8 +29,8 @@ class DoctrineTestHelper
*/
public static function createTestEntityManager()
{
if (!class_exists('PDO') || !in_array('sqlite', \PDO::getAvailableDrivers())) {
\PHPUnit_Framework_TestCase::markTestSkipped('This test requires SQLite support in your environment');
if (!extension_loaded('pdo_sqlite')) {
\PHPUnit_Framework_TestCase::markTestSkipped('Extension pdo_sqlite is required.');
}

$config = new \Doctrine\ORM\Configuration();
Expand Down
7 changes: 3 additions & 4 deletions src/Symfony/Bridge/Doctrine/Tests/Logger/DbalLoggerTest.php
Expand Up @@ -132,12 +132,11 @@ public function testLogLongString()
));
}

/**
* @requires extension mbstring
*/
public function testLogUTF8LongString()
{
if (!function_exists('mb_detect_encoding')) {
$this->markTestSkipped('Testing log shortening of utf8 charsets requires the mb_detect_encoding() function.');
}

$logger = $this->getMock('Symfony\\Component\\HttpKernel\\Log\\LoggerInterface');

$dbalLogger = $this
Expand Down
Expand Up @@ -13,14 +13,13 @@

use Symfony\Component\ClassLoader\ApcUniversalClassLoader;

/**
* @requires extension apc
*/
class ApcUniversalClassLoaderTest extends \PHPUnit_Framework_TestCase
{
protected function setUp()
{
if (!extension_loaded('apc')) {
$this->markTestSkipped('The apc extension is not available.');
}

if (!(ini_get('apc.enabled') && ini_get('apc.enable_cli'))) {
$this->markTestSkipped('The apc extension is available, but not enabled.');
} else {
Expand Down
Expand Up @@ -20,14 +20,11 @@

class ClassCollectionLoaderTest extends \PHPUnit_Framework_TestCase
{
/**
* @requires PHP 5.4
*/
public function testTraitDependencies()
{
if (PHP_VERSION_ID < 50400) {
$this->markTestSkipped('Requires PHP > 5.4');

return;
}

require_once __DIR__.'/Fixtures/deps/traits.php';

$r = new \ReflectionClass('Symfony\Component\ClassLoader\ClassCollectionLoader');
Expand Down Expand Up @@ -97,15 +94,10 @@ public function getDifferentOrders()

/**
* @dataProvider getDifferentOrdersForTraits
* @requires PHP 5.4
*/
public function testClassWithTraitsReordering(array $classes)
{
if (PHP_VERSION_ID < 50400) {
$this->markTestSkipped('Requires PHP > 5.4');

return;
}

require_once __DIR__.'/Fixtures/ClassesWithParents/ATrait.php';
require_once __DIR__.'/Fixtures/ClassesWithParents/BTrait.php';
require_once __DIR__.'/Fixtures/ClassesWithParents/CTrait.php';
Expand Down Expand Up @@ -146,14 +138,11 @@ public function getDifferentOrdersForTraits()
);
}

/**
* @requires PHP 5.4
*/
public function testFixClassWithTraitsOrdering()
{
if (PHP_VERSION_ID < 50400) {
$this->markTestSkipped('Requires PHP > 5.4');

return;
}

require_once __DIR__.'/Fixtures/ClassesWithParents/CTrait.php';
require_once __DIR__.'/Fixtures/ClassesWithParents/F.php';
require_once __DIR__.'/Fixtures/ClassesWithParents/G.php';
Expand Down
7 changes: 3 additions & 4 deletions src/Symfony/Component/Console/Tests/ApplicationTest.php
Expand Up @@ -489,12 +489,11 @@ public function testRenderException()
$this->assertStringEqualsFile(self::$fixturesPath.'/application_renderexception4.txt', $tester->getDisplay(true), '->renderException() wraps messages when they are bigger than the terminal');
}

/**
* @requires extension mbstring
*/
public function testRenderExceptionWithDoubleWidthCharacters()
{
if (!function_exists('mb_strwidth')) {
$this->markTestSkipped('The "mb_strwidth" function is not available');
}

$application = $this->getMock('Symfony\Component\Console\Application', array('getTerminalWidth'));
$application->setAutoExit(false);
$application->expects($this->any())
Expand Down
Expand Up @@ -52,12 +52,11 @@ public function testFormatBlock()
);
}

/**
* @requires extension mbstring
*/
public function testFormatBlockWithDiacriticLetters()
{
if (!function_exists('mb_detect_encoding')) {
$this->markTestSkipped('This test requires mbstring to work.');
}

$formatter = new FormatterHelper();

$this->assertEquals(
Expand All @@ -69,11 +68,11 @@ public function testFormatBlockWithDiacriticLetters()
);
}

/**
* @requires extension mbstring
*/
public function testFormatBlockWithDoubleWidthDiacriticLetters()
{
if (!extension_loaded('mbstring')) {
$this->markTestSkipped('This test requires mbstring to work.');
}
$formatter = new FormatterHelper();
$this->assertEquals(
'<error> </error>'."\n".
Expand Down
Expand Up @@ -164,12 +164,11 @@ public function testRedrawFrequency()
$progress->advance(1);
}

/**
* @requires extension mbstring
*/
public function testMultiByteSupport()
{
if (!function_exists('mb_strlen') || (false === $encoding = mb_detect_encoding('■'))) {
$this->markTestSkipped('The mbstring extension is needed for multi-byte support');
}

$progress = new ProgressHelper();
$progress->start($output = $this->getOutputStream());
$progress->setBarCharacter('■');
Expand Down
14 changes: 6 additions & 8 deletions src/Symfony/Component/Console/Tests/Helper/TableHelperTest.php
Expand Up @@ -233,12 +233,11 @@ public function testRenderProvider()
);
}

/**
* @requires extension mbstring
*/
public function testRenderMultiByte()
{
if (!function_exists('mb_strwidth')) {
$this->markTestSkipped('The "mbstring" extension is not available');
}

$table = new TableHelper();
$table
->setHeaders(array('■■'))
Expand All @@ -260,12 +259,11 @@ public function testRenderMultiByte()
$this->assertEquals($expected, $this->getOutputContent($output));
}

/**
* @requires extension mbstring
*/
public function testRenderFullWidthCharacters()
{
if (!function_exists('mb_strwidth')) {
$this->markTestSkipped('The "mbstring" extension is not available');
}

$table = new TableHelper();
$table
->setHeaders(array('あいうえお'))
Expand Down
2 changes: 1 addition & 1 deletion src/Symfony/Component/Form/Tests/AbstractLayoutTest.php
Expand Up @@ -22,7 +22,7 @@ abstract class AbstractLayoutTest extends \Symfony\Component\Form\Test\FormInteg
protected function setUp()
{
if (!extension_loaded('intl')) {
$this->markTestSkipped('The "intl" extension is not available');
$this->markTestSkipped('Extension intl is required.');

This comment has been minimized.

Copy link
@OskarStark

OskarStark Oct 12, 2015

Contributor

`@requires extension intl`` doesn't work here?

This comment has been minimized.

Copy link
@nicolas-grekas

nicolas-grekas Oct 12, 2015

Author Member

no because it's an abstract class and annotations are not propagated to children

This comment has been minimized.

Copy link
@OskarStark

OskarStark Oct 12, 2015

Contributor

ah, thank you for the info 👍

}

\Locale::setDefault('en');
Expand Down
Expand Up @@ -116,12 +116,11 @@ public function testTransformDifferentTimezones()
$this->assertSame($output, $transformer->transform($input));
}

/**
* @requires PHP 5.5
*/
public function testTransformDateTimeImmutable()
{
if (PHP_VERSION_ID < 50500) {
$this->markTestSkipped('DateTimeImmutable was introduced in PHP 5.5.0');
}

$transformer = new DateTimeToArrayTransformer('America/New_York', 'Asia/Hong_Kong');

$input = new \DateTimeImmutable('2010-02-03 04:05:06 America/New_York');
Expand Down
Expand Up @@ -141,12 +141,11 @@ public function testTransformWithDifferentPatterns()
$this->assertEquals('02*2010*03 04|05|06', $transformer->transform($this->dateTime));
}

/**
* @requires PHP 5.5
*/
public function testTransformDateTimeImmutableTimezones()
{
if (PHP_VERSION_ID < 50500) {
$this->markTestSkipped('DateTimeImmutable was introduced in PHP 5.5.0');
}

$transformer = new DateTimeToLocalizedStringTransformer('America/New_York', 'Asia/Hong_Kong');

$input = new \DateTimeImmutable('2010-02-03 04:05:06 America/New_York');
Expand Down
Expand Up @@ -81,13 +81,10 @@ public function testTransform($fromTz, $toTz, $from, $to)

/**
* @dataProvider transformProvider
* @requires PHP 5.5
*/
public function testTransformDateTimeImmutable($fromTz, $toTz, $from, $to)
{
if (PHP_VERSION_ID < 50500) {
$this->markTestSkipped('DateTimeImmutable was introduced in PHP 5.5.0');
}

$transformer = new DateTimeToRfc3339Transformer($fromTz, $toTz);

$this->assertSame($to, $transformer->transform(null !== $from ? new \DateTimeImmutable($from) : null));
Expand Down
Expand Up @@ -97,12 +97,11 @@ public function testTransformWithDifferentTimezones()
$this->assertEquals($output, $transformer->transform($input));
}

/**
* @requires PHP 5.5
*/
public function testTransformDateTimeImmutable()
{
if (PHP_VERSION_ID < 50500) {
$this->markTestSkipped('DateTimeImmutable was introduced in PHP 5.5.0');
}

$transformer = new DateTimeToStringTransformer('Asia/Hong_Kong', 'America/New_York', 'Y-m-d H:i:s');

$input = new \DateTimeImmutable('2010-02-03 12:05:06 America/New_York');
Expand Down
Expand Up @@ -56,12 +56,11 @@ public function testTransformFromDifferentTimezone()
$this->assertEquals($output, $transformer->transform($input));
}

/**
* @requires PHP 5.5
*/
public function testTransformDateTimeImmutable()
{
if (PHP_VERSION_ID < 50500) {
$this->markTestSkipped('DateTimeImmutable was introduced in PHP 5.5.0');
}

$transformer = new DateTimeToTimestampTransformer('Asia/Hong_Kong', 'America/New_York');

$input = new \DateTimeImmutable('2010-02-03 04:05:06 America/New_York');
Expand Down
Expand Up @@ -134,13 +134,13 @@ public function testReverseTransformWithGrouping($to, $from, $locale)
$this->assertEquals($to, $transformer->reverseTransform($from));
}

// https://github.com/symfony/symfony/issues/7609
/**
* @see https://github.com/symfony/symfony/issues/7609
*
* @requires extension mbstring
*/
public function testReverseTransformWithGroupingAndFixedSpaces()
{
if (!function_exists('mb_detect_encoding')) {
$this->markTestSkipped('The "mbstring" extension is required for this test.');
}

// Since we test against other locales, we need the full implementation
IntlTestHelper::requireFullIntl($this);

Expand Down Expand Up @@ -375,13 +375,10 @@ public function testReverseTransformDisallowsCenteredExtraCharacters()
/**
* @expectedException \Symfony\Component\Form\Exception\TransformationFailedException
* @expectedExceptionMessage The number contains unrecognized characters: "foo8"
* @requires extension mbstring
*/
public function testReverseTransformDisallowsCenteredExtraCharactersMultibyte()
{
if (!function_exists('mb_detect_encoding')) {
$this->markTestSkipped('The "mbstring" extension is required for this test.');
}

// Since we test against other locales, we need the full implementation
IntlTestHelper::requireFullIntl($this);

Expand All @@ -395,13 +392,10 @@ public function testReverseTransformDisallowsCenteredExtraCharactersMultibyte()
/**
* @expectedException \Symfony\Component\Form\Exception\TransformationFailedException
* @expectedExceptionMessage The number contains unrecognized characters: "foo8"
* @requires extension mbstring
*/
public function testReverseTransformIgnoresTrailingSpacesInExceptionMessage()
{
if (!function_exists('mb_detect_encoding')) {
$this->markTestSkipped('The "mbstring" extension is required for this test.');
}

// Since we test against other locales, we need the full implementation
IntlTestHelper::requireFullIntl($this);

Expand All @@ -426,13 +420,10 @@ public function testReverseTransformDisallowsTrailingExtraCharacters()
/**
* @expectedException \Symfony\Component\Form\Exception\TransformationFailedException
* @expectedExceptionMessage The number contains unrecognized characters: "foo"
* @requires extension mbstring
*/
public function testReverseTransformDisallowsTrailingExtraCharactersMultibyte()
{
if (!function_exists('mb_detect_encoding')) {
$this->markTestSkipped('The "mbstring" extension is required for this test.');
}

// Since we test against other locales, we need the full implementation
IntlTestHelper::requireFullIntl($this);

Expand Down
Expand Up @@ -873,8 +873,7 @@ public function testDayErrorsBubbleUp($widget)
public function testYearsFor32BitsMachines()
{
if (4 !== PHP_INT_SIZE) {
$this->markTestSkipped(
'PHP must be compiled in 32 bit mode to run this test');
$this->markTestSkipped('PHP 32 bit is required.');
}

$form = $this->factory->create('date', null, array(
Expand Down
Expand Up @@ -47,14 +47,13 @@ public function testGenerateCsrfToken()
$this->assertEquals(sha1('SECRET'.'foo'.session_id()), $token);
}

/**
* @requires PHP 5.4
*/
public function testGenerateCsrfTokenOnUnstartedSession()
{
session_id('touti');

if (PHP_VERSION_ID < 50400) {
$this->markTestSkipped('This test requires PHP >= 5.4');
}

$this->assertSame(PHP_SESSION_NONE, session_status());

$token = $this->provider->generateCsrfToken('foo');
Expand Down
5 changes: 1 addition & 4 deletions src/Symfony/Component/HttpFoundation/Tests/IpUtilsTest.php
Expand Up @@ -68,13 +68,10 @@ public function testIpv6Provider()

/**
* @expectedException \RuntimeException
* @requires extension sockets
*/
public function testAnIpv6WithOptionDisabledIpv6()
{
if (!extension_loaded('sockets')) {
$this->markTestSkipped('Only works when the socket extension is enabled');
}

if (defined('AF_INET6')) {
$this->markTestSkipped('Only works when PHP is compiled with the option "disable-ipv6".');
}
Expand Down

0 comments on commit 4061d37

Please sign in to comment.