mirror of
https://github.com/elyby/accounts.git
synced 2024-11-08 13:42:30 +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:
parent
7b11366a5a
commit
d9f2b1a8c9
@ -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(), []));
|
||||
}
|
||||
|
@ -13,7 +13,7 @@ class TestCase extends Unit {
|
||||
*/
|
||||
protected $tester;
|
||||
|
||||
protected function tearDown() {
|
||||
protected function tearDown(): void {
|
||||
parent::tearDown();
|
||||
Mockery::close();
|
||||
}
|
||||
|
@ -20,7 +20,7 @@ class ComponentTest extends TestCase {
|
||||
*/
|
||||
private $component;
|
||||
|
||||
protected function setUp() {
|
||||
protected function setUp(): void {
|
||||
parent::setUp();
|
||||
|
||||
$this->api = $this->createMock(Api::class);
|
||||
|
@ -38,9 +38,8 @@ class CreateWebHooksDeliveriesTest extends TestCase {
|
||||
'status' => 0,
|
||||
];
|
||||
$result = CreateWebHooksDeliveries::createAccountEdit($account, $changedAttributes);
|
||||
$this->assertInstanceOf(CreateWebHooksDeliveries::class, $result);
|
||||
$this->assertSame('account.edit', $result->type);
|
||||
$this->assertArraySubset([
|
||||
$this->assertEmpty(array_diff_assoc([
|
||||
'id' => 123,
|
||||
'uuid' => 'afc8dc7a-4bbf-4d3a-8699-68890088cf84',
|
||||
'username' => 'mock-username',
|
||||
@ -48,8 +47,8 @@ class CreateWebHooksDeliveriesTest extends TestCase {
|
||||
'lang' => 'en',
|
||||
'isActive' => true,
|
||||
'registered' => '2018-07-08T00:13:34+00:00',
|
||||
'changedAttributes' => $changedAttributes,
|
||||
], $result->payloads);
|
||||
], $result->payloads));
|
||||
$this->assertSame($changedAttributes, $result->payloads['changedAttributes']);
|
||||
}
|
||||
|
||||
public function testExecute() {
|
||||
|
@ -90,10 +90,9 @@ class DeliveryWebHookTest extends TestCase {
|
||||
$task->execute(mock(Queue::class));
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException \GuzzleHttp\Exception\ServerException
|
||||
*/
|
||||
public function testExecuteUnhandledException() {
|
||||
$this->expectException(ServerException::class);
|
||||
|
||||
$this->response = new Response(502);
|
||||
$task = $this->createMockedTask();
|
||||
$task->type = 'account.edit';
|
||||
|
@ -50,7 +50,7 @@ class PullMojangUsernameTest extends TestCase {
|
||||
public function testExecuteUsernameExists() {
|
||||
$this->mockedMethod->willReturn(new ProfileInfo('069a79f444e94726a5befca90e38aaf5', 'Notch'));
|
||||
|
||||
/** @var \common\models\MojangUsername $mojangUsernameFixture */
|
||||
/** @var MojangUsername $mojangUsernameFixture */
|
||||
$mojangUsernameFixture = $this->tester->grabFixture('mojangUsernames', 'Notch');
|
||||
$task = new PullMojangUsername();
|
||||
$task->username = 'Notch';
|
||||
@ -89,7 +89,7 @@ class PullMojangUsernameTest extends TestCase {
|
||||
}
|
||||
|
||||
public function testExecuteRemoveIfExistsNoMore() {
|
||||
$this->mockedMethod->willThrowException(new NoContentException(new Request('', ''), new Response()));
|
||||
$this->mockedMethod->willThrowException(new NoContentException(new Request('GET', ''), new Response()));
|
||||
|
||||
$username = $this->tester->grabFixture('mojangUsernames', 'not-exists')['username'];
|
||||
$task = new PullMojangUsername();
|
||||
|
@ -41,7 +41,7 @@ class SendCurrentEmailConfirmationTest extends TestCase {
|
||||
$this->assertSame(['mock@ely.by' => 'mock-username'], $email->getTo());
|
||||
$this->assertSame('Ely.by Account change E-mail confirmation', $email->getSubject());
|
||||
$children = $email->getSwiftMessage()->getChildren()[0];
|
||||
$this->assertContains('GFEDCBA', $children->getBody());
|
||||
$this->assertStringContainsString('GFEDCBA', $children->getBody());
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -41,7 +41,7 @@ class SendNewEmailConfirmationTest extends TestCase {
|
||||
$this->assertSame(['mock@ely.by' => 'mock-username'], $email->getTo());
|
||||
$this->assertSame('Ely.by Account new E-mail confirmation', $email->getSubject());
|
||||
$children = $email->getSwiftMessage()->getChildren()[0];
|
||||
$this->assertContains('GFEDCBA', $children->getBody());
|
||||
$this->assertStringContainsString('GFEDCBA', $children->getBody());
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -32,7 +32,7 @@
|
||||
"yiisoft/yii2-swiftmailer": "~2.1.0"
|
||||
},
|
||||
"require-dev": {
|
||||
"codeception/base": "^3.0.0",
|
||||
"codeception/codeception": "^3.0",
|
||||
"codeception/specify": "^1.0.0",
|
||||
"ely/php-code-style": "^0.3.0",
|
||||
"flow/jsonpath": "^0.4.0",
|
||||
@ -47,7 +47,8 @@
|
||||
"symfony/polyfill-ctype": "*",
|
||||
"symfony/polyfill-mbstring": "*",
|
||||
"symfony/polyfill-php70": "*",
|
||||
"symfony/polyfill-php72": "*"
|
||||
"symfony/polyfill-php72": "*",
|
||||
"symfony/polyfill-php73": "*"
|
||||
},
|
||||
"repositories": [
|
||||
{
|
||||
|
621
composer.lock
generated
621
composer.lock
generated
File diff suppressed because it is too large
Load Diff
Loading…
Reference in New Issue
Block a user