Commit 9bde3ab6 by Qiang Xue

Merge branch 'tests_improved_verify' of github.com:Ragazzo/yii2 into Ragazzo-tests_improved_verify

Conflicts: apps/basic/tests/README.md apps/basic/tests/unit/models/LoginFormTest.php
parents 3bf072a7 ee0c105b
......@@ -3,7 +3,13 @@ These tests are developed with [Codeception PHP Testing Framework](http://codece
After creating the basic application, follow these steps to prepare for the tests:
1. In the file `_bootstrap.php`, modify the definition of the constant `TEST_ENTRY_URL` so
1. To install `Codeception` and its dependencies through composer, run the following commands:
```
php composer.phar require --dev "codeception/codeception *" "codeception/specify *" "codeception/verify *"
```
2. In the file `_bootstrap.php`, modify the definition of the constant `TEST_ENTRY_URL` so
that it points to the correct entry script URL.
2. Go to the application base directory and build the test suites:
......
......@@ -39,15 +39,16 @@ class ContactFormTest extends TestCase
$model->contact('admin@example.com');
$this->specify('email should be send', function () {
$this->assertFileExists($this->getMessageFile(), 'email file should exist');
expect('email file should exist', file_exists($this->getMessageFile()))->true();
});
$this->specify('message should contain correct data', function () use($model) {
$emailMessage = file_get_contents($this->getMessageFile());
$this->assertContains($model->name, $emailMessage, 'email should contain user name');
$this->assertContains($model->email, $emailMessage, 'email should contain sender email');
$this->assertContains($model->subject, $emailMessage, 'email should contain subject');
$this->assertContains($model->body, $emailMessage, 'email should contain body');
expect('email should contain user name', $emailMessage)->contains($model->name);
expect('email should contain sender email', $emailMessage)->contains($model->email);
expect('email should contain subject', $emailMessage)->contains($model->subject);
expect('email should contain body', $emailMessage)->contains($model->body);
});
}
......
......@@ -19,8 +19,8 @@ class LoginFormTest extends TestCase
$model->password = 'some_password';
$this->specify('user should not be able to login, when there is no identity' , function () use ($model) {
$this->assertFalse($model->login());
$this->assertTrue(Yii::$app->user->isGuest,'user should not be logged in');
expect('model should not login user', $model->login())->false();
expect('user should not be logged in', Yii::$app->user->isGuest)->true();
});
}
......@@ -32,9 +32,9 @@ class LoginFormTest extends TestCase
$model->password = 'wrong-password';
$this->specify('user should not be able to login with wrong password', function () use ($model) {
$this->assertFalse($model->login());
$this->assertArrayHasKey('password', $model->errors);
$this->assertTrue(Yii::$app->user->isGuest, 'user should not be logged in');
expect('model should not login user', $model->login())->false();
expect('error message should be set', $model->errors)->hasKey('password');
expect('user should not be logged in', Yii::$app->user->isGuest)->true();
});
}
......@@ -46,9 +46,9 @@ class LoginFormTest extends TestCase
$model->password = 'demo';
$this->specify('user should be able to login with correct credentials', function() use ($model) {
$this->assertTrue($model->login());
$this->assertArrayNotHasKey('password', $model->errors);
$this->assertFalse(Yii::$app->user->isGuest,'user should be logged in');
expect('model should login user', $model->login())->true();
expect('error message should not be set', $model->errors)->hasntKey('password');
expect('user should be logged in', Yii::$app->user->isGuest)->false();
});
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment