Skip to content

Commit 09c4a64

Browse files
[tests] Use @requires annotation when possible
1 parent b885ae6 commit 09c4a64

9 files changed

+26
-44
lines changed

Tests/AbstractLayoutTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ abstract class AbstractLayoutTest extends \Symfony\Component\Form\Test\FormInteg
2222
protected function setUp()
2323
{
2424
if (!extension_loaded('intl')) {
25-
$this->markTestSkipped('The "intl" extension is not available');
25+
$this->markTestSkipped('Extension intl is required.');
2626
}
2727

2828
\Locale::setDefault('en');

Tests/Extension/Core/DataTransformer/DateTimeToArrayTransformerTest.php

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -116,12 +116,11 @@ public function testTransformDifferentTimezones()
116116
$this->assertSame($output, $transformer->transform($input));
117117
}
118118

119+
/**
120+
* @requires PHP 5.5
121+
*/
119122
public function testTransformDateTimeImmutable()
120123
{
121-
if (PHP_VERSION_ID < 50500) {
122-
$this->markTestSkipped('DateTimeImmutable was introduced in PHP 5.5.0');
123-
}
124-
125124
$transformer = new DateTimeToArrayTransformer('America/New_York', 'Asia/Hong_Kong');
126125

127126
$input = new \DateTimeImmutable('2010-02-03 04:05:06 America/New_York');

Tests/Extension/Core/DataTransformer/DateTimeToLocalizedStringTransformerTest.php

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -141,12 +141,11 @@ public function testTransformWithDifferentPatterns()
141141
$this->assertEquals('02*2010*03 04|05|06', $transformer->transform($this->dateTime));
142142
}
143143

