mirror of
https://github.com/elyby/accounts.git
synced 2025-05-31 14:11:46 +05:30
Upgrade PHPUnit to 8. Replace codeception/base with codeception/codeception due to release bug in the base version.
This commit is contained in:
@@ -13,7 +13,7 @@ class TestCase extends Unit {
|
||||
*/
|
||||
protected $tester;
|
||||
|
||||
protected function tearDown() {
|
||||
protected function tearDown(): void {
|
||||
parent::tearDown();
|
||||
Mockery::close();
|
||||
}
|
||||
|
@@ -30,20 +30,19 @@ class FeedbackFormTest extends TestCase {
|
||||
->getMock();
|
||||
|
||||
$model
|
||||
->expects($this->any())
|
||||
->method('getAccount')
|
||||
->will($this->returnValue(new Account([
|
||||
->willReturn(new Account([
|
||||
'id' => '123',
|
||||
'username' => 'Erick',
|
||||
'email' => 'find-this@email.net',
|
||||
'created_at' => time() - 86400,
|
||||
])));
|
||||
]));
|
||||
$this->assertTrue($model->sendMessage());
|
||||
/** @var Message $message */
|
||||
$message = $this->tester->grabLastSentEmail();
|
||||
$this->assertInstanceOf(Message::class, $message);
|
||||
$data = (string)$message;
|
||||
$this->assertContains('find-this@email.net', $data);
|
||||
$this->assertStringContainsString('find-this@email.net', $data);
|
||||
}
|
||||
|
||||
}
|
||||
|
@@ -1,4 +1,6 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace codeception\api\unit\models\authentication;
|
||||
|
||||
use api\components\ReCaptcha\Validator as ReCaptchaValidator;
|
||||
@@ -14,7 +16,7 @@ use Yii;
|
||||
|
||||
class ForgotPasswordFormTest extends TestCase {
|
||||
|
||||
protected function setUp() {
|
||||
protected function setUp(): void {
|
||||
parent::setUp();
|
||||
Yii::$container->set(ReCaptchaValidator::class, new class(mock(ClientInterface::class)) extends ReCaptchaValidator {
|
||||
public function validateValue($value) {
|
||||
|
@@ -15,13 +15,13 @@ class LoginFormTest extends TestCase {
|
||||
|
||||
private $originalRemoteAddr;
|
||||
|
||||
protected function setUp() {
|
||||
protected function setUp(): void {
|
||||
$this->originalRemoteAddr = $_SERVER['REMOTE_ADDR'] ?? null;
|
||||
$_SERVER['REMOTE_ADDR'] = '127.0.0.1';
|
||||
parent::setUp();
|
||||
}
|
||||
|
||||
protected function tearDown() {
|
||||
protected function tearDown(): void {
|
||||
parent::tearDown();
|
||||
$_SERVER['REMOTE_ADDR'] = $this->originalRemoteAddr;
|
||||
}
|
||||
|
@@ -22,7 +22,7 @@ use const common\LATEST_RULES_VERSION;
|
||||
|
||||
class RegistrationFormTest extends TestCase {
|
||||
|
||||
protected function setUp() {
|
||||
protected function setUp(): void {
|
||||
parent::setUp();
|
||||
$this->mockRequest();
|
||||
Yii::$container->set(ReCaptchaValidator::class, new class(mock(ClientInterface::class)) extends ReCaptchaValidator {
|
||||
|
@@ -1,4 +1,6 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace api\tests\_support\models\authentication;
|
||||
|
||||
use api\components\ReCaptcha\Validator as ReCaptchaValidator;
|
||||
@@ -15,7 +17,7 @@ use Yii;
|
||||
class RepeatAccountActivationFormTest extends TestCase {
|
||||
use Specify;
|
||||
|
||||
protected function setUp() {
|
||||
protected function setUp(): void {
|
||||
parent::setUp();
|
||||
Yii::$container->set(ReCaptchaValidator::class, new class(mock(ClientInterface::class)) extends ReCaptchaValidator {
|
||||
public function validateValue($value) {
|
||||
|
@@ -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;
|
||||
}
|
||||
|
@@ -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', ''));
|
||||
}
|
||||
|
@@ -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);
|
||||
|
@@ -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'])
|
||||
|
@@ -7,6 +7,7 @@ use api\components\User\IdentityInterface;
|
||||
use api\rbac\rules\AccountOwner;
|
||||
use common\models\Account;
|
||||
use common\tests\unit\TestCase;
|
||||
use InvalidArgumentException;
|
||||
use Yii;
|
||||
use yii\rbac\Item;
|
||||
use const common\LATEST_RULES_VERSION;
|
||||
@@ -53,10 +54,9 @@ class AccountOwnerTest extends TestCase {
|
||||
$this->assertFalse($rule->execute('token', $item, ['accountId' => 1, 'optionalRules' => true]));
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException \InvalidArgumentException
|
||||
*/
|
||||
public function testExecuteWithoutAccountId() {
|
||||
$this->expectException(InvalidArgumentException::class);
|
||||
|
||||
$rule = new AccountOwner();
|
||||
$this->assertFalse($rule->execute('token', new Item(), []));
|
||||
}
|
||||
|
@@ -9,6 +9,7 @@ use api\rbac\rules\OauthClientOwner;
|
||||
use common\models\Account;
|
||||
use common\tests\fixtures\OauthClientFixture;
|
||||
use common\tests\unit\TestCase;
|
||||
use InvalidArgumentException;
|
||||
use Yii;
|
||||
use yii\rbac\Item;
|
||||
use const common\LATEST_RULES_VERSION;
|
||||
@@ -59,10 +60,9 @@ class OauthClientOwnerTest extends TestCase {
|
||||
$this->assertFalse($rule->execute('token', $item, ['accountId' => 1]));
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException \InvalidArgumentException
|
||||
*/
|
||||
public function testExecuteWithoutClientId() {
|
||||
$this->expectException(InvalidArgumentException::class);
|
||||
|
||||
$rule = new OauthClientOwner();
|
||||
$this->assertFalse($rule->execute('token', new Item(), []));
|
||||
}
|
||||
|
Reference in New Issue
Block a user