generated from spatie/package-skeleton-laravel
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
e1df1f0
commit ce688ab
Showing
8 changed files
with
116 additions
and
9 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
<?php | ||
|
||
// config for MorningTrain/LaravelEConomic | ||
return [ | ||
|
||
'app_secret_token' => env('ECONOMIC_APP_SECRET_TOKEN'), | ||
'agreement_grant_token' => env('ECONOMIC_AGREEMENT_GRANT_TOKEN'), | ||
]; |
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,45 @@ | ||
<?php | ||
|
||
namespace MorningTrain\LaravelEConomic\Drivers; | ||
|
||
use Illuminate\Support\Facades\Http; | ||
use MorningTrain\Economic\Classes\EconomicResponse; | ||
use MorningTrain\Economic\Interfaces\EconomicDriver; | ||
|
||
class HttpEconomicDriver implements EconomicDriver | ||
{ | ||
public function get(string $url, array $queryArgs = []): EconomicResponse | ||
{ | ||
$response = Http::economic()->get($url, $queryArgs); | ||
|
||
return new EconomicResponse($response->status(), $response->json()); | ||
} | ||
|
||
public function post(string $url, array $body = []): EconomicResponse | ||
{ | ||
$response = Http::economic()->post($url, $body); | ||
|
||
return new EconomicResponse($response->status(), $response->json()); | ||
} | ||
|
||
public function put(string $url, array $body = []): EconomicResponse | ||
{ | ||
$response = Http::economic()->put($url, $body); | ||
|
||
return new EconomicResponse($response->status(), $response->json()); | ||
} | ||
|
||
public function delete(string $url): EconomicResponse | ||
{ | ||
$response = Http::economic()->delete($url); | ||
|
||
return new EconomicResponse($response->status(), $response->json()); | ||
} | ||
|
||
public function patch(string $url): EconomicResponse | ||
{ | ||
$response = Http::economic()->patch($url); | ||
|
||
return new EconomicResponse($response->status(), $response->json()); | ||
} | ||
} |
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 was deleted.
Oops, something went wrong.
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 |
---|---|---|
@@ -1,5 +1,10 @@ | ||
<?php | ||
|
||
use Illuminate\Support\Facades\Http; | ||
use MorningTrain\LaravelEConomic\Tests\TestCase; | ||
|
||
uses(TestCase::class)->in(__DIR__); | ||
|
||
uses()->beforeEach(function() { | ||
Http::preventStrayRequests(); | ||
})->in(__DIR__); |
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,35 @@ | ||
<?php | ||
|
||
use Illuminate\Http\Client\Request; | ||
use Illuminate\Support\Facades\Http; | ||
use MorningTrain\Economic\Resources\Customer; | ||
|
||
it('adds headers from env', function () { | ||
Http::fake([ | ||
'*' => Http::response([]), | ||
]); | ||
|
||
Customer::first(); | ||
|
||
Http::assertSent(function (Request $request) { | ||
return $request->hasHeader('X-AppSecretToken', 'SECRET_TOKEN') | ||
&& $request->hasHeader('X-AgreementGrantToken', 'GRANT_TOKEN') | ||
&& $request->hasHeader('Content-Type'); | ||
}); | ||
}); | ||
|
||
it('sends request with filters', function () { | ||
Http::fake([ | ||
'https://restapi.e-conomic.com/customers*' => Http::response([]), | ||
]); | ||
|
||
Customer::where('name', 'Morningtrain')->first(); | ||
|
||
Http::assertSent(function (Request $request) { | ||
return $request->data() === [ | ||
'pageSize' => 1, | ||
'skipPages' => 0, | ||
'filter' => 'name$eq:Morningtrain', | ||
]; | ||
}); | ||
}); |