We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
I add authentication plugin and authorization plugin to my CakePHP App.
On web broswer login works right.
I'm try to test it with PHPUnit and i receive some errors.
On my test i run this:
$config = TableRegistry::getTableLocator()->exists('Users') ? [] : ['className' => UsersTable::class]; $users = TableRegistry::getTableLocator()->get('Users', $config); $user = $users->get($userId); $this->session(['Auth' => $user]); $this->enableCsrfToken(); $this->enableSecurityToken(); // call $this->get('Users/login'); $this->assertResponseSuccess(); // Check for a 2xx/3xx response code
In my Application.php
new AuthorizationMiddleware($this, [ 'identityDecorator' => function (AuthorizationService $auth, ArrayAccess $user) { debug($user);die; return $user->setAuthorization($auth); }, 'requireAuthorizationCheck' => false, 'unauthorizedHandler' => [ 'className' => 'Authorization.Redirect', 'url' => '/users/login', 'queryParam' => 'redirectUrl', 'exceptions' => [ MissingIdentityException::class, OtherException::class ] ] ])
debug print on test show:
########## DEBUG ########## object(Authentication\Identity) id:0 { 'config' => [ 'fieldMap' => [ 'id' => 'id' ] ] 'data' => object(Cake\ORM\Entity) id:1 { 'id' => (int) 1 'role_id' => (int) 1 'status_id' => (int) 1 ...
On Web Browser show:
object(App\Model\Entity\User) id:0 { 'id' => (int) 1 'role_id' => (int) 2 'status_id' => (int) 1 ...
Error, in testCase on cli-error.log is
Call to undefined method Authentication\Identity::setAuthorization()
Which configuration options am I missing to get things to work together correctly?
The text was updated successfully, but these errors were encountered:
Seems like you might be getting an auto-model in your tests. You should check if $users is the correct class name.
$users
Sorry, something went wrong.
Yes it works. I change on my test this:
$config = TableRegistry::getTableLocator()->exists('Users') ? [] : ['className' => UsersTable::class]; $users = TableRegistry::getTableLocator()->get('Users', $config);
with this
$users = TableRegistry::getTableLocator()->get('Users');
Now it works correctly. Thanks a lot.
No branches or pull requests
I add authentication plugin and authorization plugin to my CakePHP App.
On web broswer login works right.
I'm try to test it with PHPUnit and i receive some errors.
On my test i run this:
In my Application.php
debug print on test show:
On Web Browser show:
Error, in testCase on cli-error.log is
Call to undefined method Authentication\Identity::setAuthorization()
Which configuration options am I missing to get things to work together correctly?
The text was updated successfully, but these errors were encountered: