i written a webaplication with cakephp 4.x. In my controller(AppController.php) i have implements the following:
...
public function beforeRender(\Cake\Event\EventInterface $event)
{
#Load User_ID
if($this->Authentication->getIdentity()){
$identity = $this->Authentication->getIdentity();
$user_id = $this->Authentication->getIdentity()->getIdentifier();
}
}
...
Now i written the phpunit test following:
...
private function loginAsAdmin() {
$this->Users = TableRegistry::getTableLocator()->get('Users');
$user = $this->Users->get(1);
$this->session(['Auth.User'=> $user->toArray()]);
}
/**
* Test loginAsUser method
*
* @return void
*/
public function testLoginAsAdmin(): void
{
$this->loginAsAdmin();
$this->get('/admin/dashboard');
$this->assertSession(1, 'Auth.User.id'); //check if the user is logged in
}
...
But my identity object is allways empty. empty identity object
The object should actually look like this: the original object with data
i have no more ideas how to implement it. Can someone help me?