Fix some tests

This commit is contained in:
ErickSkrauch 2019-08-01 19:58:18 +03:00
parent 45c2ed601d
commit 6bd054e743
7 changed files with 17 additions and 39 deletions

View File

@ -112,22 +112,20 @@ class LoginForm extends ApiForm {
Assert::true($account->save(), 'Unable to upgrade user\'s password');
}
$refreshToken = null;
$session = null;
if ($this->rememberMe) {
$session = new AccountSession();
$session->account_id = $account->id;
$session->setIp(Yii::$app->request->userIP);
$session->generateRefreshToken();
Assert::true($session->save(), 'Cannot save account session model');
$refreshToken = $session->refresh_token;
}
$token = TokensFactory::createForAccount($account, $session);
$transaction->commit();
return new AuthenticationResult($token, $refreshToken);
return new AuthenticationResult($token, $session ? $session->refresh_token : null);
}
}

View File

@ -13,7 +13,7 @@ use Yii;
class FunctionalTester extends Actor {
use FunctionalTesterActions;
public function amAuthenticated(string $asUsername = 'admin'): int {
public function amAuthenticated(string $asUsername = 'admin') { // Do not declare type
/** @var Account $account */
$account = Account::findOne(['username' => $asUsername]);
if ($account === null) {

View File

@ -9,7 +9,7 @@ use Ramsey\Uuid\Uuid;
class AuthserverSteps extends FunctionalTester {
public function amAuthenticated(string $asUsername = 'admin', string $password = 'password_0'): array {
public function amAuthenticated(string $asUsername = 'admin', string $password = 'password_0') {
$route = new AuthserverRoute($this);
$clientToken = Uuid::uuid4()->toString();
$route->authenticate([

View File

@ -25,7 +25,7 @@ class ComponentTest extends TestCase {
public function _before() {
parent::_before();
$this->component = new Component($this->getComponentConfig());
$this->component = new Component();
}
public function _fixtures(): array {
@ -72,7 +72,6 @@ class ComponentTest extends TestCase {
/** @var Component|\PHPUnit\Framework\MockObject\MockObject $component */
$component = $this->getMockBuilder(Component::class)
->setMethods(['getIsGuest'])
->setConstructorArgs([$this->getComponentConfig()])
->getMock();
$component
@ -91,7 +90,7 @@ class ComponentTest extends TestCase {
$session = $this->tester->grabFixture('sessions', 'admin2');
/** @var Component|\Mockery\MockInterface $component */
$component = mock(Component::class . '[getActiveSession]', [$this->getComponentConfig()])->makePartial();
$component = mock(Component::class . '[getActiveSession]')->makePartial();
$component->shouldReceive('getActiveSession')->times(1)->andReturn($session);
/** @var Account $account */
@ -140,15 +139,4 @@ class ComponentTest extends TestCase {
Yii::$app->request->headers->set('Authorization', $bearerToken);
}
private function getComponentConfig() {
return [
'identityClass' => IdentityFactory::class,
'enableSession' => false,
'loginUrl' => null,
'secret' => 'secret',
'publicKeyPath' => 'data/certs/public.crt',
'privateKeyPath' => 'data/certs/private.key',
];
}
}

View File

@ -1,7 +1,7 @@
<?php
declare(strict_types=1);
namespace codeception\api\unit\models;
namespace codeception\api\unit\components\User;
use api\components\User\JwtIdentity;
use api\tests\unit\TestCase;

View File

@ -1,4 +1,6 @@
<?php
declare(strict_types=1);
namespace common\tests\unit\rbac\rules;
use api\components\User\Component;
@ -13,12 +15,8 @@ use const common\LATEST_RULES_VERSION;
class AccountOwnerTest extends TestCase {
public function testIdentityIsNull() {
$component = mock(Component::class . '[findIdentityByAccessToken]', [[
'secret' => 'secret',
'publicKeyPath' => 'data/certs/public.crt',
'privateKeyPath' => 'data/certs/private.key',
]]);
$component->shouldDeferMissing();
$component = mock(Component::class . '[findIdentityByAccessToken]');
$component->makePartial();
$component->shouldReceive('findIdentityByAccessToken')->andReturn(null);
Yii::$app->set('user', $component);
@ -38,12 +36,8 @@ class AccountOwnerTest extends TestCase {
$identity = mock(IdentityInterface::class);
$identity->shouldReceive('getAccount')->andReturn($account);
$component = mock(Component::class . '[findIdentityByAccessToken]', [[
'secret' => 'secret',
'publicKeyPath' => 'data/certs/public.crt',
'privateKeyPath' => 'data/certs/private.key',
]]);
$component->shouldDeferMissing();
$component = mock(Component::class . '[findIdentityByAccessToken]');
$component->makePartial();
$component->shouldReceive('findIdentityByAccessToken')->withArgs(['token'])->andReturn($identity);
Yii::$app->set('user', $component);

View File

@ -1,4 +1,6 @@
<?php
declare(strict_types=1);
namespace common\tests\unit\rbac\rules;
use api\components\User\Component;
@ -34,12 +36,8 @@ class OauthClientOwnerTest extends TestCase {
$identity->shouldReceive('getAccount')->andReturn($account);
/** @var Component|\Mockery\MockInterface $component */
$component = mock(Component::class . '[findIdentityByAccessToken]', [[
'secret' => 'secret',
'publicKeyPath' => 'data/certs/public.crt',
'privateKeyPath' => 'data/certs/private.key',
]]);
$component->shouldDeferMissing();
$component = mock(Component::class . '[findIdentityByAccessToken]');
$component->makePartial();
$component->shouldReceive('findIdentityByAccessToken')->withArgs(['token'])->andReturn($identity);
Yii::$app->set('user', $component);