Created
November 29, 2023 10:30
-
-
Save DominikStyp/ee2fbc2c660c4094bca287bb59eade42 to your computer and use it in GitHub Desktop.
Mock HTTP Request, and custom facade in Laravel test (PHPUnit)
This file contains 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\Feature; | |
use Symfony\Component\HttpFoundation\Request; | |
use Tests\TestCase; | |
class BrandResolveByMultipleDomainsTest extends TestCase | |
{ | |
private function mockRequest(string $domain): void | |
{ | |
$this->app->bind('request', function () use ($domain) { | |
$request = new \Illuminate\Http\Request; | |
return $request->createFromBase( | |
Request::create( | |
'/login', | |
'GET', | |
[], | |
[], | |
[], | |
[ | |
'HTTP_HOST' => $domain, | |
'SERVER_NAME' => $domain, | |
'SERVER_PORT' => '80', | |
'SERVER_ADDR' => '127.0.0.1' | |
] | |
) | |
); | |
}); | |
} | |
private function mockFacade() : void | |
{ | |
$object = new \stdClass(); | |
\SomeCustomFacade::partialMock() | |
->shouldReceive('someMethod') | |
->andReturn($object); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment