Skip to content

Instantly share code, notes, and snippets.

@DominikStyp
Created November 29, 2023 10:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save DominikStyp/ee2fbc2c660c4094bca287bb59eade42 to your computer and use it in GitHub Desktop.
Save DominikStyp/ee2fbc2c660c4094bca287bb59eade42 to your computer and use it in GitHub Desktop.
Mock HTTP Request, and custom facade in Laravel test (PHPUnit)
<?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