2020-06-27 23:45:49 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace Zoomyboy\LaravelNami\Tests;
|
|
|
|
|
2022-02-18 18:29:02 +01:00
|
|
|
use Zoomyboy\LaravelNami\Api;
|
2022-03-05 20:22:09 +01:00
|
|
|
use Zoomyboy\LaravelNami\Authentication\Auth;
|
2022-02-19 18:41:51 +01:00
|
|
|
use Zoomyboy\LaravelNami\Authentication\Authenticator;
|
2022-02-18 18:29:02 +01:00
|
|
|
use Zoomyboy\LaravelNami\Nami;
|
2022-02-10 23:19:31 +01:00
|
|
|
use Zoomyboy\LaravelNami\Providers\NamiServiceProvider;
|
2020-06-28 00:25:41 +02:00
|
|
|
|
2020-06-27 23:45:49 +02:00
|
|
|
class TestCase extends \Orchestra\Testbench\TestCase
|
|
|
|
{
|
2022-03-11 20:20:00 +01:00
|
|
|
public function setUp(): void
|
|
|
|
{
|
2021-06-21 22:37:23 +02:00
|
|
|
parent::setUp();
|
|
|
|
|
2022-02-19 18:41:51 +01:00
|
|
|
$this->setupCookies();
|
2021-06-21 22:37:23 +02:00
|
|
|
}
|
|
|
|
|
2020-06-28 00:25:41 +02:00
|
|
|
protected function getPackageProviders($app)
|
|
|
|
{
|
2022-03-11 20:20:00 +01:00
|
|
|
return [NamiServiceProvider::class];
|
2020-06-28 00:25:41 +02:00
|
|
|
}
|
|
|
|
|
2022-03-11 20:20:00 +01:00
|
|
|
public function getAnnotations(): array
|
|
|
|
{
|
2021-06-18 23:36:22 +02:00
|
|
|
return [];
|
|
|
|
}
|
|
|
|
|
2022-03-11 20:20:00 +01:00
|
|
|
public function fakeJson(string $file, array $data = []): string
|
|
|
|
{
|
2022-02-10 23:19:31 +01:00
|
|
|
ob_start();
|
2022-03-11 20:20:00 +01:00
|
|
|
include __DIR__.'/json/'.$file;
|
|
|
|
|
2022-02-10 23:19:31 +01:00
|
|
|
return ob_get_clean();
|
2020-06-29 00:30:57 +02:00
|
|
|
}
|
|
|
|
|
2022-02-18 18:29:02 +01:00
|
|
|
public function login(): Api
|
|
|
|
{
|
2022-03-05 20:22:09 +01:00
|
|
|
Auth::fake();
|
|
|
|
Auth::success(12345, 'secret');
|
2022-02-18 18:29:02 +01:00
|
|
|
|
2022-03-05 20:22:09 +01:00
|
|
|
return Nami::login(12345, 'secret');
|
|
|
|
}
|
|
|
|
|
|
|
|
public function loginWithWrongCredentials(): Api
|
|
|
|
{
|
|
|
|
Auth::fake();
|
2022-09-01 23:11:21 +02:00
|
|
|
Auth::fails(12345, 'wrong');
|
2022-03-05 20:22:09 +01:00
|
|
|
|
|
|
|
return Nami::login(12345, 'wrong');
|
2020-06-29 23:12:16 +02:00
|
|
|
}
|
|
|
|
|
2022-02-20 00:28:18 +01:00
|
|
|
protected function clearCookies(): void
|
2022-02-18 17:56:04 +01:00
|
|
|
{
|
2022-02-19 18:41:51 +01:00
|
|
|
foreach (glob(__DIR__.'/../.cookies_test/*') as $file) {
|
2022-02-18 17:56:04 +01:00
|
|
|
unlink($file);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-02-20 00:28:18 +01:00
|
|
|
private function setupCookies(): void
|
|
|
|
{
|
|
|
|
Authenticator::setPath(__DIR__.'/../.cookies_test');
|
|
|
|
$this->clearCookies();
|
|
|
|
}
|
2020-06-27 23:45:49 +02:00
|
|
|
}
|