144+
/**
145+
* @requires PHP 5.5
146+
*/
144147
public function testTransformDateTimeImmutableTimezones()
145148
{
146-
if (PHP_VERSION_ID < 50500) {
147-
$this->markTestSkipped('DateTimeImmutable was introduced in PHP 5.5.0');
148-
}
149-
150149
$transformer = new DateTimeToLocalizedStringTransformer('America/New_York', 'Asia/Hong_Kong');
151150

152151
$input = new \DateTimeImmutable('2010-02-03 04:05:06 America/New_York');

Tests/Extension/Core/DataTransformer/DateTimeToRfc3339TransformerTest.php

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -81,13 +81,10 @@ public function testTransform($fromTz, $toTz, $from, $to)
8181

8282
/**
8383
* @dataProvider transformProvider
84+
* @requires PHP 5.5
8485
*/
8586
public function testTransformDateTimeImmutable($fromTz, $toTz, $from, $to)
8687
{
87-
if (PHP_VERSION_ID < 50500) {
88-
$this->markTestSkipped('DateTimeImmutable was introduced in PHP 5.5.0');
89-
}
90-
9188
$transformer = new DateTimeToRfc3339Transformer($fromTz, $toTz);
9289

9390
$this->assertSame($to, $transformer->transform(null !== $from ? new \DateTimeImmutable($from) : null));

Tests/Extension/Core/DataTransformer/DateTimeToStringTransformerTest.php

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -97,12 +97,11 @@ public function testTransformWithDifferentTimezones()
9797
$this->assertEquals($output, $transformer->transform($input));
9898
}
9999

100+
/**
101+
* @requires PHP 5.5
102+
*/
100103
public function testTransformDateTimeImmutable()
101104
{
102-
if (PHP_VERSION_ID < 50500) {
103-
$this->markTestSkipped('DateTimeImmutable was introduced in PHP 5.5.0');
104-
}
105-
106105
$transformer = new DateTimeToStringTransformer('Asia/Hong_Kong', 'America/New_York', 'Y-m-d H:i:s');
107106

108107
$input = new \DateTimeImmutable('2010-02-03 12:05:06 America/New_York');

Tests/Extension/Core/DataTransformer/DateTimeToTimestampTransformerTest.php

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -56,12 +56,11 @@ public function testTransformFromDifferentTimezone()
5656
$this->assertEquals($output, $transformer->transform($input));
5757
}
5858

59+
/**
60+
* @requires PHP 5.5
61+
*/
5962
public function testTransformDateTimeImmutable()
6063
{
61-
if (PHP_VERSION_ID < 50500) {
62-
$this->markTestSkipped('DateTimeImmutable was introduced in PHP 5.5.0');
63-
}
64-
6564
$transformer = new DateTimeToTimestampTransformer('Asia/Hong_Kong', 'America/New_York');
6665

6766
$input = new \DateTimeImmutable('2010-02-03 04:05:06 America/New_York');

Tests/Extension/Core/DataTransformer/NumberToLocalizedStringTransformerTest.php

Lines changed: 8 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -134,13 +134,13 @@ public function testReverseTransformWithGrouping($to, $from, $locale)
134134
$this->assertEquals($to, $transformer->reverseTransform($from));
135135
}
136136

137-
// https://github.com/symfony/symfony/issues/7609
137+
/**
138+
* @see https://github.com/symfony/symfony/issues/7609
139+
*
140+
* @requires extension mbstring
141+
*/
138142
public function testReverseTransformWithGroupingAndFixedSpaces()
139143
{
140-
if (!function_exists('mb_detect_encoding')) {
141-
$this->markTestSkipped('The "mbstring" extension is required for this test.');
142-
}
143-
144144
// Since we test against other locales, we need the full implementation
145145
IntlTestHelper::requireFullIntl($this);
146146

@@ -375,13 +375,10 @@ public function testReverseTransformDisallowsCenteredExtraCharacters()
375375
/**
376376
* @expectedException \Symfony\Component\Form\Exception\TransformationFailedException
377377
* @expectedExceptionMessage The number contains unrecognized characters: "foo8"
378+
* @requires extension mbstring
378379
*/
379380
public function testReverseTransformDisallowsCenteredExtraCharactersMultibyte()
380381
{
381-
if (!function_exists('mb_detect_encoding')) {
382-
$this->markTestSkipped('The "mbstring" extension is required for this test.');
383-
}
384-
385382
// Since we test against other locales, we need the full implementation
386383
IntlTestHelper::requireFullIntl($this);
387384

@@ -395,13 +392,10 @@ public function testReverseTransformDisallowsCenteredExtraCharactersMultibyte()
395392
/**
396393
* @expectedException \Symfony\Component\Form\Exception\TransformationFailedException
397394
* @expectedExceptionMessage The number contains unrecognized characters: "foo8"
395+
* @requires extension mbstring
398396
*/
399397
public function testReverseTransformIgnoresTrailingSpacesInExceptionMessage()
400398
{
401-
if (!function_exists('mb_detect_encoding')) {
402-
$this->markTestSkipped('The "mbstring" extension is required for this test.');
403-
}
404-
405399
// Since we test against other locales, we need the full implementation
406400
IntlTestHelper::requireFullIntl($this);
407401

@@ -426,13 +420,10 @@ public function testReverseTransformDisallowsTrailingExtraCharacters()
426420
/**
427421
* @expectedException \Symfony\Component\Form\Exception\TransformationFailedException
428422
* @expectedExceptionMessage The number contains unrecognized characters: "foo"
423+
* @requires extension mbstring
429424
*/
430425
public function testReverseTransformDisallowsTrailingExtraCharactersMultibyte()
431426
{
432-
if (!function_exists('mb_detect_encoding')) {
433-
$this->markTestSkipped('The "mbstring" extension is required for this test.');
434-
}
435-
436427
// Since we test against other locales, we need the full implementation
437428
IntlTestHelper::requireFullIntl($this);
438429

Tests/Extension/Core/Type/DateTypeTest.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -873,8 +873,7 @@ public function testDayErrorsBubbleUp($widget)
873873
public function testYearsFor32BitsMachines()
874874
{
875875
if (4 !== PHP_INT_SIZE) {
876-
$this->markTestSkipped(
877-
'PHP must be compiled in 32 bit mode to run this test');
876+
$this->markTestSkipped('PHP 32 bit is required.');
878877
}
879878

880879
$form = $this->factory->create('date', null, array(

Tests/Extension/Csrf/CsrfProvider/DefaultCsrfProviderTest.php

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -47,14 +47,13 @@ public function testGenerateCsrfToken()
4747
$this->assertEquals(sha1('SECRET'.'foo'.session_id()), $token);
4848
}
4949

50+
/**
51+
* @requires PHP 5.4
52+
*/
5053
public function testGenerateCsrfTokenOnUnstartedSession()
5154
{
5255
session_id('touti');
5356

54-
if (PHP_VERSION_ID < 50400) {
55-
$this->markTestSkipped('This test requires PHP >= 5.4');
56-
}
57-
5857
$this->assertSame(PHP_SESSION_NONE, session_status());
5958

6059
$token = $this->provider->generateCsrfToken('foo');

0 commit comments

Comments
 (0)