Created
January 31, 2024 09:27
-
-
Save ziadoz/286ea03b156f4c41ea6d1b5225f20a85 to your computer and use it in GitHub Desktop.
Laravel - Modify Route Controller for Testing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
namespace Tests; | |
use App\Controllers\MyController; | |
use Illuminate\Http\Response; | |
use Illuminate\Http\Request; | |
use Tests\TestCase; | |
class MyTest extends TestCase | |
{ | |
public function test_thing(): void | |
{ | |
// Make response slower deliberately for testing. | |
$this->app->bind(MyController::class, function () { | |
return new class extends MyController | |
{ | |
public function index(Request $request): Response | |
{ | |
sleep(5); | |
return parent::index($request); | |
} | |
}; | |
}); | |
// Test the controller... | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment