[ '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']); }); } }