8000 minor #16186 [2.7][tests] Use @requires annotation when possible (nic… · symfony/symfony@52dbc3b · GitHub
[go: up one dir, main page]

Skip to content

Commit 52dbc3b

Browse files
minor #16186 [2.7][tests] Use @requires annotation when possible (nicolas-grekas)
This PR was merged into the 2.7 branch. Discussion ---------- [2.7][tests] Use @requires annotation when possible | Q | A | ------------- | --- | Bug fix? | no | New feature? | no | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | - | License | MIT | Doc PR | - Commits ------- b028aea [tests] Use @requires annotation when possible
2 parents 309ad43 + b028aea commit 52dbc3b

File tree

23 files changed

+247
-96
lines changed

23 files changed

+247
-96
lines changed

src/Symfony/Bundle/FrameworkBundle/Tests/Console/Descriptor/JsonDescriptorTest.php

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,15 +13,11 @@
1313

1414
use Symfony\Bundle\FrameworkBundle\Console\Descriptor\JsonDescriptor;
1515

16+
/**
17+
* @requires PHP 5.4
18+
*/
1619
class JsonDescriptorTest extends AbstractDescriptorTest
1720
{
18-
protected function setUp()
19-
{
20-
if (PHP_VERSION_ID < 50400) {
21-
$this->markTestSkipped('Test skipped on PHP 5.3 as JSON_PRETTY_PRINT does not exist.');
22-
}
23-
}
24-
2521
protected function getDescriptor()
2622
{
2723
return new JsonDescriptor();

src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/FrameworkExtensionTest.php

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -291,13 +291,10 @@ public function testValidation()
291291

292292
/**
293293
* @group legacy
294+
* @requires extension apc
294295
*/
295296
public function testLegacyFullyConfiguredValidationService()
296297
{
297-
if (!extension_loaded('apc')) {
298-
$this->markTestSkipped('The apc extension is not available.');
299-
}
300-
301298
$container = $this->createContainerFromFile('full');
302299

303300
$this->assertInstanceOf('Symfony\Component\Validator\Validator\ValidatorInterface', $container->get('validator'));

src/Symfony/Bundle/SecurityBundle/Tests/Functional/SetAclCommandTest.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
* Tests SetAclCommand.
3434
*
3535
* @author Kévin Dunglas <kevin@les-tilleuls.coop>
36+
* @requires extension pdo_sqlite
3637
*/
3738
class SetAclCommandTest extends WebTestCase
3839
{
@@ -41,9 +42,6 @@ class SetAclCommandTest extends WebTestCase
4142

4243
protected function setUp()
4344
{
44-
if (!class_exists('PDO') || !in_array('sqlite', \PDO::getAvailableDrivers())) {
45-
self::markTestSkipped('This test requires SQLite support in your environment');
46-
}
4745
parent::setUp();
4846

4947
$this->deleteTmpDir('Acl');
Lines changed: 199 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,199 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Symfony package.
5+
*
6+
* (c) Fabien Potencier <fabien@symfony.com>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
namespace Symfony\Component\ClassLoader\Tests;
13+
14+
use Symfony\Component\ClassLoader\ApcClassLoader;
15+
use Symfony\Component\ClassLoader\ClassLoader;
16+
17+
/**
18+
* @requires extension apc
19+
*/
20+
class ApcClassLoaderTest extends \PHPUnit_Framework_TestCase
21+
{
22+
protected function setUp()
23+
{
24+
if (!(ini_get('apc.enabled') && ini_get('apc.enable_cli'))) {
25+
$this->markTestSkipped('The apc extension is available, but not enabled.');
26+
} else {
27+
apc_clear_cache('user');
28+
}
29+
}
30+
31+
protected function tearDown()
32+
{
33+
if (ini_get('apc.enabled') && ini_get('apc.enable_cli')) {
34+
apc_clear_cache('user');
35+
}
36+
}
37+
38+
public function testConstructor()
39+
{
40+
$loader = new ClassLoader();
41+
$loader->addPrefix('Apc\Namespaced', __DIR__.DIRECTORY_SEPARATOR.'Fixtures');
42+
43+
$loader = new ApcClassLoader('test.prefix.', $loader);
44+
45+
$this->assertEquals($loader->findFile('\Apc\Namespaced\FooBar'), apc_fetch('test.prefix.\Apc\Namespaced\FooBar'), '__construct() takes a prefix as its first argument');
46+
}
47+
48+
/**
49+
* @dataProvider getLoadClassTests
50+
*/
51+
public function testLoadClass($className, $testClassName, $message)
52+
{
53+
$loader = new ClassLoader();
54+
$loader->addPrefix('Apc\Namespaced', __DIR__.DIRECTORY_SEPARATOR.'Fixtures');
55+
$loader->addPrefix('Apc_Pearlike_', __DIR__.DIRECTORY_SEPARATOR.'Fixtures');
56+
57+
$loader = new ApcClassLoader('test.prefix.', $loader);
58+
$loader->loadClass($testClassName);
59+
$this->assertTrue(class_exists($className), $message);
60+
}
61+
62+
public function getLoadClassTests()
63+
{
64+
return array(
65+
array('\\Apc\\Namespaced\\Foo', 'Apc\\Namespaced\\Foo', '->loadClass() loads Apc\Namespaced\Foo class'),
66+
array('Apc_Pearlike_Foo', 'Apc_Pearlike_Foo', '->loadClass() loads Apc_Pearlike_Foo class'),
67+
);
68+
}
69+
70+
/**
71+
* @dataProvider getLoadClassFromFallbackTests
72+
*/
73+
public function testLoadClassFromFallback($className, $testClassName, $message)
74+
{
75+
$loader = new ClassLoader();
76+
$loader->addPrefix('Apc\Namespaced', __DIR__.DIRECTORY_SEPARATOR.'Fixtures');
77+
$loader->addPrefix('Apc_Pearlike_', __DIR__.DIRECTORY_SEPARATOR.'Fixtures');
78+
$loader->addPrefix('', array(__DIR__.DIRECTORY_SEPARATOR.'Fixtures/Apc/fallback'));
79+
80+
$loader = new ApcClassLoader('test.prefix.fallback', $loader);
81+
$loader->loadClass($testClassName);
82+
83+
$this->assertTrue(class_exists($className), $message);
84+
}
85+
86+
public function getLoadClassFromFallbackTests()
87+
{
88+
return array(
89+
array('\\Apc\\Namespaced\\Baz', 'Apc\\Namespaced\\Baz', '->loadClass() loads Apc\Namespaced\Baz class'),
90+
array('Apc_Pearlike_Baz', 'Apc_Pearlike_Baz', '->loadClass() loads Apc_Pearlike_Baz class'),
91+
array('\\Apc\\Namespaced\\FooBar', 'Apc\\Namespaced\\FooBar', '->loadClass() loads Apc\Namespaced\Baz class from fallback dir'),
92+
array('Apc_Pearlike_FooBar', 'Apc_Pearlike_FooBar', '->loadClass() loads Apc_Pearlike_Baz class from fallback dir'),
93+
);
94+
}
95+
96+
/**
97+
* @dataProvider getLoadClassNamespaceCollisionTests
98+
*/
99+
public function testLoadClassNamespaceCollision($namespaces, $className, $message)
100+
{
101+
$loader = new ClassLoader();
102+
$loader->addPrefixes($namespaces);
103+
104+
$loader = new ApcClassLoader('test.prefix.collision.', $loader);
105+
$loader->loadClass($className);
106+
107+
$this->assertTrue(class_exists($className), $message);
108+
}
109+
110+
public function getLoadClassNamespaceCollisionTests()
111+
{
112+
return array(
113+
array(
114+
array(
115+
'Apc\\NamespaceCollision\\A' => __DIR__.DIRECTORY_SEPARATOR.'Fixtures/Apc/alpha',
116+
'Apc\\NamespaceCollision\\A\\B' => __DIR__.DIRECTORY_SEPARATOR.'Fixtures/Apc/beta',
117+
),
118+
'Apc\NamespaceCollision\A\Foo',
119+
'->loadClass() loads NamespaceCollision\A\Foo from alpha.',
120+
),
121+
array(
122+
array(
123+
'Apc\\NamespaceCollision\\A\\B' => __DIR__.DIRECTORY_SEPARATOR.'Fixtures/Apc/beta',
124+
'Apc\\NamespaceCollision\\A' => __DIR__.DIRECTORY_SEPARATOR.'Fixtures/Apc/alpha',
125+
),
126+
'Apc\NamespaceCollision\A\Bar',
127+
'->loadClass() loads NamespaceCollision\A\Bar from alpha.',
128+
),
129+
array(
130+
array(
131+
'Apc\\NamespaceCollision\\A' => __DIR__.DIRECTORY_SEPARATOR.'Fixtures/Apc/alpha',
132+
'Apc\\NamespaceCollision\\A\\B' => __DIR__.DIRECTORY_SEPARATOR.'Fixtures/Apc/beta',
133+
),
134+
'Apc\NamespaceCollision\A\B\Foo',
135+
'->loadClass() loads NamespaceCollision\A\B\Foo from beta.',
136+
),
137+
array(
138+
array(
139+
'Apc\\NamespaceCollision\\A\\B' => __DIR__.DIRECTORY_SEPARATOR.'Fixtures/Apc/beta',
140+
'Apc\\NamespaceCollision\\A' => __DIR__.DIRECTORY_SEPARATOR.'Fixtures/Apc/alpha',
141+
),
142+
'Apc\NamespaceCollision\A\B\Bar',
143+
'->loadClass() loads NamespaceCollision\A\B\Bar from beta.',
144+
),
145+
);
146+
}
147+
148+
/**
149+
* @dataProvider getLoadClassPrefixCollisionTests
150+
*/
151+
public function testLoadClassPrefixCollision($prefixes, $className, $message)
152+
{
153+
$loader = new ClassLoader();
154+
$loader->addPrefixes($prefixes);
155+
156+
$loader = new ApcClassLoader('test.prefix.collision.', $loader);
157+
$loader->loadClass($className);
158+
159+
$this->assertTrue(class_exists($className), $message);
160+
}
161+
162+
public function getLoadClassPrefixCollisionTests()
163+
{
164+
return array(
165+
array(
166+
array(
167+
'ApcPrefixCollision_A_' => __DIR__.DIRECTORY_SEPARATOR.'Fixtures/Apc/alpha/Apc',
168+
'ApcPrefixCollision_A_B_' => __DIR__.DIRECTORY_SEPARATOR.'Fixtures/Apc/beta/Apc',
169+
),
170+
'ApcPrefixCollision_A_Foo',
171+
'->loadClass() loads ApcPrefixCollision_A_Foo from alpha.',
172+
),
173+
array(
174+
array(
175+
'ApcPrefixCollision_A_B_' => __DIR__.DIRECTORY_SEPARATOR.'Fixtures/Apc/beta/Apc',
176+
'ApcPrefixCollision_A_' => __DIR__.DIRECTORY_SEPARATOR.'Fixtures/Apc/alpha/Apc',
177+
),
178+
'ApcPrefixCollision_A_Bar',
179+
'->loadClass() loads ApcPrefixCollision_A_Bar from alpha.',
180+
),
181+
array(
182+
array(
183+
'ApcPrefixCollision_A_' => __DIR__.DIRECTORY_SEPARATOR.'Fixtures/Apc/alpha/Apc',
184+
'ApcPrefixCollision_A_B_' => __DIR__.DIRECTORY_SEPARATOR.'Fixtures/Apc/beta/Apc',
185+
),
186+
'ApcPrefixCollision_A_B_Foo',
187+
'->loadClass() loads ApcPrefixCollision_A_B_Foo from beta.',
188+
),
189+
array(
190+
array(
191+
'ApcPrefixCollision_A_B_' => __DIR__.DIRECTORY_SEPARATOR.'Fixtures/Apc/beta/Apc',
192+
'ApcPrefixCollision_A_' => __DIR__.DIRECTORY_SEPARATOR.'Fixtures/Apc/alpha/Apc',
193+
),
194+
'ApcPrefixCollision_A_B_Bar',
195+
'->loadClass() loads ApcPrefixCollision_A_B_Bar from beta.',
196+
),
197+
);
198+
}
199+
}

src/Symfony/Component/Console/Tests/ApplicationTest.php

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1001,12 +1001,11 @@ public function testSetRunCustomDefaultCommand()
10011001
$this->assertEquals('interact called'.PHP_EOL.'called'.PHP_EOL, $tester->getDisplay(), 'Application runs the default set command if different from \'list\' command');
10021002
}
10031003

1004+
/**
1005+
* @requires function posix_isatty
1006+
*/
10041007
public function testCanCheckIfTerminalIsInteractive()
10051008
{
1006-
if (!function_exists('posix_isatty')) {
1007-
$this->markTestSkipped('posix_isatty function is required');
1008-
}
1009-
10101009
$application = new CustomDefaultCommandApplication();
10111010
$application->setAutoExit(false);
10121011

src/Symfony/Component/Console/Tests/Helper/ProgressBarTest.php

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -270,12 +270,11 @@ public function testRedrawFrequency()
270270
$bar->advance(1);
271271
}
272272

273+
/**
274+
* @requires extension mbstring
275+
*/
273276
public function testMultiByteSupport()
274277
{
275-
if (!function_exists('mb_strlen') || (false === $encoding = mb_detect_encoding(''))) {
276-
$this->markTestSkipped('The mbstring extension is needed for multi-byte support');
277-
}
278-
279278
$bar = new ProgressBar($output = $this->getOutputStream());
280279
$bar->start();
281280
$bar->setBarCharacter('');

src/Symfony/Component/Console/Tests/Helper/TableTest.php

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -464,12 +464,11 @@ public function testRenderProvider()
464464
);
465465
}
466466

467+
/**
468+
* @requires extension mbstring
469+
*/
467470
public function testRenderMultiByte()
468471
{
469-
if (!function_exists('mb_strlen')) {
470-
$this->markTestSkipped('The "mbstring" extension is not available');
471-
}
472-
473472
$table = new Table($output = $this->getOutputStream());
474473
$table
475474
->setHeaders(array('■■'))

src/Symfony/Component/DependencyInjection/Tests/Compiler/MergeExtensionConfigurationPassTest.php

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,6 @@ class MergeExtensionConfigurationPassTest extends \PHPUnit_Framework_TestCase
1919
{
2020
public function testExpressionLanguageProviderForwarding()
2121
{
22-
if (true !== class_exists('Symfony\\Component\\ExpressionLanguage\\ExpressionLanguage')) {
23-
$this->markTestSkipped('The ExpressionLanguage component isn\'t available!');
24-
}
25-
2622
$tmpProviders = array();
2723

2824
$extension = $this->getMock('Symfony\\Component\\DependencyInjection\\Extension\\ExtensionInterface');

src/Symfony/Component/Filesystem/Tests/FilesystemTestCase.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -95,25 +95,25 @@ protected function getFileGroup($filepath)
9595
protected function markAsSkippedIfSymlinkIsMissing()
9696
{
9797
if (!function_exists('symlink')) {
98-
$this->markTestSkipped('symlink is not supported');
98+
$this->markTestSkipped('Function symlink is required.');
9999
}
100100

101101
if ('\\' === DIRECTORY_SEPARATOR && false === self::$symlinkOnWindows) {
102-
$this->markTestSkipped('symlink requires "Create symbolic links" privilege on windows');
102+
$this->markTestSkipped('symlink requires "Create symbolic links" privilege on Windows');
103103
}
104104
}
105105

106106
protected function markAsSkippedIfChmodIsMissing()
107107
{
108108
if ('\\' === DIRECTORY_SEPARATOR) {
109-
$this->markTestSkipped('chmod is not supported on windows');
109+
$this->markTestSkipped('chmod is not supported on Windows');
110110
}
111111
}
112112

113113
protected function markAsSkippedIfPosixIsMissing()
114114
{
115-
if ('\\' === DIRECTORY_SEPARATOR || !function_exists('posix_isatty')) {
116-
$this->markTestSkipped('Posix is not supported');
115+
if (!function_exists('posix_isatty')) {
116+
$this->markTestSkipped('Function posix_isatty is required.');
117117
}
118118
}
119119
}

src/Symfony/Component/HttpFoundation/Tests/JsonResponseTest.php

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -205,13 +205,10 @@ public function testSetContent()
205205
/**
206206
* @expectedException \Exception
207207
* @expectedExceptionMessage This error is expected
208+
* @requires PHP 5.4
208209
*/
209210
public function testSetContentJsonSerializeError()
210211
{
211-
if (!interface_exists('JsonSerializable')) {
212-
$this->markTestSkipped('Interface JsonSerializable is available in PHP 5.4+');
213-
}
214-
215212
$serializable = new JsonSerializableObject();
216213

217214
JsonResponse::create($serializable);

src/Symfony/Component/HttpFoundation/Tests/Session/Storage/Handler/LegacyPdoSessionHandlerTest.php

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,17 +15,14 @@
1515

1616
/**
1717
* @group legacy
18+
* @requires extension pdo_sqlite
1819
*/
1920
class LegacyPdoSessionHandlerTest extends \PHPUnit_Framework_TestCase
2021
{
2122
private $pdo;
2223

2324
protected function setUp()
2425
{
25-
if (!class_exists('PDO') || !in_array('sqlite', \PDO::getAvailableDrivers())) {
26-
$this->markTestSkipped('This test requires SQLite support in your environment');
27-
}
28-
2926
$this->pdo = new \PDO('sqlite::memory:');
3027
$this->pdo->setAttribute(\PDO::ATTR_ERRMODE, \PDO::ERRMODE_EXCEPTION);
3128
$sql = 'CREATE TABLE sessions (sess_id VARCHAR(128) PRIMARY KEY, sess_data TEXT, sess_time INTEGER)';

src/Symfony/Component/HttpKernel/Tests/DataCollector/Util/ValueExporterTest.php

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,12 +31,11 @@ public function testDateTime()
3131
$this->assertSame('Object(DateTime) - 2014-06-10T07:35:40+0000', $this->valueExporter->exportValue($dateTime));
3232
}
3333

34+
/**
35+
* @requires PHP 5.5
36+
*/
3437
public function testDateTimeImmutable()
3538
{
36-
if (!class_exists('DateTimeImmutable', false)) {
37-
$this->markTestSkipped('Test skipped, class DateTimeImmutable does not exist.');
38-
}
39-
4039
$dateTime = new \DateTimeImmutable('2014-06-10 07:35:40', new \DateTimeZone('UTC'));
4140
$this->assertSame('Object(DateTimeImmutable) - 2014-06-10T07:35:40+0000', $this->valueExporter->exportValue($dateTime));
4241
}

0 commit comments

Comments
 (0)
0