Skip to content

Commit 7820f8d

Browse files
committed
bug #41384 Fix SkippedTestSuite (jderusse)
This PR was merged into the 4.4 branch. Discussion ---------- Fix SkippedTestSuite | Q | A | ------------- | --- | Branch? | 4.4 | Bug fix? | yes | New feature? | no | Deprecations? | no | Tickets | - | License | MIT | Doc PR | - Throwing a TestSkipped in a `setUpBeforeClass` si handled by PHP unit as a standard exception, leading to a generic exception `Test skipped because of an error in hook method` (see https://github.com/symfony/symfony/pull/41380/checks?check_run_id=2645369759#step:14:165) However phpunit is able to catch `SkippedTestSuiteError` in such situation.(https://github.com/sebastianbergmann/phpunit/blob/master/src/Framework/TestSuite.php#L438-L448) This PR replaces `self::markTestSkipped` by `throw new SkippedTestSuiteError` (we don't have static method helper for this exception) in our `setUpBeforeClass` methods. Commits ------- 6f2aa6d Fix SkippedTestSuite
2 parents 2abf5a4 + 6f2aa6d commit 7820f8d

24 files changed

+67
-36
lines changed

src/Symfony/Component/Cache/Tests/Adapter/AbstractRedisAdapterTest.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111

1212
namespace Symfony\Component\Cache\Tests\Adapter;
1313

14+
use PHPUnit\Framework\SkippedTestSuiteError;
1415
use Psr\Cache\CacheItemPoolInterface;
1516
use Symfony\Component\Cache\Adapter\RedisAdapter;
1617

@@ -32,12 +33,12 @@ public function createCachePool(int $defaultLifetime = 0, string $testMethod = n
3233
public static function setUpBeforeClass(): void
3334
{
3435
if (!\extension_loaded('redis')) {
35-
self::markTestSkipped('Extension redis required.');
36+
throw new SkippedTestSuiteError('Extension redis required.');
3637
}
3738
try {
3839
(new \Redis())->connect(getenv('REDIS_HOST'));
3940
} catch (\Exception $e) {
40-
self::markTestSkipped($e->getMessage());
41+
throw new SkippedTestSuiteError($e->getMessage());
4142
}
4243
}
4344

src/Symfony/Component/Cache/Tests/Adapter/MemcachedAdapterTest.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111

1212
namespace Symfony\Component\Cache\Tests\Adapter;
1313

14+
use PHPUnit\Framework\SkippedTestSuiteError;
1415
use Psr\Cache\CacheItemPoolInterface;
1516
use Symfony\Component\Cache\Adapter\AbstractAdapter;
1617
use Symfony\Component\Cache\Adapter\MemcachedAdapter;
@@ -32,14 +33,14 @@ class MemcachedAdapterTest extends AdapterTestCase
3233
public static function setUpBeforeClass(): void
3334
{
3435
if (!MemcachedAdapter::isSupported()) {
35-
self::markTestSkipped('Extension memcached >=2.2.0 required.');
36+
throw new SkippedTestSuiteError('Extension memcached >=2.2.0 required.');
3637
}
3738
self::$client = AbstractAdapter::createConnection('memcached://'.getenv('MEMCACHED_HOST'), ['binary_protocol' => false]);
3839
self::$client->get('foo');
3940
$code = self::$client->getResultCode();
4041

4142
if (\Memcached::RES_SUCCESS !== $code && \Memcached::RES_NOTFOUND !== $code) {
42-
self::markTestSkipped('Memcached error: '.strtolower(self::$client->getResultMessage()));
43+
throw new SkippedTestSuiteError('Memcached error: '.strtolower(self::$client->getResultMessage()));
4344
}
4445
}
4546

src/Symfony/Component/Cache/Tests/Adapter/PdoAdapterTest.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111

1212
namespace Symfony\Component\Cache\Tests\Adapter;
1313

14+
use PHPUnit\Framework\SkippedTestSuiteError;
1415
use Psr\Cache\CacheItemPoolInterface;
1516
use Symfony\Component\Cache\Adapter\PdoAdapter;
1617

@@ -26,7 +27,7 @@ class PdoAdapterTest extends AdapterTestCase
2627
public static function setUpBeforeClass(): void
2728
{
2829
if (!\extension_loaded('pdo_sqlite')) {
29-
self::markTestSkipped('Extension pdo_sqlite required.');
30+
throw new SkippedTestSuiteError('Extension pdo_sqlite required.');
3031
}
3132

3233
self::$dbFile = tempnam(sys_get_temp_dir(), 'sf_sqlite_cache');

src/Symfony/Component/Cache/Tests/Adapter/PdoDbalAdapterTest.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
namespace Symfony\Component\Cache\Tests\Adapter;
1313

1414
use Doctrine\DBAL\DriverManager;
15+
use PHPUnit\Framework\SkippedTestSuiteError;
1516
use Psr\Cache\CacheItemPoolInterface;
1617
use Symfony\Component\Cache\Adapter\PdoAdapter;
1718

@@ -27,7 +28,7 @@ class PdoDbalAdapterTest extends AdapterTestCase
2728
public static function setUpBeforeClass(): void
2829
{
2930
if (!\extension_loaded('pdo_sqlite')) {
30-
self::markTestSkipped('Extension pdo_sqlite required.');
31+
throw new SkippedTestSuiteError('Extension pdo_sqlite required.');
3132
}
3233

3334
self::$dbFile = tempnam(sys_get_temp_dir(), 'sf_sqlite_cache');

src/Symfony/Component/Cache/Tests/Adapter/PredisRedisClusterAdapterTest.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111

1212
namespace Symfony\Component\Cache\Tests\Adapter;
1313

14+
use PHPUnit\Framework\SkippedTestSuiteError;
1415
use Symfony\Component\Cache\Adapter\RedisAdapter;
1516

1617
/**
@@ -21,7 +22,7 @@ class PredisRedisClusterAdapterTest extends AbstractRedisAdapterTest
2122
public static function setUpBeforeClass(): void
2223
{
2324
if (!$hosts = getenv('REDIS_CLUSTER_HOSTS')) {
24-
self::markTestSkipped('REDIS_CLUSTER_HOSTS env var is not defined.');
25+
throw new SkippedTestSuiteError('REDIS_CLUSTER_HOSTS env var is not defined.');
2526
}
2627

2728
self::$redis = RedisAdapter::createConnection('redis:?host['.str_replace(' ', ']&host[', $hosts).']', ['class' => \Predis\Client::class, 'redis_cluster' => true, 'prefix' => 'prefix_']);

src/Symfony/Component/Cache/Tests/Adapter/RedisAdapterSentinelTest.php

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111

1212
namespace Symfony\Component\Cache\Tests\Adapter;
1313

14+
use PHPUnit\Framework\SkippedTestSuiteError;
1415
use Symfony\Component\Cache\Adapter\AbstractAdapter;
1516
use Symfony\Component\Cache\Adapter\RedisAdapter;
1617
use Symfony\Component\Cache\Exception\InvalidArgumentException;
@@ -23,13 +24,13 @@ class RedisAdapterSentinelTest extends AbstractRedisAdapterTest
2324
public static function setUpBeforeClass(): void
2425
{
2526
if (!class_exists(\Predis\Client::class)) {
26-
self::markTestSkipped('The Predis\Client class is required.');
27+
throw new SkippedTestSuiteError('The Predis\Client class is required.');
2728
}
2829
if (!$hosts = getenv('REDIS_SENTINEL_HOSTS')) {
29-
self::markTestSkipped('REDIS_SENTINEL_HOSTS env var is not defined.');
30+
throw new SkippedTestSuiteError('REDIS_SENTINEL_HOSTS env var is not defined.');
3031
}
3132
if (!$service = getenv('REDIS_SENTINEL_SERVICE')) {
32-
self::markTestSkipped('REDIS_SENTINEL_SERVICE env var is not defined.');
33+
throw new SkippedTestSuiteError('REDIS_SENTINEL_SERVICE env var is not defined.');
3334
}
3435

3536
self::$redis = AbstractAdapter::createConnection('redis:?host['.str_replace(' ', ']&host[', $hosts).']', ['redis_sentinel' => $service, 'prefix' => 'prefix_']);

src/Symfony/Component/Cache/Tests/Adapter/RedisArrayAdapterTest.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@
1111

1212
namespace Symfony\Component\Cache\Tests\Adapter;
1313

14+
use PHPUnit\Framework\SkippedTestSuiteError;
15+
1416
/**
1517
* @group integration
1618
*/
@@ -20,7 +22,7 @@ public static function setUpBeforeClass(): void
2022
{
2123
parent::setupBeforeClass();
2224
if (!class_exists(\RedisArray::class)) {
23-
self::markTestSkipped('The RedisArray class is required.');
25+
throw new SkippedTestSuiteError('The RedisArray class is required.');
2426
}
2527
self::$redis = new \RedisArray([getenv('REDIS_HOST')], ['lazy_connect' => true]);
2628
self::$redis->setOption(\Redis::OPT_PREFIX, 'prefix_');

src/Symfony/Component/Cache/Tests/Adapter/RedisClusterAdapterTest.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111

1212
namespace Symfony\Component\Cache\Tests\Adapter;
1313

14+
use PHPUnit\Framework\SkippedTestSuiteError;
1415
use Psr\Cache\CacheItemPoolInterface;
1516
use Symfony\Component\Cache\Adapter\AbstractAdapter;
1617
use Symfony\Component\Cache\Adapter\RedisAdapter;
@@ -25,10 +26,10 @@ class RedisClusterAdapterTest extends AbstractRedisAdapterTest
2526
public static function setUpBeforeClass(): void
2627
{
2728
if (!class_exists(\RedisCluster::class)) {
28-
self::markTestSkipped('The RedisCluster class is required.');
29+
throw new SkippedTestSuiteError('The RedisCluster class is required.');
2930
}
3031
if (!$hosts = getenv('REDIS_CLUSTER_HOSTS')) {
31-
self::markTestSkipped('REDIS_CLUSTER_HOSTS env var is not defined.');
32+
throw new SkippedTestSuiteError('REDIS_CLUSTER_HOSTS env var is not defined.');
3233
}
3334

3435
self::$redis = AbstractAdapter::createConnection('redis:?host['.str_replace(' ', ']&host[', $hosts).']', ['lazy' => true, 'redis_cluster' => true]);

src/Symfony/Component/Cache/Tests/Simple/AbstractRedisCacheTest.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111

1212
namespace Symfony\Component\Cache\Tests\Simple;
1313

14+
use PHPUnit\Framework\SkippedTestSuiteError;
1415
use Psr\SimpleCache\CacheInterface;
1516
use Symfony\Component\Cache\Simple\RedisCache;
1617

@@ -35,12 +36,12 @@ public function createSimpleCache(int $defaultLifetime = 0): CacheInterface
3536
public static function setUpBeforeClass(): void
3637
{
3738
if (!\extension_loaded('redis')) {
38-
self::markTestSkipped('Extension redis required.');
39+
throw new SkippedTestSuiteError('Extension redis required.');
3940
}
4041
try {
4142
(new \Redis())->connect(getenv('REDIS_HOST'));
4243
} catch (\Exception $e) {
43-
self::markTestSkipped($e->getMessage());
44+
throw new SkippedTestSuiteError($e->getMessage());
4445
}
4546
}
4647

src/Symfony/Component/Cache/Tests/Simple/MemcachedCacheTest.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111

1212
namespace Symfony\Component\Cache\Tests\Simple;
1313

14+
use PHPUnit\Framework\SkippedTestSuiteError;
1415
use Psr\SimpleCache\CacheInterface;
1516
use Symfony\Component\Cache\Adapter\AbstractAdapter;
1617
use Symfony\Component\Cache\Exception\CacheException;
@@ -33,14 +34,14 @@ class MemcachedCacheTest extends CacheTestCase
3334
public static function setUpBeforeClass(): void
3435
{
3536
if (!MemcachedCache::isSupported()) {
36-
self::markTestSkipped('Extension memcached >=2.2.0 required.');
37+
throw new SkippedTestSuiteError('Extension memcached >=2.2.0 required.');
3738
}
3839
self::$client = AbstractAdapter::createConnection('memcached://'.getenv('MEMCACHED_HOST'));
3940
self::$client->get('foo');
4041
$code = self::$client->getResultCode();
4142

4243
if (\Memcached::RES_SUCCESS !== $code && \Memcached::RES_NOTFOUND !== $code) {
43-
self::markTestSkipped('Memcached error: '.strtolower(self::$client->getResultMessage()));
44+
throw new SkippedTestSuiteError('Memcached error: '.strtolower(self::$client->getResultMessage()));
4445
}
4546
}
4647

0 commit comments

Comments
 (0)