accounts/tests/codeception/console/unit/controllers/AccountQueueControllerTest.php
ErickSkrauch cba769a1ec В проект внедрён RabbitMQ.
Контроллер для работы с RabbitMQ научился создавать типизированные аргументы для $body
Добавлена таблица с историей ников
Добавлена таблица Mojang ников
Добавлена проверка активированности аккаунта в AccountsController
2016-04-23 21:44:10 +03:00

96 lines
4.1 KiB
PHP
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<?php
namespace codeception\console\unit\controllers;
use Codeception\Specify;
use common\models\amqp\UsernameChanged;
use common\models\MojangUsername;
use console\controllers\AccountQueueController;
use tests\codeception\common\fixtures\AccountFixture;
use tests\codeception\common\fixtures\MojangUsernameFixture;
use tests\codeception\console\unit\DbTestCase;
use Yii;
/**
* @property array $accounts
* @property array $mojangUsernames
*/
class AccountQueueControllerTest extends DbTestCase {
use Specify;
public function fixtures() {
return [
'accounts' => [
'class' => AccountFixture::class,
'dataFile' => '@tests/codeception/common/fixtures/data/accounts.php',
],
'mojangUsernames' => [
'class' => MojangUsernameFixture::class,
'dataFile' => '@tests/codeception/common/fixtures/data/mojang-usernames.php',
],
];
}
public function testRouteUsernameChanged() {
// TODO: пропустить тест, если у нас нету интернета
$controller = new AccountQueueController('account-queue', Yii::$app);
$this->specify('Update last_pulled_at time if username exists', function() use ($controller) {
$accountInfo = $this->accounts['admin'];
$body = new UsernameChanged([
'accountId' => $accountInfo['id'],
'oldUsername' => $accountInfo['username'],
'newUsername' => 'Notch',
]);
$controller->routeUsernameChanged($body);
/** @var MojangUsername|null $mojangUsername */
$mojangUsername = MojangUsername::findOne('Notch');
expect($mojangUsername)->isInstanceOf(MojangUsername::class);
expect($mojangUsername->last_pulled_at)->greaterThan($this->mojangUsernames['Notch']['last_pulled_at']);
expect($mojangUsername->last_pulled_at)->lessOrEquals(time());
});
$this->specify('Add new MojangUsername if don\'t exists', function() use ($controller) {
$accountInfo = $this->accounts['admin'];
$body = new UsernameChanged([
'accountId' => $accountInfo['id'],
'oldUsername' => $accountInfo['username'],
'newUsername' => 'Chest',
]);
$controller->routeUsernameChanged($body);
/** @var MojangUsername|null $mojangUsername */
$mojangUsername = MojangUsername::findOne('Chest');
expect($mojangUsername)->isInstanceOf(MojangUsername::class);
});
$this->specify('Remove MojangUsername, if now it\'s does\'t exists', function() use ($controller) {
$accountInfo = $this->accounts['admin'];
$username = $this->mojangUsernames['not-exists']['username'];
$body = new UsernameChanged([
'accountId' => $accountInfo['id'],
'oldUsername' => $accountInfo['username'],
'newUsername' => $username,
]);
$controller->routeUsernameChanged($body);
/** @var MojangUsername|null $mojangUsername */
$mojangUsername = MojangUsername::findOne($username);
expect($mojangUsername)->null();
});
$this->specify('Update uuid if username for now owned by other player', function() use ($controller) {
$accountInfo = $this->accounts['admin'];
$mojangInfo = $this->mojangUsernames['uuid-changed'];
$username = $mojangInfo['username'];
$body = new UsernameChanged([
'accountId' => $accountInfo['id'],
'oldUsername' => $accountInfo['username'],
'newUsername' => $username,
]);
$controller->routeUsernameChanged($body);
/** @var MojangUsername|null $mojangUsername */
$mojangUsername = MojangUsername::findOne($username);
expect($mojangUsername)->isInstanceOf(MojangUsername::class);
expect($mojangUsername->uuid)->notEquals($mojangInfo['uuid']);
});
}
}