Skip to content

Commit 8448fa2

Browse files
authored
[12.x] Test Improvements (#55307)
* [12.x] Test Improvements fixes risky tests Signed-off-by: Mior Muhammad Zaki <[email protected]> * wip Signed-off-by: Mior Muhammad Zaki <[email protected]> --------- Signed-off-by: Mior Muhammad Zaki <[email protected]>
1 parent 906295d commit 8448fa2

File tree

4 files changed

+33
-25
lines changed

4 files changed

+33
-25
lines changed

tests/Database/DatabaseEloquentCollectionTest.php

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@
1414
use PHPUnit\Framework\TestCase;
1515
use stdClass;
1616

17+
use function Orchestra\Testbench\phpunit_version_compare;
18+
1719
class DatabaseEloquentCollectionTest extends TestCase
1820
{
1921
/**
@@ -702,7 +704,12 @@ public function testLoadExistsShouldCastBool()
702704
$user = EloquentTestUserModel::with('articles')->first();
703705
$user->articles->loadExists('comments');
704706
$commentsExists = $user->articles->pluck('comments_exists')->toArray();
705-
$this->assertContainsOnly('bool', $commentsExists);
707+
708+
if (phpunit_version_compare('11.5.0', '<')) {
709+
$this->assertContainsOnly('bool', $commentsExists);
710+
} else {
711+
$this->assertContainsOnlyBool($commentsExists);
712+
}
706713
}
707714

708715
public function testWithNonScalarKey()

tests/Integration/Cache/Psr6RedisTest.php

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -14,16 +14,15 @@ class Psr6RedisTest extends TestCase
1414

1515
protected function setUp(): void
1616
{
17-
parent::setUp();
17+
$this->afterApplicationCreated(function () {
18+
$this->setUpRedis();
19+
});
1820

19-
$this->setUpRedis();
20-
}
21+
$this->beforeApplicationDestroyed(function () {
22+
$this->tearDownRedis();
23+
});
2124

22-
protected function tearDown(): void
23-
{
24-
$this->tearDownRedis();
25-
26-
parent::tearDown();
25+
parent::setUp();
2726
}
2827

2928
#[DataProvider('redisClientDataProvider')]

tests/Integration/Cache/RedisStoreTest.php

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -16,18 +16,19 @@ class RedisStoreTest extends TestCase
1616
{
1717
use InteractsWithRedis;
1818

19+
/** {@inheritdoc} */
20+
#[\Override]
1921
protected function setUp(): void
2022
{
21-
parent::setUp();
23+
$this->afterApplicationCreated(function () {
24+
$this->setUpRedis();
25+
});
2226

23-
$this->setUpRedis();
24-
}
27+
$this->beforeApplicationDestroyed(function () {
28+
$this->tearDownRedis();
29+
});
2530

26-
protected function tearDown(): void
27-
{
28-
$this->tearDownRedis();
29-
30-
parent::tearDown();
31+
parent::setUp();
3132
}
3233

3334
public function testCacheTtl(): void

tests/Integration/Queue/RedisQueueTest.php

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -31,18 +31,19 @@ class RedisQueueTest extends TestCase
3131
*/
3232
private $container;
3333

34+
/** {@inheritdoc} */
35+
#[\Override]
3436
protected function setUp(): void
3537
{
36-
parent::setUp();
37-
38-
$this->setUpRedis();
39-
}
38+
$this->afterApplicationCreated(function () {
39+
$this->setUpRedis();
40+
});
4041

41-
protected function tearDown(): void
42-
{
43-
$this->tearDownRedis();
42+
$this->beforeApplicationDestroyed(function () {
43+
$this->tearDownRedis();
44+
});
4445

45-
parent::tearDown();
46+
parent::setUp();
4647
}
4748

4849
/**

0 commit comments

Comments
 (0)