Add fake backend
This commit is contained in:
parent
cb97b8f1a9
commit
60465625b7
|
@ -8,9 +8,9 @@ use Illuminate\Support\Str;
|
||||||
use App\Nami\Exceptions\TooManyLoginAttemptsException;
|
use App\Nami\Exceptions\TooManyLoginAttemptsException;
|
||||||
use Illuminate\Support\Facades\Http;
|
use Illuminate\Support\Facades\Http;
|
||||||
use Illuminate\Support\Collection;
|
use Illuminate\Support\Collection;
|
||||||
use Zoomyboy\LaravelNami\Concerns\NamiData;
|
use Zoomyboy\LaravelNami\Backend\Backend;
|
||||||
|
|
||||||
class Api implements NamiData {
|
class Api {
|
||||||
|
|
||||||
public $cookie;
|
public $cookie;
|
||||||
public $loggedIn = null;
|
public $loggedIn = null;
|
||||||
|
@ -20,8 +20,8 @@ class Api implements NamiData {
|
||||||
$this->cookie = new \GuzzleHttp\Cookie\CookieJar();
|
$this->cookie = new \GuzzleHttp\Cookie\CookieJar();
|
||||||
}
|
}
|
||||||
|
|
||||||
private function http() {
|
public function http() {
|
||||||
return Http::withOptions(['cookies' => $this->cookie]);
|
return Backend::cookie($this->cookie);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function setUser(NamiUser $user) {
|
public function setUser(NamiUser $user) {
|
||||||
|
|
|
@ -0,0 +1,15 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Zoomyboy\LaravelNami\Backend;
|
||||||
|
|
||||||
|
use Illuminate\Support\Facades\Facade;
|
||||||
|
|
||||||
|
class Backend extends Facade {
|
||||||
|
protected static function getFacadeAccessor() { return 'nami.backend'; }
|
||||||
|
|
||||||
|
public static function fake() {
|
||||||
|
static::swap($api = new FakeBackend());
|
||||||
|
|
||||||
|
return $api;
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,9 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Zoomyboy\LaravelNami\Backend;
|
||||||
|
|
||||||
|
class FakeBackend {
|
||||||
|
|
||||||
|
private $members;
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,13 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Zoomyboy\LaravelNami\Backend;
|
||||||
|
|
||||||
|
use Illuminate\Support\Facades\Http;
|
||||||
|
|
||||||
|
class LiveBackend {
|
||||||
|
|
||||||
|
public static function cookie($cookie) {
|
||||||
|
return Http::withOptions(['cookies' => $cookie]);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -1,11 +0,0 @@
|
||||||
<?php
|
|
||||||
|
|
||||||
namespace Zoomyboy\LaravelNami\Concerns;
|
|
||||||
|
|
||||||
use Illuminate\Support\Collection;
|
|
||||||
|
|
||||||
interface NamiData {
|
|
||||||
|
|
||||||
public function nationalities(): Collection;
|
|
||||||
|
|
||||||
}
|
|
|
@ -0,0 +1,27 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Zoomyboy\LaravelNami;
|
||||||
|
|
||||||
|
use PHPUnit\Framework\Assert;
|
||||||
|
|
||||||
|
trait FakesNami {
|
||||||
|
|
||||||
|
public function fakeNami() {
|
||||||
|
Nami::fake();
|
||||||
|
}
|
||||||
|
|
||||||
|
public function fakeNamiMembers($members) {
|
||||||
|
foreach ($members as $member) {
|
||||||
|
Nami::addMember($member);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public function assertMemberExists($groupId, $data) {
|
||||||
|
Assert::assertNotNull($existing = Nami::member($groupId, $data['id']));
|
||||||
|
|
||||||
|
foreach ($data as $key => $value) {
|
||||||
|
Assert::assertEquals($value, $existing[$key]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -1,10 +1,12 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
namespace Zoomyboy\LaravelNami;
|
namespace Zoomyboy\LaravelNami\Providers;
|
||||||
|
|
||||||
use Illuminate\Support\Facades\Auth;
|
use Illuminate\Support\Facades\Auth;
|
||||||
use GuzzleHttp\Client as GuzzleClient;
|
use GuzzleHttp\Client as GuzzleClient;
|
||||||
use Illuminate\Support\ServiceProvider;
|
use Illuminate\Support\ServiceProvider;
|
||||||
|
use Zoomyboy\LaravelNami\Backend\LiveBackend;
|
||||||
|
use Zoomyboy\LaravelNami\Api;
|
||||||
|
|
||||||
class NamiServiceProvider extends ServiceProvider
|
class NamiServiceProvider extends ServiceProvider
|
||||||
{
|
{
|
||||||
|
@ -19,5 +21,8 @@ class NamiServiceProvider extends ServiceProvider
|
||||||
$this->app->singleton('nami.api', function() {
|
$this->app->singleton('nami.api', function() {
|
||||||
return new Api();
|
return new Api();
|
||||||
});
|
});
|
||||||
|
$this->app->bind('nami.backend', function() {
|
||||||
|
return new LiveBackend();
|
||||||
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -3,9 +3,9 @@
|
||||||
namespace Zoomyboy\LaravelNami\Tests;
|
namespace Zoomyboy\LaravelNami\Tests;
|
||||||
|
|
||||||
use Illuminate\Support\Facades\Config;
|
use Illuminate\Support\Facades\Config;
|
||||||
use Zoomyboy\LaravelNami\NamiServiceProvider;
|
|
||||||
use Illuminate\Support\Facades\Http;
|
use Illuminate\Support\Facades\Http;
|
||||||
use Zoomyboy\LaravelNami\Tests\Stub\Member;
|
use Zoomyboy\LaravelNami\Tests\Stub\Member;
|
||||||
|
use Zoomyboy\LaravelNami\Providers\NamiServiceProvider;
|
||||||
|
|
||||||
class TestCase extends \Orchestra\Testbench\TestCase
|
class TestCase extends \Orchestra\Testbench\TestCase
|
||||||
{
|
{
|
||||||
|
|
Loading…
Reference in New Issue