From 60465625b79f2491492ecf9511747706c82c2db1 Mon Sep 17 00:00:00 2001 From: philipp lang Date: Thu, 13 May 2021 23:25:00 +0200 Subject: [PATCH] Add fake backend --- src/Api.php | 8 +++--- src/Backend/Backend.php | 15 ++++++++++++ src/Backend/FakeBackend.php | 9 +++++++ src/Backend/LiveBackend.php | 13 ++++++++++ src/Concerns/NamiData.php | 11 --------- src/FakesNami.php | 27 +++++++++++++++++++++ src/{ => Providers}/NamiServiceProvider.php | 7 +++++- tests/TestCase.php | 2 +- 8 files changed, 75 insertions(+), 17 deletions(-) create mode 100644 src/Backend/Backend.php create mode 100644 src/Backend/FakeBackend.php create mode 100644 src/Backend/LiveBackend.php delete mode 100644 src/Concerns/NamiData.php create mode 100644 src/FakesNami.php rename src/{ => Providers}/NamiServiceProvider.php (68%) diff --git a/src/Api.php b/src/Api.php index 8ca60b7..598db63 100644 --- a/src/Api.php +++ b/src/Api.php @@ -8,9 +8,9 @@ use Illuminate\Support\Str; use App\Nami\Exceptions\TooManyLoginAttemptsException; use Illuminate\Support\Facades\Http; use Illuminate\Support\Collection; -use Zoomyboy\LaravelNami\Concerns\NamiData; +use Zoomyboy\LaravelNami\Backend\Backend; -class Api implements NamiData { +class Api { public $cookie; public $loggedIn = null; @@ -20,8 +20,8 @@ class Api implements NamiData { $this->cookie = new \GuzzleHttp\Cookie\CookieJar(); } - private function http() { - return Http::withOptions(['cookies' => $this->cookie]); + public function http() { + return Backend::cookie($this->cookie); } public function setUser(NamiUser $user) { diff --git a/src/Backend/Backend.php b/src/Backend/Backend.php new file mode 100644 index 0000000..7626678 --- /dev/null +++ b/src/Backend/Backend.php @@ -0,0 +1,15 @@ + $cookie]); + } + +} diff --git a/src/Concerns/NamiData.php b/src/Concerns/NamiData.php deleted file mode 100644 index 06e2c4a..0000000 --- a/src/Concerns/NamiData.php +++ /dev/null @@ -1,11 +0,0 @@ - $value) { + Assert::assertEquals($value, $existing[$key]); + } + } + +} diff --git a/src/NamiServiceProvider.php b/src/Providers/NamiServiceProvider.php similarity index 68% rename from src/NamiServiceProvider.php rename to src/Providers/NamiServiceProvider.php index 30626cc..e935f1f 100644 --- a/src/NamiServiceProvider.php +++ b/src/Providers/NamiServiceProvider.php @@ -1,10 +1,12 @@ app->singleton('nami.api', function() { return new Api(); }); + $this->app->bind('nami.backend', function() { + return new LiveBackend(); + }); } } diff --git a/tests/TestCase.php b/tests/TestCase.php index ddba1ef..a1f07a1 100644 --- a/tests/TestCase.php +++ b/tests/TestCase.php @@ -3,9 +3,9 @@ namespace Zoomyboy\LaravelNami\Tests; use Illuminate\Support\Facades\Config; -use Zoomyboy\LaravelNami\NamiServiceProvider; use Illuminate\Support\Facades\Http; use Zoomyboy\LaravelNami\Tests\Stub\Member; +use Zoomyboy\LaravelNami\Providers\NamiServiceProvider; class TestCase extends \Orchestra\Testbench\TestCase {