succeeds('lala-testsession'); app(MainCookie::class)->login('12345', 'secret'); Http::assertSentCount(1); $cookie = file_get_contents(__DIR__ . '/../../.cookies_test/12345_' . now()->timestamp . '.txt'); $this->assertEquals('lala-testsession.srv-nami06', $cookie); app(LoginFake::class)->assertSent('12345', 'secret'); } public function testItThrowsExceptionWhenLoginFails(): void { app(LoginFake::class)->fails('::token::'); $this->expectException(LoginException::class); app(MainCookie::class)->login('12345', 'secret'); } public function testItDoesntSaveCookieWhenLoginFails(): void { app(LoginFake::class)->fails('::token::'); try { app(MainCookie::class)->login('12345', 'secret'); } catch (LoginException $e) { } Http::assertSentCount(1); $this->assertEmpty(glob(__DIR__ . '/../../.cookies_test/*')); } public function testItDoesntResetCookieWhenAlreadyLoggedIn(): void { app(CourseFake::class)->fetches(103, []); file_put_contents(__DIR__ . '/../../.cookies_test/90100_' . now()->subMinutes(5)->timestamp . '.txt', 'cook-testsession.srv-nami06'); Nami::login('90100', 'secret'); Http::assertSentCount(0); $this->assertFileExists(__DIR__ . '/../../.cookies_test/90100_' . now()->subMinutes(5)->timestamp . '.txt'); $this->assertCount(1, glob(__DIR__ . '/../../.cookies_test/*')); } public function testItIgnoresExpiredCookie(): void { app(CourseFake::class)->fetches(103, []); app(LoginFake::class)->succeeds('newlogin'); file_put_contents(__DIR__ . '/../../.cookies_test/90100_' . now()->subHour()->timestamp . '.txt', 'oldlogin-testsession.srv-nami06'); Nami::login('90100', 'secret'); Http::assertSentCount(1); $cookie = file_get_contents(__DIR__ . '/../../.cookies_test/90100_' . now()->timestamp . '.txt'); $this->assertEquals('newlogin.srv-nami06', $cookie); $this->assertFileExists(__DIR__ . '/../../.cookies_test/90100_' . now()->timestamp . '.txt'); $this->assertCount(1, glob(__DIR__ . '/../../.cookies_test/*')); } public function testItDoesntUseOtherCookieForLogin(): void { app(CourseFake::class)->fetches(103, []); app(LoginFake::class)->succeeds('newlogin'); file_put_contents(__DIR__ . '/../../.cookies_test/11111_' . now()->timestamp . '.txt', 'oldlogin-testsession.srv-nami06'); app(Authenticator::class)->login('12345', 'secret'); app(LoginFake::class)->assertSent('12345', 'secret'); $this->assertFileExists(__DIR__ . '/../../.cookies_test/11111_' . now()->timestamp . '.txt'); $this->assertFileExists(__DIR__ . '/../../.cookies_test/12345_' . now()->timestamp . '.txt'); } public function testItRefreshesLogin(): void { app(LoginFake::class)->succeeds('newlogin'); $auth = app(Authenticator::class)->login('12345', 'secret'); rename( __DIR__ . '/../../.cookies_test/12345_' . now()->timestamp . '.txt', __DIR__ . '/../../.cookies_test/12345_' . now()->subMinutes(51)->timestamp . '.txt' ); $auth->refresh(); Http::assertSentCount(2); } }