Fixed: Change cookie path in tests
This commit is contained in:
parent
63cef42385
commit
53f7537dbc
|
@ -4,4 +4,5 @@
|
||||||
*.swm
|
*.swm
|
||||||
tags
|
tags
|
||||||
.cookies
|
.cookies
|
||||||
|
.cookies_test
|
||||||
/.phpunit.result.cache
|
/.phpunit.result.cache
|
||||||
|
|
|
@ -9,5 +9,11 @@ abstract class Authenticator {
|
||||||
abstract public function login(int $mglnr, string $password): self;
|
abstract public function login(int $mglnr, string $password): self;
|
||||||
abstract public function http(): PendingRequest;
|
abstract public function http(): PendingRequest;
|
||||||
abstract public function isLoggedIn(): bool;
|
abstract public function isLoggedIn(): bool;
|
||||||
|
protected static $path = __DIR__.'/../../.cookies';
|
||||||
|
|
||||||
|
public static function setPath(string $path): void
|
||||||
|
{
|
||||||
|
static::$path = $path;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -10,7 +10,6 @@ use Zoomyboy\LaravelNami\LoginException;
|
||||||
|
|
||||||
class MainCookie extends Authenticator {
|
class MainCookie extends Authenticator {
|
||||||
|
|
||||||
private string $path = __DIR__.'/../../.cookies';
|
|
||||||
private FileCookieJar $cookie;
|
private FileCookieJar $cookie;
|
||||||
private string $url = 'https://nami.dpsg.de';
|
private string $url = 'https://nami.dpsg.de';
|
||||||
|
|
||||||
|
@ -59,7 +58,7 @@ class MainCookie extends Authenticator {
|
||||||
|
|
||||||
private function newFileName(): string
|
private function newFileName(): string
|
||||||
{
|
{
|
||||||
return $this->path.'/'.time().'.txt';
|
return parent::$path.'/'.time().'.txt';
|
||||||
}
|
}
|
||||||
|
|
||||||
private function isExpired(): bool
|
private function isExpired(): bool
|
||||||
|
@ -76,7 +75,7 @@ class MainCookie extends Authenticator {
|
||||||
*/
|
*/
|
||||||
private function file(): ?string
|
private function file(): ?string
|
||||||
{
|
{
|
||||||
$files = glob($this->path.'/*');
|
$files = glob(parent::$path.'/*');
|
||||||
|
|
||||||
if (!count($files)) {
|
if (!count($files)) {
|
||||||
return null;
|
return null;
|
||||||
|
|
|
@ -4,7 +4,9 @@ namespace Zoomyboy\LaravelNami\Tests;
|
||||||
|
|
||||||
use Illuminate\Support\Facades\Config;
|
use Illuminate\Support\Facades\Config;
|
||||||
use Illuminate\Support\Facades\Http;
|
use Illuminate\Support\Facades\Http;
|
||||||
|
use Illuminate\Support\Facades\Storage;
|
||||||
use Zoomyboy\LaravelNami\Api;
|
use Zoomyboy\LaravelNami\Api;
|
||||||
|
use Zoomyboy\LaravelNami\Authentication\Authenticator;
|
||||||
use Zoomyboy\LaravelNami\Cookies\Cookie;
|
use Zoomyboy\LaravelNami\Cookies\Cookie;
|
||||||
use Zoomyboy\LaravelNami\Cookies\FakeCookie;
|
use Zoomyboy\LaravelNami\Cookies\FakeCookie;
|
||||||
use Zoomyboy\LaravelNami\Nami;
|
use Zoomyboy\LaravelNami\Nami;
|
||||||
|
@ -17,7 +19,7 @@ class TestCase extends \Orchestra\Testbench\TestCase
|
||||||
public function setUp(): void {
|
public function setUp(): void {
|
||||||
parent::setUp();
|
parent::setUp();
|
||||||
|
|
||||||
$this->clearCookies();
|
$this->setupCookies();
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function getPackageProviders($app)
|
protected function getPackageProviders($app)
|
||||||
|
@ -37,14 +39,16 @@ class TestCase extends \Orchestra\Testbench\TestCase
|
||||||
|
|
||||||
public function login(): Api
|
public function login(): Api
|
||||||
{
|
{
|
||||||
touch (__DIR__.'/../.cookies/'.time().'.txt');
|
touch (__DIR__.'/../.cookies_test/'.time().'.txt');
|
||||||
|
|
||||||
return Nami::login(123, 'secret');
|
return Nami::login(123, 'secret');
|
||||||
}
|
}
|
||||||
|
|
||||||
private function clearCookies(): void
|
private function setupCookies(): void
|
||||||
{
|
{
|
||||||
foreach (glob(__DIR__.'/../.cookies/*') as $file) {
|
Authenticator::setPath(__DIR__.'/../.cookies_test');
|
||||||
|
|
||||||
|
foreach (glob(__DIR__.'/../.cookies_test/*') as $file) {
|
||||||
unlink($file);
|
unlink($file);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -57,12 +57,12 @@ class LoginTest extends TestCase
|
||||||
|
|
||||||
Nami::login(12345, 'secret');
|
Nami::login(12345, 'secret');
|
||||||
|
|
||||||
$this->assertFileExists(__DIR__.'/../../.cookies/'.time().'.txt');
|
$this->assertFileExists(__DIR__.'/../../.cookies_test/'.time().'.txt');
|
||||||
}
|
}
|
||||||
|
|
||||||
public function test_dont_login_if_cookie_exists(): void
|
public function test_dont_login_if_cookie_exists(): void
|
||||||
{
|
{
|
||||||
touch(__DIR__.'/../../.cookies/'.time().'.txt');
|
touch(__DIR__.'/../../.cookies_test/'.time().'.txt');
|
||||||
|
|
||||||
Nami::login(12345, 'secret');
|
Nami::login(12345, 'secret');
|
||||||
|
|
||||||
|
@ -72,19 +72,19 @@ class LoginTest extends TestCase
|
||||||
public function test_delete_expired_cookie_before_login(): void
|
public function test_delete_expired_cookie_before_login(): void
|
||||||
{
|
{
|
||||||
$lastLogin = now()->subHours(2)->timestamp;
|
$lastLogin = now()->subHours(2)->timestamp;
|
||||||
touch(__DIR__."/../../.cookies/{$lastLogin}.txt");
|
touch(__DIR__."/../../.cookies_test/{$lastLogin}.txt");
|
||||||
Http::fake($this->fakeSuccessfulLogin());
|
Http::fake($this->fakeSuccessfulLogin());
|
||||||
|
|
||||||
Nami::login(12345, 'secret');
|
Nami::login(12345, 'secret');
|
||||||
|
|
||||||
Http::assertSentCount(2);
|
Http::assertSentCount(2);
|
||||||
$this->assertFileDoesNotExist(__DIR__."/../../.cookies/{$lastLogin}.txt");
|
$this->assertFileDoesNotExist(__DIR__."/../../.cookies_test/{$lastLogin}.txt");
|
||||||
}
|
}
|
||||||
|
|
||||||
public function test_login_once_if_cookie_is_expired(): void
|
public function test_login_once_if_cookie_is_expired(): void
|
||||||
{
|
{
|
||||||
$lastLogin = now()->subHour()->subMinutes(10)->timestamp;
|
$lastLogin = now()->subHour()->subMinutes(10)->timestamp;
|
||||||
touch(__DIR__."/../../.cookies/{$lastLogin}.txt");
|
touch(__DIR__."/../../.cookies_test/{$lastLogin}.txt");
|
||||||
Http::fake($this->fakeSuccessfulLogin());
|
Http::fake($this->fakeSuccessfulLogin());
|
||||||
|
|
||||||
Nami::login(12345, 'secret');
|
Nami::login(12345, 'secret');
|
||||||
|
|
Loading…
Reference in New Issue