diff --git a/tests/codeception/common/fixtures/MojangUsernameFixture.php b/tests/codeception/common/fixtures/MojangUsernameFixture.php index b27ef0c..c0e53d7 100644 --- a/tests/codeception/common/fixtures/MojangUsernameFixture.php +++ b/tests/codeception/common/fixtures/MojangUsernameFixture.php @@ -8,4 +8,6 @@ class MojangUsernameFixture extends ActiveFixture { public $modelClass = MojangUsername::class; + public $dataFile = '@tests/codeception/common/fixtures/data/mojang-usernames.php'; + } diff --git a/tests/codeception/common/fixtures/OauthClientFixture.php b/tests/codeception/common/fixtures/OauthClientFixture.php index e6dee18..5b0385f 100644 --- a/tests/codeception/common/fixtures/OauthClientFixture.php +++ b/tests/codeception/common/fixtures/OauthClientFixture.php @@ -8,6 +8,8 @@ class OauthClientFixture extends ActiveFixture { public $modelClass = OauthClient::class; + public $dataFile = '@tests/codeception/common/fixtures/data/oauth-clients.php'; + public $depends = [ AccountFixture::class, ]; diff --git a/tests/codeception/common/fixtures/OauthSessionFixture.php b/tests/codeception/common/fixtures/OauthSessionFixture.php index 77adb2a..0bbab87 100644 --- a/tests/codeception/common/fixtures/OauthSessionFixture.php +++ b/tests/codeception/common/fixtures/OauthSessionFixture.php @@ -9,6 +9,8 @@ class OauthSessionFixture extends ActiveFixture { public $modelClass = OauthSession::class; + public $dataFile = '@tests/codeception/common/fixtures/data/oauth-sessions.php'; + public $depends = [ OauthClientFixture::class, AccountFixture::class, diff --git a/tests/codeception/common/unit.suite.yml b/tests/codeception/common/unit.suite.yml index a0582a5..8ce2d31 100644 --- a/tests/codeception/common/unit.suite.yml +++ b/tests/codeception/common/unit.suite.yml @@ -1,6 +1,8 @@ -# Codeception Test Suite Configuration - -# suite for unit (internal) tests. -# RUN `build` COMMAND AFTER ADDING/REMOVING MODULES. - class_name: UnitTester +modules: + enabled: + - Yii2: + part: [orm, email, fixtures] + config: + Yii2: + configFile: '../config/api/unit.php' diff --git a/tests/codeception/common/unit/DbTestCase.php b/tests/codeception/common/unit/DbTestCase.php deleted file mode 100644 index 2159a69..0000000 --- a/tests/codeception/common/unit/DbTestCase.php +++ /dev/null @@ -1,11 +0,0 @@ -specify('setting value should change model data field', function() { - $model = $this->createModel(); - /** @var DataBehavior $behavior */ - $behavior = $model->behaviors['dataBehavior']; - $this->callProtected($behavior, 'setKey', 'my-key', 'my-value'); - expect($model->_data)->equals(serialize(['my-key' => 'my-value'])); - }); + $model = $this->createModel(); + /** @var DataBehavior $behavior */ + $behavior = $model->behaviors['dataBehavior']; + $this->callProtected($behavior, 'setKey', 'my-key', 'my-value'); + $this->assertEquals(serialize(['my-key' => 'my-value']), $model->_data); } public function testGetKey() { - $this->specify('getting value from exists data should work', function() { - $model = $this->createModel(); - $model->_data = serialize(['some-key' => 'some-value']); - /** @var DataBehavior $behavior */ - $behavior = $model->behaviors['dataBehavior']; - expect($this->callProtected($behavior, 'getKey', 'some-key'))->equals('some-value'); - }); + $model = $this->createModel(); + $model->_data = serialize(['some-key' => 'some-value']); + /** @var DataBehavior $behavior */ + $behavior = $model->behaviors['dataBehavior']; + $this->assertEquals('some-value', $this->callProtected($behavior, 'getKey', 'some-key')); } public function testGetData() { diff --git a/tests/codeception/common/unit/behaviors/EmailActivationExpirationBehaviorTest.php b/tests/codeception/common/unit/behaviors/EmailActivationExpirationBehaviorTest.php index 5fbd663..5078acb 100644 --- a/tests/codeception/common/unit/behaviors/EmailActivationExpirationBehaviorTest.php +++ b/tests/codeception/common/unit/behaviors/EmailActivationExpirationBehaviorTest.php @@ -12,12 +12,10 @@ class EmailActivationExpirationBehaviorTest extends TestCase { use ProtectedCaller; public function testCalculateTime() { - $this->specify('just use create_time and plus passed time', function() { - $behavior = $this->createBehavior(); - $time = time(); - $behavior->owner->created_at = $time; - expect($this->callProtected($behavior, 'calculateTime', 10))->equals($time + 10); - }); + $behavior = $this->createBehavior(); + $time = time(); + $behavior->owner->created_at = $time; + $this->assertEquals($time + 10, $this->callProtected($behavior, 'calculateTime', 10)); } public function testCompareTime() { diff --git a/tests/codeception/common/unit/models/AccountSessionTest.php b/tests/codeception/common/unit/models/AccountSessionTest.php index 66a8f14..0e98803 100644 --- a/tests/codeception/common/unit/models/AccountSessionTest.php +++ b/tests/codeception/common/unit/models/AccountSessionTest.php @@ -1,35 +1,27 @@ specify('method call will set refresh_token value', function() { - $model = new AccountSession(); - $model->generateRefreshToken(); - expect($model->refresh_token)->notNull(); - }); + $model = new AccountSession(); + $model->generateRefreshToken(); + $this->assertNotNull($model->refresh_token, 'method call will set refresh_token value'); } public function testSetIp() { - $this->specify('method should convert passed ip string to long', function() { - $model = new AccountSession(); - $model->setIp('127.0.0.1'); - expect($model->last_used_ip)->equals(2130706433); - }); + $model = new AccountSession(); + $model->setIp('127.0.0.1'); + $this->assertEquals(2130706433, $model->last_used_ip, 'method should convert passed ip string to long'); } public function testGetReadableIp() { - $this->specify('method should convert stored ip long into readable ip string', function() { - $model = new AccountSession(); - $model->last_used_ip = 2130706433; - expect($model->getReadableIp())->equals('127.0.0.1'); - }); + $model = new AccountSession(); + $model->last_used_ip = 2130706433; + $this->assertEquals('127.0.0.1', $model->getReadableIp(), 'method should convert stored long into readable ip'); } } diff --git a/tests/codeception/common/unit/models/AccountTest.php b/tests/codeception/common/unit/models/AccountTest.php index 8bdb07d..a2078dc 100644 --- a/tests/codeception/common/unit/models/AccountTest.php +++ b/tests/codeception/common/unit/models/AccountTest.php @@ -6,27 +6,17 @@ use common\components\UserPass; use common\models\Account; use tests\codeception\common\fixtures\AccountFixture; use tests\codeception\common\fixtures\MojangUsernameFixture; -use tests\codeception\common\unit\DbTestCase; +use tests\codeception\common\unit\TestCase; use Yii; use const common\LATEST_RULES_VERSION; -/** - * @property array $accounts - * @property array $mojangAccounts - */ -class AccountTest extends DbTestCase { +class AccountTest extends TestCase { use Specify; - public function fixtures() { + public function _fixtures() { return [ - 'accounts' => [ - 'class' => AccountFixture::class, - 'dataFile' => '@tests/codeception/common/fixtures/data/accounts.php', - ], - 'mojangAccounts' => [ - 'class' => MojangUsernameFixture::class, - 'dataFile' => '@tests/codeception/common/fixtures/data/mojang-usernames.php', - ], + 'accounts' => AccountFixture::class, + 'mojangAccounts' => MojangUsernameFixture::class, ]; } @@ -73,7 +63,8 @@ class AccountTest extends DbTestCase { }); $this->specify('username should be unique', function() { - $model = new Account(['username' => $this->accounts['admin']['username']]); + $model = new Account(); + $model->username = $this->tester->grabFixture('accounts', 'admin')['username']; expect($model->validate('username'))->false(); expect($model->getErrors('username'))->equals(['error.username_not_available']); }); @@ -111,7 +102,7 @@ class AccountTest extends DbTestCase { }); $this->specify('email should be unique', function() { - $model = new Account(['email' => $this->accounts['admin']['email']]); + $model = new Account(['email' => $this->tester->grabFixture('accounts', 'admin')['email']]); expect($model->validate('email'))->false(); expect($model->getErrors('email'))->equals(['error.email_not_available']); }); diff --git a/tests/codeception/common/unit/models/EmailActivationTest.php b/tests/codeception/common/unit/models/EmailActivationTest.php index 8880e2d..d436b23 100644 --- a/tests/codeception/common/unit/models/EmailActivationTest.php +++ b/tests/codeception/common/unit/models/EmailActivationTest.php @@ -1,31 +1,35 @@ EmailActivationFixture::class, ]; } public function testInstantiate() { - $this->specify('return valid model type', function() { - expect(EmailActivation::findOne([ - 'type' => EmailActivation::TYPE_REGISTRATION_EMAIL_CONFIRMATION, - ]))->isInstanceOf(RegistrationConfirmation::class); - expect(EmailActivation::findOne([ - 'type' => EmailActivation::TYPE_FORGOT_PASSWORD_KEY, - ]))->isInstanceOf(ForgotPassword::class); - }); + $this->assertInstanceOf(confirmations\RegistrationConfirmation::class, EmailActivation::findOne([ + 'type' => EmailActivation::TYPE_REGISTRATION_EMAIL_CONFIRMATION, + ])); + + $this->assertInstanceOf(confirmations\ForgotPassword::class, EmailActivation::findOne([ + 'type' => EmailActivation::TYPE_FORGOT_PASSWORD_KEY, + ])); + + $this->assertInstanceOf(confirmations\CurrentEmailConfirmation::class, EmailActivation::findOne([ + 'type' => EmailActivation::TYPE_CURRENT_EMAIL_CONFIRMATION, + ])); + + $this->assertInstanceOf(confirmations\NewEmailConfirmation::class, EmailActivation::findOne([ + 'type' => EmailActivation::TYPE_NEW_EMAIL_CONFIRMATION, + ])); } } diff --git a/tests/codeception/common/unit/validators/LanguageValidatorTest.php b/tests/codeception/common/unit/validators/LanguageValidatorTest.php index 5d1b0ea..e40e72c 100644 --- a/tests/codeception/common/unit/validators/LanguageValidatorTest.php +++ b/tests/codeception/common/unit/validators/LanguageValidatorTest.php @@ -11,25 +11,18 @@ class LanguageValidatorTest extends TestCase { use ProtectedCaller; public function testGetFilesNames() { - $this->specify('get list of 2 languages: ru and en', function() { - $model = $this->createModelWithFixturePath(); - expect($this->callProtected($model, 'getFilesNames'))->equals(['en', 'ru']); - }); + $model = $this->createModelWithFixturePath(); + $this->assertEquals(['en', 'ru'], $this->callProtected($model, 'getFilesNames')); } - public function testValidateValue() { - $this->specify('get null, because language is supported', function() { - $model = $this->createModelWithFixturePath(); - expect($this->callProtected($model, 'validateValue', 'ru'))->null(); - }); + public function testValidateValueSupportedLanguage() { + $model = $this->createModelWithFixturePath(); + $this->assertNull($this->callProtected($model, 'validateValue', 'ru')); + } - $this->specify('get error message, because language is unsupported', function() { - $model = $this->createModelWithFixturePath(); - expect($this->callProtected($model, 'validateValue', 'by'))->equals([ - $model->message, - [], - ]); - }); + public function testValidateNotSupportedLanguage() { + $model = $this->createModelWithFixturePath(); + $this->assertEquals([$model->message, []], $this->callProtected($model, 'validateValue', 'by')); } /**