Upgrade Codeception to 3 version. Remove codeception/verify.

This commit is contained in:
ErickSkrauch
2019-05-14 01:58:29 +03:00
parent 5dacd66fb7
commit 75fdd5d1ba
35 changed files with 737 additions and 291 deletions

View File

@@ -1,9 +1,12 @@
<?php
declare(strict_types=1);
namespace common\tests\unit;
use Codeception\Test\Unit;
use Mockery;
class TestCase extends \Codeception\Test\Unit {
class TestCase extends Unit {
/**
* @var \common\tests\UnitTester
@@ -22,7 +25,7 @@ class TestCase extends \Codeception\Test\Unit {
*
* @return array
*/
public function _fixtures() {
public function _fixtures(): array {
return [];
}

View File

@@ -33,7 +33,7 @@ class DataBehaviorTest extends TestCase {
$model = $this->createModel();
/** @var DataBehavior $behavior */
$behavior = $model->behaviors['dataBehavior'];
expect($this->callProtected($behavior, 'getData'))->equals([]);
$this->assertSame([], $this->callProtected($behavior, 'getData'));
});
$this->specify('getting value from serialized data field should return encoded value', function() {
@@ -42,7 +42,7 @@ class DataBehaviorTest extends TestCase {
$model->_data = serialize($data);
/** @var DataBehavior $behavior */
$behavior = $model->behaviors['dataBehavior'];
expect($this->callProtected($behavior, 'getData'))->equals($data);
$this->assertSame($data, $this->callProtected($behavior, 'getData'));
});
$this->specify('getting value from invalid serialization string', function() {

View File

@@ -21,24 +21,24 @@ class EmailActivationExpirationBehaviorTest extends TestCase {
public function testCompareTime() {
$this->specify('expect false, if passed value is less then 0', function() {
$behavior = $this->createBehavior();
expect($this->callProtected($behavior, 'compareTime', -1))->false();
$this->assertFalse($this->callProtected($behavior, 'compareTime', -1));
});
$this->specify('expect true, if passed value is equals 0', function() {
$behavior = $this->createBehavior();
expect($this->callProtected($behavior, 'compareTime', 0))->true();
$this->assertTrue($this->callProtected($behavior, 'compareTime', 0));
});
$this->specify('expect true, if passed value is more than 0 and current time is greater then calculated', function() {
$behavior = $this->createBehavior();
$behavior->owner->created_at = time() - 10;
expect($this->callProtected($behavior, 'compareTime', 5))->true();
$this->assertTrue($this->callProtected($behavior, 'compareTime', 5));
});
$this->specify('expect false, if passed value is more than 0 and current time is less then calculated', function() {
$behavior = $this->createBehavior();
$behavior->owner->created_at = time() - 2;
expect($this->callProtected($behavior, 'compareTime', 7))->false();
$this->assertFalse($this->callProtected($behavior, 'compareTime', 7));
});
}
@@ -47,14 +47,14 @@ class EmailActivationExpirationBehaviorTest extends TestCase {
$behavior = $this->createBehavior();
$behavior->repeatTimeout = 30;
$behavior->owner->created_at = time() - 60;
expect($behavior->canRepeat())->true();
$this->assertTrue($behavior->canRepeat());
});
$this->specify('we cannot repeat, if created_at + repeatTimeout is less, then current time', function() {
$behavior = $this->createBehavior();
$behavior->repeatTimeout = 60;
$behavior->owner->created_at = time() - 30;
expect($behavior->canRepeat())->false();
$this->assertFalse($behavior->canRepeat());
});
}
@@ -63,14 +63,14 @@ class EmailActivationExpirationBehaviorTest extends TestCase {
$behavior = $this->createBehavior();
$behavior->expirationTimeout = 30;
$behavior->owner->created_at = time() - 60;
expect($behavior->isExpired())->true();
$this->assertTrue($behavior->isExpired());
});
$this->specify('key is not expired, if created_at + expirationTimeout is less, then current time', function() {
$behavior = $this->createBehavior();
$behavior->expirationTimeout = 60;
$behavior->owner->created_at = time() - 30;
expect($behavior->isExpired())->false();
$this->assertFalse($behavior->isExpired());
});
}
@@ -79,7 +79,7 @@ class EmailActivationExpirationBehaviorTest extends TestCase {
$behavior = $this->createBehavior();
$behavior->repeatTimeout = 30;
$behavior->owner->created_at = time() - 60;
expect($behavior->canRepeatIn())->equals($behavior->owner->created_at + $behavior->repeatTimeout);
$this->assertSame($behavior->owner->created_at + $behavior->repeatTimeout, $behavior->canRepeatIn());
});
}
@@ -88,7 +88,7 @@ class EmailActivationExpirationBehaviorTest extends TestCase {
$behavior = $this->createBehavior();
$behavior->expirationTimeout = 30;
$behavior->owner->created_at = time() - 60;
expect($behavior->expireIn())->equals($behavior->owner->created_at + $behavior->expirationTimeout);
$this->assertSame($behavior->owner->created_at + $behavior->expirationTimeout, $behavior->expireIn());
});
}

