Skip to content

Commit 506de15

Browse files
authored
[8.x] Clean up test suite (#39406)
* Remove integration group * Remove other groups * Replace markTestSkipped with PHPUnit annotations * Fixes * fix * Replace OS check * wip
1 parent f7c9f2c commit 506de15

File tree

132 files changed

+87
-524
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

132 files changed

+87
-524
lines changed

src/Illuminate/Foundation/Testing/Concerns/InteractsWithRedis.php

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,6 @@ trait InteractsWithRedis
3030
*/
3131
public function setUpRedis()
3232
{
33-
$app = $this->app ?? new Application;
34-
$host = Env::get('REDIS_HOST', '127.0.0.1');
35-
$port = Env::get('REDIS_PORT', 6379);
36-
3733
if (! extension_loaded('redis')) {
3834
$this->markTestSkipped('The redis extension is not installed. Please install the extension to enable '.__CLASS__);
3935
}
@@ -42,6 +38,10 @@ public function setUpRedis()
4238
$this->markTestSkipped('Trying default host/port failed, please set environment variable REDIS_HOST & REDIS_PORT to enable '.__CLASS__);
4339
}
4440

41+
$app = $this->app ?? new Application;
42+
$host = Env::get('REDIS_HOST', '127.0.0.1');
43+
$port = Env::get('REDIS_PORT', 6379);
44+
4545
foreach ($this->redisDriverProvider() as $driver) {
4646
$this->redis[$driver[0]] = new RedisManager($app, $driver[0], [
4747
'cluster' => false,
@@ -63,6 +63,7 @@ public function setUpRedis()
6363
} catch (Exception $e) {
6464
if ($host === '127.0.0.1' && $port === 6379 && Env::get('REDIS_HOST') === null) {
6565
static::$connectionFailedOnceWithDefaultsSkip = true;
66+
6667
$this->markTestSkipped('Trying default host/port failed, please set environment variable REDIS_HOST & REDIS_PORT to enable '.__CLASS__);
6768
}
6869
}

tests/Cache/CacheMemcachedConnectorTest.php

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ class CacheMemcachedConnectorTest extends TestCase
1313
protected function tearDown(): void
1414
{
1515
m::close();
16+
17+
parent::tearDown();
1618
}
1719

1820
public function testServersAreAddedCorrectly()
@@ -46,12 +48,11 @@ public function testServersAreAddedCorrectlyWithPersistentConnection()
4648
$this->assertSame($result, $memcached);
4749
}
4850

51+
/**
52+
* @requires extension memcached
53+
*/
4954
public function testServersAreAddedCorrectlyWithValidOptions()
5055
{
51-
if (! class_exists('Memcached')) {
52-
$this->markTestSkipped('Memcached module not installed');
53-
}
54-
5556
$validOptions = [
5657
Memcached::OPT_NO_BLOCK => true,
5758
Memcached::OPT_CONNECT_TIMEOUT => 2000,
@@ -70,12 +71,11 @@ public function testServersAreAddedCorrectlyWithValidOptions()
7071
$this->assertSame($result, $memcached);
7172
}
7273

74+
/**
75+
* @requires extension memcached
76+
*/
7377
public function testServersAreAddedCorrectlyWithSaslCredentials()
7478
{
75-
if (! class_exists('Memcached')) {
76-
$this->markTestSkipped('Memcached module not installed');
77-
}
78-
7979
$saslCredentials = ['foo', 'bar'];
8080

8181
$memcached = $this->memcachedMockWithAddServer();

tests/Cache/CacheMemcachedStoreTest.php

Lines changed: 3 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@
99
use PHPUnit\Framework\TestCase;
1010
use stdClass;
1111

12+
/**
13+
* @requires extension memcached
14+
*/
1215
class CacheMemcachedStoreTest extends TestCase
1316
{
1417
protected function tearDown(): void
@@ -20,10 +23,6 @@ protected function tearDown(): void
2023

2124
public function testGetReturnsNullWhenNotFound()
2225
{
23-
if (! class_exists(Memcached::class)) {
24-
$this->markTestSkipped('Memcached module not installed');
25-
}
26-
2726
$memcache = $this->getMockBuilder(stdClass::class)->addMethods(['get', 'getResultCode'])->getMock();
2827
$memcache->expects($this->once())->method('get')->with($this->equalTo('foo:bar'))->willReturn(null);
2928
$memcache->expects($this->once())->method('getResultCode')->willReturn(1);
@@ -33,10 +32,6 @@ public function testGetReturnsNullWhenNotFound()
3332

3433
public function testMemcacheValueIsReturned()
3534
{
36-
if (! class_exists(Memcached::class)) {
37-
$this->markTestSkipped('Memcached module not installed');
38-
}
39-
4035
$memcache = $this->getMockBuilder(stdClass::class)->addMethods(['get', 'getResultCode'])->getMock();
4136
$memcache->expects($this->once())->method('get')->willReturn('bar');
4237
$memcache->expects($this->once())->method('getResultCode')->willReturn(0);
@@ -46,10 +41,6 @@ public function testMemcacheValueIsReturned()
4641

4742
public function testMemcacheGetMultiValuesAreReturnedWithCorrectKeys()
4843
{
49-
if (! class_exists(Memcached::class)) {
50-
$this->markTestSkipped('Memcached module not installed');
51-
}
52-
5344
$memcache = $this->getMockBuilder(stdClass::class)->addMethods(['getMulti', 'getResultCode'])->getMock();
5445
$memcache->expects($this->once())->method('getMulti')->with(
5546
['foo:foo', 'foo:bar', 'foo:baz']
@@ -69,10 +60,6 @@ public function testMemcacheGetMultiValuesAreReturnedWithCorrectKeys()
6960

7061
public function testSetMethodProperlyCallsMemcache()
7162
{
72-
if (! class_exists(Memcached::class)) {
73-
$this->markTestSkipped('Memcached module not installed');
74-
}
75-
7663
Carbon::setTestNow($now = Carbon::now());
7764
$memcache = $this->getMockBuilder(Memcached::class)->onlyMethods(['set'])->getMock();
7865
$memcache->expects($this->once())->method('set')->with($this->equalTo('foo'), $this->equalTo('bar'), $this->equalTo($now->timestamp + 60))->willReturn(true);
@@ -84,10 +71,6 @@ public function testSetMethodProperlyCallsMemcache()
8471

8572
public function testIncrementMethodProperlyCallsMemcache()
8673
{
87-
if (! class_exists(Memcached::class)) {
88-
$this->markTestSkipped('Memcached module not installed');
89-
}
90-
9174
/* @link https://github.com/php-memcached-dev/php-memcached/pull/468 */
9275
if (version_compare(phpversion(), '8.0.0', '>=')) {
9376
$this->markTestSkipped('Test broken due to parse error in PHP Memcached.');
@@ -102,10 +85,6 @@ public function testIncrementMethodProperlyCallsMemcache()
10285

10386
public function testDecrementMethodProperlyCallsMemcache()
10487
{
105-
if (! class_exists(Memcached::class)) {
106-
$this->markTestSkipped('Memcached module not installed');
107-
}
108-
10988
/* @link https://github.com/php-memcached-dev/php-memcached/pull/468 */
11089
if (version_compare(phpversion(), '8.0.0', '>=')) {
11190
$this->markTestSkipped('Test broken due to parse error in PHP Memcached.');
@@ -120,10 +99,6 @@ public function testDecrementMethodProperlyCallsMemcache()
12099

121100
public function testStoreItemForeverProperlyCallsMemcached()
122101
{
123-
if (! class_exists(Memcached::class)) {
124-
$this->markTestSkipped('Memcached module not installed');
125-
}
126-
127102
$memcache = $this->getMockBuilder(Memcached::class)->onlyMethods(['set'])->getMock();
128103
$memcache->expects($this->once())->method('set')->with($this->equalTo('foo'), $this->equalTo('bar'), $this->equalTo(0))->willReturn(true);
129104
$store = new MemcachedStore($memcache);
@@ -133,10 +108,6 @@ public function testStoreItemForeverProperlyCallsMemcached()
133108

134109
public function testForgetMethodProperlyCallsMemcache()
135110
{
136-
if (! class_exists(Memcached::class)) {
137-
$this->markTestSkipped('Memcached module not installed');
138-
}
139-
140111
$memcache = $this->getMockBuilder(Memcached::class)->onlyMethods(['delete'])->getMock();
141112
$memcache->expects($this->once())->method('delete')->with($this->equalTo('foo'));
142113
$store = new MemcachedStore($memcache);
@@ -145,10 +116,6 @@ public function testForgetMethodProperlyCallsMemcache()
145116

146117
public function testFlushesCached()
147118
{
148-
if (! class_exists(Memcached::class)) {
149-
$this->markTestSkipped('Memcached module not installed');
150-
}
151-
152119
$memcache = $this->getMockBuilder(Memcached::class)->onlyMethods(['flush'])->getMock();
153120
$memcache->expects($this->once())->method('flush')->willReturn(true);
154121
$store = new MemcachedStore($memcache);
@@ -158,10 +125,6 @@ public function testFlushesCached()
158125

159126
public function testGetAndSetPrefix()
160127
{
161-
if (! class_exists(Memcached::class)) {
162-
$this->markTestSkipped('Memcached module not installed');
163-
}
164-
165128
$store = new MemcachedStore(new Memcached, 'bar');
166129
$this->assertSame('bar:', $store->getPrefix());
167130
$store->setPrefix('foo');

tests/Console/Scheduling/EventTest.php

Lines changed: 14 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -12,36 +12,35 @@ class EventTest extends TestCase
1212
protected function tearDown(): void
1313
{
1414
m::close();
15+
16+
parent::tearDown();
1517
}
1618

19+
/**
20+
* @requires OS Linux|Darwin
21+
*/
1722
public function testBuildCommandUsingUnix()
1823
{
19-
if (windows_os()) {
20-
$this->markTestSkipped('Skipping since operating system is Windows');
21-
}
22-
2324
$event = new Event(m::mock(EventMutex::class), 'php -i');
2425

2526
$this->assertSame("php -i > '/dev/null' 2>&1", $event->buildCommand());
2627
}
2728

29+
/**
30+
* @requires OS Windows
31+
*/
2832
public function testBuildCommandUsingWindows()
2933
{
30-
if (! windows_os()) {
31-
$this->markTestSkipped('Skipping since operating system is not Windows');
32-
}
33-
3434
$event = new Event(m::mock(EventMutex::class), 'php -i');
3535

3636
$this->assertSame('php -i > "NUL" 2>&1', $event->buildCommand());
3737
}
3838

39+
/**
40+
* @requires OS Linux|Darwin
41+
*/
3942
public function testBuildCommandInBackgroundUsingUnix()
4043
{
41-
if (windows_os()) {
42-
$this->markTestSkipped('Skipping since operating system is Windows');
43-
}
44-
4544
$event = new Event(m::mock(EventMutex::class), 'php -i');
4645
$event->runInBackground();
4746

@@ -50,12 +49,11 @@ public function testBuildCommandInBackgroundUsingUnix()
5049
$this->assertSame("(php -i > '/dev/null' 2>&1 ; '".PHP_BINARY."' artisan schedule:finish {$scheduleId} \"$?\") > '/dev/null' 2>&1 &", $event->buildCommand());
5150
}
5251

52+
/**
53+
* @requires OS Windows
54+
*/
5355
public function testBuildCommandInBackgroundUsingWindows()
5456
{
55-
if (! windows_os()) {
56-
$this->markTestSkipped('Skipping since operating system is not Windows');
57-
}
58-
5957
$event = new Event(m::mock(EventMutex::class), 'php -i');
6058
$event->runInBackground();
6159

tests/Database/DatabaseConnectorTest.php

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -192,12 +192,11 @@ public function testSqlServerConnectCallsCreateConnectionWithOptionalArguments()
192192
$this->assertSame($result, $connection);
193193
}
194194

195+
/**
196+
* @requires extension odbc
197+
*/
195198
public function testSqlServerConnectCallsCreateConnectionWithPreferredODBC()
196199
{
197-
if (! in_array('odbc', PDO::getAvailableDrivers())) {
198-
$this->markTestSkipped('PHP was compiled without PDO ODBC support.');
199-
}
200-
201200
$config = ['odbc' => true, 'odbc_datasource_name' => 'server=localhost;database=test;'];
202201
$dsn = $this->getDsn($config);
203202
$connector = $this->getMockBuilder(SqlServerConnector::class)->onlyMethods(['createConnection', 'getOptions'])->getMock();

tests/Database/DatabaseEloquentHasOneOfManyTest.php

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,6 @@
88
use InvalidArgumentException;
99
use PHPUnit\Framework\TestCase;
1010

11-
/**
12-
* @group one-of-many
13-
*/
1411
class DatabaseEloquentHasOneOfManyTest extends TestCase
1512
{
1613
protected function setUp(): void

tests/Database/DatabaseEloquentMorphOneOfManyTest.php

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,6 @@
66
use Illuminate\Database\Eloquent\Model as Eloquent;
77
use PHPUnit\Framework\TestCase;
88

9-
/**
10-
* @group one-of-many
11-
*/
129
class DatabaseEloquentMorphOneOfManyTest extends TestCase
1310
{
1411
protected function setUp(): void

tests/Database/DatabaseSQLiteSchemaGrammarTest.php

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
namespace Illuminate\Tests\Database;
44

5-
use Doctrine\DBAL\Schema\SqliteSchemaManager;
65
use Illuminate\Database\Capsule\Manager;
76
use Illuminate\Database\Connection;
87
use Illuminate\Database\Schema\Blueprint;
@@ -98,10 +97,6 @@ public function testDropIndex()
9897

9998
public function testDropColumn()
10099
{
101-
if (! class_exists(SqliteSchemaManager::class)) {
102-
$this->markTestSkipped('Doctrine should be installed to run dropColumn tests');
103-
}
104-
105100
$db = new Manager;
106101

107102
$db->addConnection([
@@ -149,10 +144,6 @@ public function testRenameTable()
149144

150145
public function testRenameIndex()
151146
{
152-
if (! class_exists(SqliteSchemaManager::class)) {
153-
$this->markTestSkipped('Doctrine should be installed to run renameIndex tests');
154-
}
155-
156147
$db = new Manager;
157148

158149
$db->addConnection([

tests/Filesystem/FilesystemTest.php

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -99,12 +99,11 @@ public function testReplaceInFileCorrectlyReplaces()
9999
$this->assertStringEqualsFile($tempFile, 'Hello Taylor');
100100
}
101101

102+
/**
103+
* @requires OS Linux|Darwin
104+
*/
102105
public function testReplaceWhenUnixSymlinkExists()
103106
{
104-
if (windows_os()) {
105-
$this->markTestSkipped('The operating system is Windows');
106-
}
107-
108107
$tempFile = self::$tempDir.'/file.txt';
109108
$symlinkDir = self::$tempDir.'/symlink_dir';
110109
$symlink = "{$symlinkDir}/symlink.txt";
@@ -495,14 +494,10 @@ public function testMakeDirectory()
495494

496495
/**
497496
* @requires extension pcntl
498-
* @requires function pcntl_fork
497+
* @requires OS Linux|Darwin
499498
*/
500499
public function testSharedGet()
501500
{
502-
if (PHP_OS === 'Darwin') {
503-
$this->markTestSkipped('The operating system is MacOS.');
504-
}
505-
506501
$content = str_repeat('123456', 1000000);
507502
$result = 1;
508503

tests/Hashing/HasherTest.php

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,6 @@ public function testBasicBcryptHashing()
2323

2424
public function testBasicArgon2iHashing()
2525
{
26-
if (! defined('PASSWORD_ARGON2I')) {
27-
$this->markTestSkipped('PHP not compiled with Argon2i hashing support.');
28-
}
29-
3026
$hasher = new ArgonHasher;
3127
$value = $hasher->make('password');
3228
$this->assertNotSame('password', $value);
@@ -38,10 +34,6 @@ public function testBasicArgon2iHashing()
3834

3935
public function testBasicArgon2idHashing()
4036
{
41-
if (! defined('PASSWORD_ARGON2ID')) {
42-
$this->markTestSkipped('PHP not compiled with Argon2id hashing support.');
43-
}
44-
4537
$hasher = new Argon2IdHasher;
4638
$value = $hasher->make('password');
4739
$this->assertNotSame('password', $value);
@@ -58,10 +50,6 @@ public function testBasicBcryptVerification()
5850
{
5951
$this->expectException(RuntimeException::class);
6052

61-
if (! defined('PASSWORD_ARGON2I')) {
62-
$this->markTestSkipped('PHP not compiled with Argon2i hashing support.');
63-
}
64-
6553
$argonHasher = new ArgonHasher(['verify' => true]);
6654
$argonHashed = $argonHasher->make('password');
6755
(new BcryptHasher(['verify' => true]))->check('password', $argonHashed);

0 commit comments

Comments
 (0)