Skip to content

Commit

Permalink
fix warnings after update phpunit to 8.2
Browse files Browse the repository at this point in the history
  • Loading branch information
skie committed May 5, 2019
1 parent 2f58de4 commit 6a7641b
Show file tree
Hide file tree
Showing 11 changed files with 53 additions and 47 deletions.
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
"cakephp/authentication": "2.x-dev as 2.0"
},
"require-dev": {
"phpunit/phpunit": "^7",
"phpunit/phpunit": "^8.0",
"league/oauth2-facebook": "@stable",
"league/oauth2-instagram": "@stable",
"league/oauth2-google": "@stable",
Expand Down
14 changes: 8 additions & 6 deletions src/Model/Behavior/SocialAccountBehavior.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,12 @@

namespace CakeDC\Users\Model\Behavior;

use ArrayObject;
use Cake\Core\Configure;
use Cake\Datasource\EntityInterface;
use Cake\Datasource\Exception\RecordNotFoundException;
use Cake\Event\Event;
use Cake\Event\EventInterface;
use Cake\Mailer\MailerAwareTrait;
use Cake\ORM\Behavior;
use Cake\ORM\Entity;
Expand Down Expand Up @@ -47,17 +49,17 @@ public function initialize(array $config): void
/**
* After save callback
*
* @param \Cake\Event\Event $event event
* @param \Cake\ORM\Entity $entity entity
* @param \Cake\Event\EventInterface $event event
* @param \Cake\Datasource\EntityInterface $entity entity
* @param \ArrayObject $options options
* @return mixed
*/
public function afterSave(Event $event, Entity $entity, $options)
public function afterSave(EventInterface $event, EntityInterface $entity, ArrayObject $options)
{
if ($entity->active) {
if ($entity->get('active')) {
return true;
}
$user = $this->_table->Users->find()->where(['Users.id' => $entity->user_id, 'Users.active' => true])->first();
$user = $this->_table->getAssociation('Users')->find()->where(['Users.id' => $entity->get('user_id'), 'Users.active' => true])->first();
if (empty($user)) {
return true;
}
Expand All @@ -70,7 +72,7 @@ public function afterSave(Event $event, Entity $entity, $options)
*
* @param \Cake\Datasource\EntityInterface $socialAccount social account
* @param \Cake\Datasource\EntityInterface $user user
* @return void
* @return array
*/
protected function sendSocialValidationEmail(EntityInterface $socialAccount, EntityInterface $user)
{
Expand Down
3 changes: 2 additions & 1 deletion tests/TestCase/Controller/Traits/RegisterTraitTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

use Cake\Core\Configure;
use Cake\Event\Event;
use Cake\Http\Exception\NotFoundException;
use Cake\Routing\Router;

class RegisterTraitTest extends BaseTraitTest
Expand Down Expand Up @@ -346,10 +347,10 @@ public function testRegisterRecaptchaDisabled()
* test
*
* @return void
* @expectedException Cake\Http\Exception\NotFoundException
*/
public function testRegisterNotEnabled()
{
$this->expectException(NotFoundException::class);
Configure::write('Users.Registration.active', false);
$this->_mockRequestPost();
$this->_mockAuthentication();
Expand Down
11 changes: 7 additions & 4 deletions tests/TestCase/Controller/Traits/SimpleCrudTraitTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@

namespace CakeDC\Users\Test\TestCase\Controller\Traits;

use Cake\Datasource\Exception\InvalidPrimaryKeyException;
use Cake\Datasource\Exception\RecordNotFoundException;

class SimpleCrudTraitTest extends BaseTraitTest
{
public $viewVars;
Expand Down Expand Up @@ -95,21 +98,21 @@ public function testView()
* test
*
* @return void
* @expectedException Cake\Datasource\Exception\RecordNotFoundException
*/
public function testViewNotFound()
{
$this->expectException(RecordNotFoundException::class);
$this->Trait->view('00000000-0000-0000-0000-000000000000');
}

/**
* test
*
* @return void
* @expectedException Cake\Datasource\Exception\InvalidPrimaryKeyException
*/
public function testViewInvalidPK()
{
$this->expectException(InvalidPrimaryKeyException::class);
$this->Trait->view();
}

Expand Down Expand Up @@ -263,10 +266,10 @@ public function testEditPostErrors()
* test
*
* @return void
* @expectedException Cake\Datasource\Exception\RecordNotFoundException
*/
public function testDeleteHappy()
{
$this->expectException(RecordNotFoundException::class);
$this->assertNotEmpty($this->table->get('00000000-0000-0000-0000-000000000001'));
$this->_mockRequestPost();
$this->Trait->request->expects($this->any())
Expand All @@ -288,10 +291,10 @@ public function testDeleteHappy()
* test
*
* @return void
* @expectedException Cake\Datasource\Exception\RecordNotFoundException
*/
public function testDeleteNotFound()
{
$this->expectException(RecordNotFoundException::class);
$this->assertNotEmpty($this->table->get('00000000-0000-0000-0000-000000000001'));
$this->_mockRequestPost();
$this->Trait->request->expects($this->any())
Expand Down
5 changes: 2 additions & 3 deletions tests/TestCase/Model/Behavior/AuthFinderBehaviorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -68,12 +68,11 @@ public function testFindActive()

/**
* Test findAuth method.
*
* @expectedException \BadMethodCallException
* @expectedExceptionMessage Missing 'username' in options data
*/
public function testFindAuthBadMethodCallException()
{
$this->expectException(\BadMethodCallException::class);
$this->expectExceptionMessage("Missing 'username' in options data");
$this->table->find('auth');
}

Expand Down
20 changes: 9 additions & 11 deletions tests/TestCase/Model/Behavior/PasswordBehaviorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@
use Cake\Mailer\TransportFactory;
use Cake\ORM\TableRegistry;
use Cake\TestSuite\TestCase;
use CakeDC\Users\Exception\UserAlreadyActiveException;
use CakeDC\Users\Exception\UserNotActiveException;
use CakeDC\Users\Exception\UserNotFoundException;
use CakeDC\Users\Model\Behavior\PasswordBehavior;
use CakeDC\Users\Test\App\Mailer\OverrideMailer;

Expand Down Expand Up @@ -115,44 +118,40 @@ public function testResetTokenSendEmail()

/**
* Test resetToken
*
* @expectedException InvalidArgumentException
*/
public function testResetTokenWithNullParams()
{
$this->expectException(\InvalidArgumentException::class);
$this->Behavior->resetToken(null);
}

/**
* Test resetTokenNoExpiration
*
* @expectedException InvalidArgumentException
* @expectedExceptionMessage Token expiration cannot be empty
*/
public function testResetTokenNoExpiration()
{
$this->expectException(\InvalidArgumentException::class);
$this->expectExceptionMessage('Token expiration cannot be empty');
$this->Behavior->resetToken('ref');
}

/**
* Test resetToken
*
* @expectedException \CakeDC\Users\Exception\UserNotFoundException
*/
public function testResetTokenNotExistingUser()
{
$this->expectException(UserNotFoundException::class);
$this->Behavior->resetToken('user-not-found', [
'expiration' => 3600,
]);
}

/**
* Test resetToken
*
* @expectedException \CakeDC\Users\Exception\UserAlreadyActiveException
*/
public function testResetTokenUserAlreadyActive()
{
$this->expectException(UserAlreadyActiveException::class);
$activeUser = TableRegistry::getTableLocator()->get('CakeDC/Users.Users')->findByUsername('user-4')->first();
$this->assertTrue($activeUser->active);
$this->table = $this->getMockForModel('CakeDC/Users.Users', ['save']);
Expand All @@ -168,11 +167,10 @@ public function testResetTokenUserAlreadyActive()

/**
* Test resetToken
*
* @expectedException \CakeDC\Users\Exception\UserNotActiveException
*/
public function testResetTokenUserNotActive()
{
$this->expectException(UserNotActiveException::class);
$this->table->findByUsername('user-1')->firstOrFail();
$this->Behavior->resetToken('user-1', [
'ensureActive' => true,
Expand Down
6 changes: 4 additions & 2 deletions tests/TestCase/Model/Behavior/RegisterBehaviorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
use Cake\ORM\TableRegistry;
use Cake\Routing\Router;
use Cake\TestSuite\TestCase;
use CakeDC\Users\Exception\TokenExpiredException;
use CakeDC\Users\Exception\UserNotFoundException;

/**
* Test Case
Expand Down Expand Up @@ -249,21 +251,21 @@ public function testValidate()
* Test Validate method
*
* @return void
* @expectedException \CakeDC\Users\Exception\TokenExpiredException
*/
public function testValidateUserWithExpiredToken()
{
$this->expectException(TokenExpiredException::class);
$this->Table->validate('token-5', 'activateUser');
}

/**
* Test Validate method
*
* @return void
* @expectedException \CakeDC\Users\Exception\UserNotFoundException
*/
public function testValidateNotExistingUser()
{
$this->expectException(UserNotFoundException::class);
$this->Table->validate('not-existing-token', 'activateUser');
}

Expand Down
17 changes: 8 additions & 9 deletions tests/TestCase/Model/Behavior/SocialAccountBehaviorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,11 @@

namespace CakeDC\Users\Test\TestCase\Model\Behavior;

use Cake\Datasource\Exception\RecordNotFoundException;
use Cake\Event\Event;
use Cake\ORM\TableRegistry;
use Cake\TestSuite\TestCase;
use CakeDC\Users\Exception\AccountAlreadyActiveException;
use CakeDC\Users\Model\Table\SocialAccountsTable;

/**
Expand Down Expand Up @@ -70,31 +72,28 @@ public function testValidateEmail()

/**
* Test validateEmail method
*
* @expectedException \Cake\Datasource\Exception\RecordNotFoundException
*/
public function testValidateEmailInvalidToken()
{
$this->expectException(RecordNotFoundException::class);
$this->Behavior->validateAccount(1, 'reference-1234', 'invalid-token');
}

/**
* Test validateEmail method
*
* @expectedException \Cake\Datasource\Exception\RecordNotFoundException
*/
public function testValidateEmailInvalidUser()
{
$this->expectException(RecordNotFoundException::class);
$this->Behavior->validateAccount(1, 'invalid-user', 'token-1234');
}

/**
* Test validateEmail method
*
* @expectedException CakeDC\Users\Exception\AccountAlreadyActiveException
*/
public function testValidateEmailActiveAccount()
{
$this->expectException(AccountAlreadyActiveException::class);
$this->Behavior->validateAccount(SocialAccountsTable::PROVIDER_TWITTER, 'reference-1-1234', 'token-1234');
}

Expand All @@ -108,7 +107,7 @@ public function testAfterSaveSocialNotActiveUserNotActive()
{
$event = new Event('eventName');
$entity = $this->Table->find()->first();
$this->assertTrue($this->Behavior->afterSave($event, $entity, []));
$this->assertTrue($this->Behavior->afterSave($event, $entity, new \ArrayObject([])));
}

/**
Expand All @@ -121,7 +120,7 @@ public function testAfterSaveSocialActiveUserActive()
{
$event = new Event('eventName');
$entity = $this->Table->findById('00000000-0000-0000-0000-000000000003')->first();
$this->assertTrue($this->Behavior->afterSave($event, $entity, []));
$this->assertTrue($this->Behavior->afterSave($event, $entity, new \ArrayObject([])));
}

/**
Expand All @@ -134,6 +133,6 @@ public function testAfterSaveSocialActiveUserNotActive()
{
$event = new Event('eventName');
$entity = $this->Table->findById('00000000-0000-0000-0000-000000000002')->first();
$this->assertTrue($this->Behavior->afterSave($event, $entity, []));
$this->assertTrue($this->Behavior->afterSave($event, $entity, new \ArrayObject([])));
}
}
9 changes: 6 additions & 3 deletions tests/TestCase/Model/Behavior/SocialBehaviorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@
namespace CakeDC\Users\Test\TestCase\Model\Behavior;

use Cake\TestSuite\TestCase;
use CakeDC\Users\Exception\AccountNotActiveException;
use CakeDC\Users\Exception\MissingEmailException;
use CakeDC\Users\Exception\UserNotActiveException;

/**
* Test Case
Expand Down Expand Up @@ -239,11 +242,11 @@ public function providerFacebookSocialLoginExistingReference()
/**
* Test socialLogin with existing and active user and not active social account
*
* @expectedException CakeDC\Users\Exception\AccountNotActiveException
* @dataProvider providerSocialLoginExistingAndNotActiveAccount
*/
public function testSocialLoginExistingNotActiveReference($data, $options)
{
$this->expectException(AccountNotActiveException::class);
$this->Behavior->expects($this->never())
->method('generateUniqueUsername');

Expand Down Expand Up @@ -280,11 +283,11 @@ public function providerSocialLoginExistingAndNotActiveAccount()
/**
* Test socialLogin with existing and active account but not active user
*
* @expectedException CakeDC\Users\Exception\UserNotActiveException
* @dataProvider providerSocialLoginExistingAccountNotActiveUser
*/
public function testSocialLoginExistingReferenceNotActiveUser($data, $options)
{
$this->expectException(UserNotActiveException::class);
$this->Behavior->expects($this->never())
->method('generateUniqueUsername');

Expand Down Expand Up @@ -322,10 +325,10 @@ public function providerSocialLoginExistingAccountNotActiveUser()
* Test socialLogin with facebook and not existing user
*
* @dataProvider providerFacebookSocialLoginNoEmail
* @expectedException CakeDC\Users\Exception\MissingEmailException
*/
public function testSocialLoginNoEmail($data, $options)
{
$this->expectException(MissingEmailException::class);
$this->Behavior->socialLogin($data, $options);
}

Expand Down
Loading

0 comments on commit 6a7641b

Please sign in to comment.