Fix: mglnr should be a string

This commit is contained in:
philipp lang 2025-07-09 00:52:52 +02:00
parent 35bed01848
commit 47f01b3c3c
11 changed files with 45 additions and 45 deletions

View File

@ -128,14 +128,14 @@ class Api
}
}
public function login(int $mglnr, string $password): self
public function login(string $mglnr, string $password): self
{
$this->authenticator->login($mglnr, $password);
return $this;
}
public function freshLogin(int $mglnr, string $password): self
public function freshLogin(string $mglnr, string $password): self
{
$this->authenticator->purge($mglnr);

View File

@ -6,10 +6,10 @@ use Illuminate\Support\Facades\Facade;
/**
* @method static void assertNotLoggedIn()
* @method static void success(int $mglnr, string $password)
* @method static void fails(int $mglnr, string $password)
* @method static void assertLoggedInWith(int $mglnr, string $password)
* @method static void assertNotLoggedInWith(int $mglnr, string $password)
* @method static void success(string $mglnr, string $password)
* @method static void fails(string $mglnr, string $password)
* @method static void assertLoggedInWith(string $mglnr, string $password)
* @method static void assertNotLoggedInWith(string $mglnr, string $password)
* @method static void assertLoggedIn()
*/
class Auth extends Facade

View File

@ -8,9 +8,9 @@ abstract class Authenticator
{
protected static string $path = __DIR__ . '/../../.cookies';
abstract public function login(int $mglnr, string $password): self;
abstract public function login(string $mglnr, string $password): self;
abstract public function purge(int $mglnr): void;
abstract public function purge(string $mglnr): void;
abstract public function http(): PendingRequest;

View File

@ -8,7 +8,7 @@ use PHPUnit\Framework\Assert;
use Zoomyboy\LaravelNami\LoginException;
/**
* @template Account of array{mglnr: int, password: string}
* @template Account of array{mglnr: string, password: string}
*/
class FakeCookie extends Authenticator
{
@ -20,7 +20,7 @@ class FakeCookie extends Authenticator
/**
* @return self<Account>
*/
public function login(int $mglnr, string $password): self
public function login(string $mglnr, string $password): self
{
$authenticated = collect($this->validAccounts)->search(
fn ($account) => $account['mglnr'] === $mglnr && $account['password'] === $password
@ -52,18 +52,18 @@ class FakeCookie extends Authenticator
* Reisters an account that can successfully login with
* the given password.
*/
public function success(int $mglnr, string $password): void
public function success(string $mglnr, string $password): void
{
$this->validAccounts[] = ['mglnr' => $mglnr, 'password' => $password];
}
public function assertLoggedInWith(int $mglnr, string $password): void
public function assertLoggedInWith(string $mglnr, string $password): void
{
Assert::assertSame($mglnr, data_get($this->authenticated, 'mglnr'));
Assert::assertSame($password, data_get($this->authenticated, 'password'));
}
public function assertNotLoggedInWith(int $mglnr, string $password): void
public function assertNotLoggedInWith(string $mglnr, string $password): void
{
Assert::assertTrue(
$mglnr !== data_get($this->authenticated, 'mglnr')
@ -72,7 +72,7 @@ class FakeCookie extends Authenticator
);
}
public function purge(int $mglnr): void
public function purge(string $mglnr): void
{
}

View File

@ -12,10 +12,10 @@ class MainCookie extends Authenticator
{
private CookieJar $cookie;
private string $url = 'https://nami.dpsg.de';
private int $mglnr;
private string $mglnr;
private string $password;
public function login(int $mglnr, string $password): self
public function login(string $mglnr, string $password): self
{
$this->mglnr = $mglnr;
$this->password = $password;
@ -46,7 +46,7 @@ class MainCookie extends Authenticator
return $this;
}
public function purge(int $mglnr): void
public function purge(string $mglnr): void
{
$this->mglnr = $mglnr;
while ($this->file()) {

View File

@ -39,7 +39,7 @@ class LoginFake extends Fake
});
}
public function assertSent(int $mglnr, string $password): void
public function assertSent(string $mglnr, string $password): void
{
Http::assertSent(function ($request) use ($mglnr, $password) {
return $request->url() === 'https://nami.dpsg.de/ica/rest/nami/auth/manual/sessionStartup'

View File

@ -5,7 +5,7 @@ namespace Zoomyboy\LaravelNami;
use Illuminate\Support\Facades\Facade;
/**
* @method static \Zoomyboy\LaravelNami\Api login(int $mglnr, string $password)
* @method static \Zoomyboy\LaravelNami\Api login(string $mglnr, string $password)
* @method static bool isLoggedIn()
* @method static \Zoomyboy\LaravelNami\Api fake()
*/

View File

@ -40,16 +40,16 @@ class TestCase extends \Orchestra\Testbench\TestCase
public function login(): Api
{
Auth::fake();
Auth::success(12345, 'secret');
Auth::success('12345', 'secret');
return Nami::login(12345, 'secret');
return Nami::login('12345', 'secret');
}
public function loginWithWrongCredentials(): Api
{
Auth::fake();
return Nami::login(12345, 'wrong');
return Nami::login('12345', 'wrong');
}
protected function clearCookies(): void

View File

@ -19,10 +19,10 @@ class BausteinTest extends TestCase
public function testGetAllCourses(): void
{
Auth::success(12345, 'secret');
Auth::success('12345', 'secret');
app(BausteinFake::class)->fetches([['id' => 788, 'descriptor' => 'abc']]);
$courses = Nami::login(12345, 'secret')->courses();
$courses = Nami::login('12345', 'secret')->courses();
$this->assertCount(1, $courses);
@ -33,9 +33,9 @@ class BausteinTest extends TestCase
public function testThrowExceptionWhenBausteinFetchingFails(): void
{
$this->expectException(NotSuccessfulException::class);
Auth::success(12345, 'secret');
Auth::success('12345', 'secret');
app(BausteinFake::class)->failsToFetch();
Nami::login(12345, 'secret')->courses();
Nami::login('12345', 'secret')->courses();
}
}

View File

@ -22,12 +22,12 @@ class GroupsTest extends TestCase
public function testGetGroups(): void
{
Auth::success(12345, 'secret');
Auth::success('12345', 'secret');
app(GroupFake::class)->fetches(null, [
1234 => ['name' => 'testgroup'],
]);
$group = Nami::login(12345, 'secret')->group(1234);
$group = Nami::login('12345', 'secret')->group(1234);
$this->assertInstanceOf(Group::class, $group);
$this->assertEquals('testgroup', $group->name);
@ -39,14 +39,14 @@ class GroupsTest extends TestCase
public function testGetSubgroups(): void
{
Auth::success(12345, 'secret');
Auth::success('12345', 'secret');
app(GroupFake::class)->fetches(null, [
1234 => ['name' => 'testgroup'],
])->fetches(1234, [
555 => ['name' => 'ABC'],
]);
$group = Nami::login(12345, 'secret')->groups(Group::from(['id' => 1234, 'name' => 'lorem', 'parentId' => null]))->first();
$group = Nami::login('12345', 'secret')->groups(Group::from(['id' => 1234, 'name' => 'lorem', 'parentId' => null]))->first();
$this->assertEquals('ABC', $group->name);
$this->assertEquals(555, $group->id);
@ -64,30 +64,30 @@ class GroupsTest extends TestCase
public function testThrowsExceptionWhenGroupFetchFailed(): void
{
$this->expectException(NotSuccessfulException::class);
Auth::success(12345, 'secret');
Auth::success('12345', 'secret');
app(GroupFake::class)->failsToFetch(null);
Nami::login(12345, 'secret')->group(1234);
Nami::login('12345', 'secret')->group(1234);
}
public function testThrowsExceptionWhenSubgroupFetchFailed(): void
{
$this->expectException(NotSuccessfulException::class);
Auth::success(12345, 'secret');
Auth::success('12345', 'secret');
app(GroupFake::class)->fetches(null, [
1234 => ['name' => 'testgroup'],
]);
app(GroupFake::class)->failsToFetch(1234);
Nami::login(12345, 'secret')->groups(Group::from(['id' => 1234, 'name' => 'lorem', 'parentId' => null]));
Nami::login('12345', 'secret')->groups(Group::from(['id' => 1234, 'name' => 'lorem', 'parentId' => null]));
}
public function testItDoesntReturnGroupWhenNoJsonIsReturned(): void
{
$this->expectException(NoJsonReceivedException::class);
Auth::success(12345, 'secret');
Auth::success('12345', 'secret');
app(GroupFake::class)->failsToFetchWithoutJson(null);
Nami::login(12345, 'secret')->group(1234);
Nami::login('12345', 'secret')->group(1234);
}
}

View File

@ -24,19 +24,19 @@ class LoginTest extends TestCase
{
app(LoginFake::class)->succeeds('lala-testsession');
app(MainCookie::class)->login(12345, 'secret');
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');
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');
app(MainCookie::class)->login('12345', 'secret');
}
public function testItDoesntSaveCookieWhenLoginFails(): void
@ -44,7 +44,7 @@ class LoginTest extends TestCase
app(LoginFake::class)->fails('::token::');
try {
app(MainCookie::class)->login(12345, 'secret');
app(MainCookie::class)->login('12345', 'secret');
} catch (LoginException $e) {
}
@ -57,7 +57,7 @@ class LoginTest extends TestCase
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');
Nami::login('90100', 'secret');
Http::assertSentCount(0);
$this->assertFileExists(__DIR__ . '/../../.cookies_test/90100_' . now()->subMinutes(5)->timestamp . '.txt');
@ -70,7 +70,7 @@ class LoginTest extends TestCase
app(LoginFake::class)->succeeds('newlogin');
file_put_contents(__DIR__ . '/../../.cookies_test/90100_' . now()->subHour()->timestamp . '.txt', 'oldlogin-testsession.srv-nami06');
Nami::login(90100, 'secret');
Nami::login('90100', 'secret');
Http::assertSentCount(1);
$cookie = file_get_contents(__DIR__ . '/../../.cookies_test/90100_' . now()->timestamp . '.txt');
@ -84,9 +84,9 @@ class LoginTest extends TestCase
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(Authenticator::class)->login('12345', 'secret');
app(LoginFake::class)->assertSent(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');
}
@ -94,7 +94,7 @@ class LoginTest extends TestCase
public function testItRefreshesLogin(): void
{
app(LoginFake::class)->succeeds('newlogin');
$auth = app(Authenticator::class)->login(12345, 'secret');
$auth = app(Authenticator::class)->login('12345', 'secret');
rename(
__DIR__ . '/../../.cookies_test/12345_' . now()->timestamp . '.txt',
__DIR__ . '/../../.cookies_test/12345_' . now()->subMinutes(51)->timestamp . '.txt'