createInstance(); $this->expectException(ModelNotFoundException::class); $usesAuth->user('self'); } /** * @covers \Engelsystem\Controllers\Api\UsesAuth::getUser */ public function testGetUserNotFound(): void { $usesAuth = $this->createInstance(); $this->expectException(ModelNotFoundException::class); $usesAuth->user(42); } /** * @covers \Engelsystem\Controllers\Api\UsesAuth::getUser */ public function testGetUserWithoutAuth(): void { $user = User::factory()->create(); $usesAuth = $this->createInstance(); $this->assertInstanceOf(User::class, $usesAuth->user($user->id)); } /** * @covers \Engelsystem\Controllers\Api\UsesAuth::setAuth * @covers \Engelsystem\Controllers\Api\UsesAuth::getUser */ public function testGetUser(): void { $user = User::factory()->create(); /** @var Authenticator|MockObject $auth */ $auth = $this->createMock(Authenticator::class); $this->setExpects($auth, 'user', null, $user); $usesAuth = $this->createInstance(); $usesAuth->setAuth($auth); $this->assertEquals($user, $usesAuth->user('self')); } protected function createInstance(): object { return new UsesAuthImplementation(new Response()); } }