Upgrade PHPUnit to 8. Replace codeception/base with codeception/codeception due to release bug in the base version.

This commit is contained in:
ErickSkrauch
2019-08-02 15:57:17 +03:00
parent 7b11366a5a
commit d9f2b1a8c9
21 changed files with 522 additions and 219 deletions

View File

@@ -1,7 +1,10 @@
<?php
declare(strict_types=1);
namespace codeception\api\unit\modules\authserver\models;
use api\models\authentication\LoginForm;
use api\modules\authserver\exceptions\ForbiddenOperationException;
use api\modules\authserver\models\AuthenticateData;
use api\modules\authserver\models\AuthenticationForm;
use api\tests\unit\TestCase;
@@ -22,11 +25,10 @@ class AuthenticationFormTest extends TestCase {
];
}
/**
* @expectedException \api\modules\authserver\exceptions\ForbiddenOperationException
* @expectedExceptionMessage Invalid credentials. Invalid nickname or password.
*/
public function testAuthenticateByWrongNicknamePass() {
$this->expectException(ForbiddenOperationException::class);
$this->expectExceptionMessage('Invalid credentials. Invalid nickname or password.');
$authForm = $this->createAuthForm();
$authForm->username = 'wrong-username';
@@ -36,11 +38,10 @@ class AuthenticationFormTest extends TestCase {
$authForm->authenticate();
}
/**
* @expectedException \api\modules\authserver\exceptions\ForbiddenOperationException
* @expectedExceptionMessage Invalid credentials. Invalid email or password.
*/
public function testAuthenticateByWrongEmailPass() {
$this->expectException(ForbiddenOperationException::class);
$this->expectExceptionMessage('Invalid credentials. Invalid email or password.');
$authForm = $this->createAuthForm();
$authForm->username = 'wrong-email@ely.by';
@@ -50,11 +51,10 @@ class AuthenticationFormTest extends TestCase {
$authForm->authenticate();
}
/**
* @expectedException \api\modules\authserver\exceptions\ForbiddenOperationException
* @expectedExceptionMessage This account has been suspended.
*/
public function testAuthenticateByValidCredentialsIntoBlockedAccount() {
$this->expectException(ForbiddenOperationException::class);
$this->expectExceptionMessage('This account has been suspended.');
$authForm = $this->createAuthForm(Account::STATUS_BANNED);
$authForm->username = 'dummy';
@@ -71,7 +71,7 @@ class AuthenticationFormTest extends TestCase {
$minecraftAccessKey->access_token = Uuid::uuid4();
$authForm->expects($this->once())
->method('createMinecraftAccessToken')
->will($this->returnValue($minecraftAccessKey));
->willReturn($minecraftAccessKey);
$authForm->username = 'dummy';
$authForm->password = 'password_0';
@@ -122,18 +122,18 @@ class AuthenticationFormTest extends TestCase {
$account->status = $status;
$account->setPassword('password_0');
$loginForm->expects($this->any())
$loginForm
->method('getAccount')
->will($this->returnValue($account));
->willReturn($account);
/** @var AuthenticationForm|\PHPUnit\Framework\MockObject\MockObject $authForm */
$authForm = $this->getMockBuilder(AuthenticationForm::class)
->setMethods(['createLoginForm', 'createMinecraftAccessToken'])
->getMock();
$authForm->expects($this->any())
$authForm
->method('createLoginForm')
->will($this->returnValue($loginForm));
->willReturn($loginForm);
return $authForm;
}

View File

@@ -1,6 +1,9 @@
<?php
declare(strict_types=1);
namespace codeception\api\unit\modules\authserver\validators;
use api\modules\authserver\exceptions\IllegalArgumentException;
use api\modules\authserver\validators\RequiredValidator;
use api\tests\unit\TestCase;
use common\tests\_support\ProtectedCaller;
@@ -13,10 +16,9 @@ class RequiredValidatorTest extends TestCase {
$this->assertNull($this->callProtected($validator, 'validateValue', 'dummy'));
}
/**
* @expectedException \api\modules\authserver\exceptions\IllegalArgumentException
*/
public function testValidateValueEmpty() {
$this->expectException(IllegalArgumentException::class);
$validator = new RequiredValidator();
$this->assertNull($this->callProtected($validator, 'validateValue', ''));
}

View File

@@ -1,6 +1,9 @@
<?php
declare(strict_types=1);
namespace api\tests\unit\modules\oauth\models;
use api\modules\oauth\exceptions\UnsupportedOauthClientType;
use api\modules\oauth\models\ApplicationType;
use api\modules\oauth\models\MinecraftServerType;
use api\modules\oauth\models\OauthClientFormFactory;
@@ -37,10 +40,9 @@ class OauthClientFormFactoryTest extends TestCase {
$this->assertSame('localhost:12345', $requestForm->minecraftServerIp);
}
/**
* @expectedException \api\modules\oauth\exceptions\UnsupportedOauthClientType
*/
public function testCreateUnknownType() {
$this->expectException(UnsupportedOauthClientType::class);
$client = new OauthClient();
$client->type = 'unknown-type';
OauthClientFormFactory::create($client);

View File

@@ -10,6 +10,7 @@ use Faker\Provider\Internet;
use Yii;
use yii\redis\Connection;
use yii\web\Request;
use yii\web\TooManyRequestsHttpException;
class RateLimiterTest extends TestCase {
@@ -63,10 +64,9 @@ class RateLimiterTest extends TestCase {
$filter->checkRateLimit(null, $request, null, null);
}
/**
* @expectedException \yii\web\TooManyRequestsHttpException
*/
public function testCheckRateLimiter() {
$this->expectException(TooManyRequestsHttpException::class);
/** @var Connection|\PHPUnit\Framework\MockObject\MockObject $redis */
$redis = $this->getMockBuilder(Connection::class)
->setMethods(['executeCommand'])