Skip to content

Commit ebf2a83

Browse files
authored
[10.x] Test Improvements for HTTP tests (#50687)
Signed-off-by: Mior Muhammad Zaki <[email protected]>
1 parent 3d3063c commit ebf2a83

File tree

3 files changed

+14
-39
lines changed

3 files changed

+14
-39
lines changed

tests/Integration/Http/Middleware/HandleCorsTest.php

Lines changed: 10 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -13,23 +13,8 @@ class HandleCorsTest extends TestCase
1313
{
1414
use ValidatesRequests;
1515

16-
protected function getEnvironmentSetUp($app)
16+
protected function defineEnvironment($app)
1717
{
18-
$kernel = $app->make(Kernel::class);
19-
$kernel->prependMiddleware(HandleCors::class);
20-
21-
$router = $app['router'];
22-
23-
$this->addWebRoutes($router);
24-
$this->addApiRoutes($router);
25-
26-
parent::getEnvironmentSetUp($app);
27-
}
28-
29-
protected function resolveApplicationConfiguration($app)
30-
{
31-
parent::resolveApplicationConfiguration($app);
32-
3318
$app['config']['cors'] = [
3419
'paths' => ['api/*'],
3520
'supports_credentials' => false,
@@ -39,6 +24,15 @@ protected function resolveApplicationConfiguration($app)
3924
'exposed_headers' => [],
4025
'max_age' => 0,
4126
];
27+
28+
$kernel = $app->make(Kernel::class);
29+
$kernel->prependMiddleware(HandleCors::class);
30+
}
31+
32+
protected function defineRoutes($router)
33+
{
34+
$this->addWebRoutes($router);
35+
$this->addApiRoutes($router);
4236
}
4337

4438
public function testShouldReturnHeaderAssessControlAllowOriginWhenDontHaveHttpOriginOnRequest()

tests/Integration/Http/ThrottleRequestsTest.php

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -9,23 +9,13 @@
99
use Illuminate\Routing\Middleware\ThrottleRequests;
1010
use Illuminate\Support\Carbon;
1111
use Illuminate\Support\Facades\Route;
12+
use Orchestra\Testbench\Attributes\WithConfig;
1213
use Orchestra\Testbench\TestCase;
1314
use Throwable;
1415

16+
#[WithConfig('hashing.driver', 'bcrypt')]
1517
class ThrottleRequestsTest extends TestCase
1618
{
17-
protected function tearDown(): void
18-
{
19-
parent::tearDown();
20-
21-
Carbon::setTestNow(null);
22-
}
23-
24-
public function getEnvironmentSetUp($app)
25-
{
26-
$app['config']->set('hashing', ['driver' => 'bcrypt']);
27-
}
28-
2919
public function testLockOpensImmediatelyAfterDecay()
3020
{
3121
Carbon::setTestNow(Carbon::create(2018, 1, 1, 0, 0, 0));

tests/Integration/Http/ThrottleRequestsWithRedisTest.php

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -6,24 +6,15 @@
66
use Illuminate\Routing\Middleware\ThrottleRequestsWithRedis;
77
use Illuminate\Support\Carbon;
88
use Illuminate\Support\Facades\Route;
9+
use Orchestra\Testbench\Attributes\WithConfig;
910
use Orchestra\Testbench\TestCase;
1011
use Throwable;
1112

13+
#[WithConfig('hashing.driver', 'bcrypt')]
1214
class ThrottleRequestsWithRedisTest extends TestCase
1315
{
1416
use InteractsWithRedis;
1517

16-
protected function tearDown(): void
17-
{
18-
parent::tearDown();
19-
Carbon::setTestNow(null);
20-
}
21-
22-
public function getEnvironmentSetUp($app)
23-
{
24-
$app['config']->set('hashing', ['driver' => 'bcrypt']);
25-
}
26-
2718
public function testLockOpensImmediatelyAfterDecay()
2819
{
2920
$this->ifRedisAvailable(function () {

0 commit comments

Comments
 (0)