-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2 from swisnl/feature/http-client-macros
Add Laravel HTTP Client macros to consume JSON:API documents
- Loading branch information
Showing
3 changed files
with
106 additions
and
0 deletions.
There are no files selected for viewing
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Swis\JsonApi\Client\Tests\Providers; | ||
|
||
use Illuminate\Http\Client\Request; | ||
use Illuminate\Support\Facades\Http; | ||
use Swis\JsonApi\Client\Document; | ||
use Swis\JsonApi\Client\Tests\AbstractTest; | ||
|
||
class ServiceProviderTest extends AbstractTest | ||
{ | ||
protected function setUp(): void | ||
{ | ||
if (!class_exists(Http::class)) { | ||
$this->markTestSkipped('The Laravel HTTP Client is not available.'); | ||
} | ||
|
||
parent::setUp(); | ||
} | ||
|
||
/** | ||
* @test | ||
*/ | ||
public function itRegistersHttpFacadeMacroForRequest(): void | ||
{ | ||
// arrange | ||
Http::fake(); | ||
|
||
// act | ||
Http::asJsonApi()->get('https://example.com'); | ||
|
||
// assert | ||
Http::assertSent(static function (Request $request) { | ||
return $request->hasHeader('Content-Type', 'application/vnd.api+json') && | ||
$request->hasHeader('Accept', 'application/vnd.api+json'); | ||
}); | ||
} | ||
|
||
/** | ||
* @test | ||
*/ | ||
public function itRegistersHttpFacadeMacroForResponse(): void | ||
{ | ||
// arrange | ||
Http::fake(); | ||
|
||
// act | ||
$data = Http::get('https://example.com')->jsonApi(); | ||
|
||
// assert | ||
$this->assertInstanceOf(Document::class, $data); | ||
} | ||
} |