View File

@@ -12,7 +12,7 @@ class PrimaryKeyValueBehaviorTest extends TestCase {
public function testRefreshPrimaryKeyValue() {
$this->specify('method should generate value for primary key field on call', function() {
$model = new DummyModel();
/** @var PrimaryKeyValueBehavior|\PHPUnit_Framework_MockObject_MockObject $behavior */
/** @var PrimaryKeyValueBehavior|\PHPUnit\Framework\MockObject\MockObject $behavior */
$behavior = $this->getMockBuilder(PrimaryKeyValueBehavior::class)
->setMethods(['isValueExists'])
->setConstructorArgs([[
@@ -28,12 +28,12 @@ class PrimaryKeyValueBehaviorTest extends TestCase {
$model->attachBehavior('primary-key-value-behavior', $behavior);
$behavior->setPrimaryKeyValue();
expect($model->id)->equals('mock');
$this->assertSame('mock', $model->id);
});
$this->specify('method should repeat value generation if generated value duplicate with exists', function() {
$model = new DummyModel();
/** @var PrimaryKeyValueBehavior|\PHPUnit_Framework_MockObject_MockObject $behavior */
/** @var PrimaryKeyValueBehavior|\PHPUnit\Framework\MockObject\MockObject $behavior */
$behavior = $this->getMockBuilder(PrimaryKeyValueBehavior::class)
->setMethods(['isValueExists', 'generateValue'])
->setConstructorArgs([[
@@ -53,7 +53,7 @@ class PrimaryKeyValueBehaviorTest extends TestCase {
$model->attachBehavior('primary-key-value-behavior', $behavior);
$behavior->setPrimaryKeyValue();
expect($model->id)->equals('3');
$this->assertSame('3', $model->id);
});
}

View File

@@ -32,16 +32,16 @@ class AccountTest extends TestCase {
'email' => 'erick@skrauch.net',
'password_hash' => UserPass::make('erick@skrauch.net', '12345678'),
]);
expect('valid password should pass', $model->validatePassword('12345678', Account::PASS_HASH_STRATEGY_OLD_ELY))->true();
expect('invalid password should fail', $model->validatePassword('87654321', Account::PASS_HASH_STRATEGY_OLD_ELY))->false();
$this->assertTrue($model->validatePassword('12345678', Account::PASS_HASH_STRATEGY_OLD_ELY), 'valid password should pass');
$this->assertFalse($model->validatePassword('87654321', Account::PASS_HASH_STRATEGY_OLD_ELY), 'invalid password should fail');
});
$this->specify('modern hash algorithm should work', function() {
$model = new Account([
'password_hash' => Yii::$app->security->generatePasswordHash('12345678'),
]);
expect('valid password should pass', $model->validatePassword('12345678', Account::PASS_HASH_STRATEGY_YII2))->true();
expect('invalid password should fail', $model->validatePassword('87654321', Account::PASS_HASH_STRATEGY_YII2))->false();
$this->assertTrue($model->validatePassword('12345678', Account::PASS_HASH_STRATEGY_YII2), 'valid password should pass');
$this->assertFalse($model->validatePassword('87654321', Account::PASS_HASH_STRATEGY_YII2), 'invalid password should fail');
});
$this->specify('if second argument is not pass model value should be used', function() {
@@ -50,15 +50,15 @@ class AccountTest extends TestCase {
'password_hash_strategy' => Account::PASS_HASH_STRATEGY_OLD_ELY,
'password_hash' => UserPass::make('erick@skrauch.net', '12345678'),
]);
expect('valid password should pass', $model->validatePassword('12345678'))->true();
expect('invalid password should fail', $model->validatePassword('87654321'))->false();
$this->assertTrue($model->validatePassword('12345678'), 'valid password should pass');
$this->assertFalse($model->validatePassword('87654321'), 'invalid password should fail');
$model = new Account([
'password_hash_strategy' => Account::PASS_HASH_STRATEGY_YII2,
'password_hash' => Yii::$app->security->generatePasswordHash('12345678'),
]);
expect('valid password should pass', $model->validatePassword('12345678'))->true();
expect('invalid password should fail', $model->validatePassword('87654321'))->false();
$this->assertTrue($model->validatePassword('12345678'), 'valid password should pass');
$this->assertFalse($model->validatePassword('87654321'), 'invalid password should fail');
});
}
@@ -70,13 +70,13 @@ class AccountTest extends TestCase {
$this->specify('Expect true if collision with current username', function() {
$model = new Account();
$model->username = 'ErickSkrauch';
expect($model->hasMojangUsernameCollision())->true();
$this->assertTrue($model->hasMojangUsernameCollision());
});
$this->specify('Expect false if some rare username without any collision on Mojang', function() {
$model = new Account();
$model->username = 'rare-username';
expect($model->hasMojangUsernameCollision())->false();
$this->assertFalse($model->hasMojangUsernameCollision());
});
}
@@ -89,19 +89,19 @@ class AccountTest extends TestCase {
public function testIsAgreedWithActualRules() {
$this->specify('get false, if rules field set in null', function() {
$model = new Account();
expect($model->isAgreedWithActualRules())->false();
$this->assertFalse($model->isAgreedWithActualRules());
});
$this->specify('get false, if rules field have version less, then actual', function() {
$model = new Account();
$model->rules_agreement_version = 0;
expect($model->isAgreedWithActualRules())->false();
$this->assertFalse($model->isAgreedWithActualRules());
});
$this->specify('get true, if rules field have equals rules version', function() {
$model = new Account();
$model->rules_agreement_version = LATEST_RULES_VERSION;
expect($model->isAgreedWithActualRules())->true();
$this->assertTrue($model->isAgreedWithActualRules());
});
}

View File

@@ -8,7 +8,7 @@ use common\tests\unit\TestCase;
class EmailActivationTest extends TestCase {
public function _fixtures() {
public function _fixtures(): array {
return [
'emailActivations' => EmailActivationFixture::class,
];

View File

@@ -7,7 +7,7 @@ use common\tests\unit\TestCase;
class OauthClientQueryTest extends TestCase {
public function _fixtures() {
public function _fixtures(): array {
return [
'oauthClients' => OauthClientFixture::class,
];

View File

@@ -14,7 +14,7 @@ use const common\LATEST_RULES_VERSION;
class OauthClientOwnerTest extends TestCase {
public function _fixtures() {
public function _fixtures(): array {
return [
'oauthClients' => OauthClientFixture::class,
];

View File

@@ -14,7 +14,7 @@ use yii\queue\Queue;
*/
class ClearAccountSessionsTest extends TestCase {
public function _fixtures() {
public function _fixtures(): array {
return [
'accounts' => fixtures\AccountFixture::class,
'oauthSessions' => fixtures\OauthSessionFixture::class,

View File

@@ -10,7 +10,7 @@ use yii\queue\Queue;
class ClearOauthSessionsTest extends TestCase {
public function _fixtures() {
public function _fixtures(): array {
return [
'oauthClients' => fixtures\OauthClientFixture::class,
'oauthSessions' => fixtures\OauthSessionFixture::class,

View File

@@ -24,7 +24,7 @@ class PullMojangUsernameTest extends TestCase {
/** @var \PHPUnit\Framework\MockObject\Builder\InvocationMocker */
private $mockedMethod;
public function _fixtures() {
public function _fixtures(): array {
return [
'mojangUsernames' => MojangUsernameFixture::class,
];