Paul Klimov
11 years ago
67 changed files with 980 additions and 4384 deletions
@ -0,0 +1,11 @@ |
|||||||
|
<?php |
||||||
|
|
||||||
|
// configuration adjustments for codeception acceptance tests. Will be merged with web.php config. |
||||||
|
|
||||||
|
return [ |
||||||
|
'components' => [ |
||||||
|
'db' => [ |
||||||
|
'dsn' => 'mysql:host=localhost;dbname=yii2basic_acceptance', |
||||||
|
], |
||||||
|
], |
||||||
|
]; |
@ -0,0 +1,11 @@ |
|||||||
|
<?php |
||||||
|
|
||||||
|
// configuration adjustments for codeception functional tests. Will be merged with web.php config. |
||||||
|
|
||||||
|
return [ |
||||||
|
'components' => [ |
||||||
|
'db' => [ |
||||||
|
'dsn' => 'mysql:host=localhost;dbname=yii2basic_functional', |
||||||
|
], |
||||||
|
], |
||||||
|
]; |
@ -0,0 +1,15 @@ |
|||||||
|
<?php |
||||||
|
|
||||||
|
// configuration adjustments for codeception unit tests. Will be merged with web.php config. |
||||||
|
|
||||||
|
return [ |
||||||
|
'components' => [ |
||||||
|
'fixture' => [ |
||||||
|
'class' => 'yii\test\DbFixtureManager', |
||||||
|
'basePath' => '@tests/unit/fixtures', |
||||||
|
], |
||||||
|
'db' => [ |
||||||
|
'dsn' => 'mysql:host=localhost;dbname=yii2basic_unit', |
||||||
|
], |
||||||
|
], |
||||||
|
]; |
@ -1,7 +0,0 @@ |
|||||||
<?php |
|
||||||
|
|
||||||
$config = require(__DIR__ . '/web.php'); |
|
||||||
|
|
||||||
// ... customize $config for the "test" environment here... |
|
||||||
|
|
||||||
return $config; |
|
@ -0,0 +1,4 @@ |
|||||||
|
# these files are auto generated by codeception build |
||||||
|
/unit/CodeGuy.php |
||||||
|
/functional/TestGuy.php |
||||||
|
/acceptance/WebGuy.php |
@ -0,0 +1,9 @@ |
|||||||
|
<?php |
||||||
|
|
||||||
|
defined('YII_DEBUG') or define('YII_DEBUG', true); |
||||||
|
defined('YII_ENV') or define('YII_ENV', 'test'); |
||||||
|
|
||||||
|
require_once(__DIR__ . '/../vendor/autoload.php'); |
||||||
|
require_once(__DIR__ . '/../vendor/yiisoft/yii2/yii/Yii.php'); |
||||||
|
|
||||||
|
Yii::setAlias('@tests', __DIR__); |
@ -1,8 +1,7 @@ |
|||||||
<?php |
<?php |
||||||
namespace Codeception\Module; |
namespace Codeception\Module; |
||||||
|
|
||||||
// here you can define custom functions for CodeGuy |
|
||||||
|
|
||||||
class CodeHelper extends \Codeception\Module |
class CodeHelper extends \Codeception\Module |
||||||
{ |
{ |
||||||
|
// here you can define custom methods for CodeGuy |
||||||
} |
} |
||||||
|
@ -1,8 +1,7 @@ |
|||||||
<?php |
<?php |
||||||
namespace Codeception\Module; |
namespace Codeception\Module; |
||||||
|
|
||||||
// here you can define custom functions for TestGuy |
|
||||||
|
|
||||||
class TestHelper extends \Codeception\Module |
class TestHelper extends \Codeception\Module |
||||||
{ |
{ |
||||||
|
// here you can define custom methods for TestGuy |
||||||
} |
} |
||||||
|
@ -1,8 +1,7 @@ |
|||||||
<?php |
<?php |
||||||
namespace Codeception\Module; |
namespace Codeception\Module; |
||||||
|
|
||||||
// here you can define custom functions for WebGuy |
|
||||||
|
|
||||||
class WebHelper extends \Codeception\Module |
class WebHelper extends \Codeception\Module |
||||||
{ |
{ |
||||||
|
// here you can define custom methods for WebGuy |
||||||
} |
} |
||||||
|
@ -0,0 +1,10 @@ |
|||||||
|
<?php |
||||||
|
|
||||||
|
namespace tests\_pages; |
||||||
|
|
||||||
|
use yii\codeception\BasePage; |
||||||
|
|
||||||
|
class AboutPage extends BasePage |
||||||
|
{ |
||||||
|
public static $URL = '?r=site/about'; |
||||||
|
} |
@ -0,0 +1,58 @@ |
|||||||
|
<?php |
||||||
|
|
||||||
|
namespace tests\_pages; |
||||||
|
|
||||||
|
use yii\codeception\BasePage; |
||||||
|
|
||||||
|
class ContactPage extends BasePage |
||||||
|
{ |
||||||
|
public static $URL = '?r=site/contact'; |
||||||
|
|
||||||
|
/** |
||||||
|
* contact form name text field locator |
||||||
|
* @var string |
||||||
|
*/ |
||||||
|
public $name = 'input[name="ContactForm[name]"]'; |
||||||
|
/** |
||||||
|
* contact form email text field locator |
||||||
|
* @var string |
||||||
|
*/ |
||||||
|
public $email = 'input[name="ContactForm[email]"]'; |
||||||
|
/** |
||||||
|
* contact form subject text field locator |
||||||
|
* @var string |
||||||
|
*/ |
||||||
|
public $subject = 'input[name="ContactForm[subject]"]'; |
||||||
|
/** |
||||||
|
* contact form body textarea locator |
||||||
|
* @var string |
||||||
|
*/ |
||||||
|
public $body = 'textarea[name="ContactForm[body]"]'; |
||||||
|
/** |
||||||
|
* contact form verification code text field locator |
||||||
|
* @var string |
||||||
|
*/ |
||||||
|
public $verifyCode = 'input[name="ContactForm[verifyCode]"]'; |
||||||
|
/** |
||||||
|
* contact form submit button |
||||||
|
* @var string |
||||||
|
*/ |
||||||
|
public $button = 'button[type=submit]'; |
||||||
|
|
||||||
|
/** |
||||||
|
* |
||||||
|
* @param array $contactData |
||||||
|
*/ |
||||||
|
public function submit(array $contactData) |
||||||
|
{ |
||||||
|
if (!empty($contactData)) |
||||||
|
{ |
||||||
|
$this->guy->fillField($this->name, $contactData['name']); |
||||||
|
$this->guy->fillField($this->email, $contactData['email']); |
||||||
|
$this->guy->fillField($this->subject, $contactData['subject']); |
||||||
|
$this->guy->fillField($this->body, $contactData['body']); |
||||||
|
$this->guy->fillField($this->verifyCode, $contactData['verifyCode']); |
||||||
|
} |
||||||
|
$this->guy->click($this->button); |
||||||
|
} |
||||||
|
} |
@ -0,0 +1,38 @@ |
|||||||
|
<?php |
||||||
|
|
||||||
|
namespace tests\_pages; |
||||||
|
|
||||||
|
use yii\codeception\BasePage; |
||||||
|
|
||||||
|
class LoginPage extends BasePage |
||||||
|
{ |
||||||
|
public static $URL = '?r=site/login'; |
||||||
|
|
||||||
|
/** |
||||||
|
* login form username text field locator |
||||||
|
* @var string |
||||||
|
*/ |
||||||
|
public $username = 'input[name="LoginForm[username]"]'; |
||||||
|
/** |
||||||
|
* login form password text field locator |
||||||
|
* @var string |
||||||
|
*/ |
||||||
|
public $password = 'input[name="LoginForm[password]"]'; |
||||||
|
/** |
||||||
|
* login form submit button locator |
||||||
|
* @var string |
||||||
|
*/ |
||||||
|
public $button = 'button[type=submit]'; |
||||||
|
|
||||||
|
/** |
||||||
|
* |
||||||
|
* @param string $username |
||||||
|
* @param string $password |
||||||
|
*/ |
||||||
|
public function login($username, $password) |
||||||
|
{ |
||||||
|
$this->guy->fillField($this->username, $username); |
||||||
|
$this->guy->fillField($this->password, $password); |
||||||
|
$this->guy->click($this->button); |
||||||
|
} |
||||||
|
} |
@ -1,5 +1,8 @@ |
|||||||
<?php |
<?php |
||||||
|
|
||||||
|
use tests\_pages\AboutPage; |
||||||
|
|
||||||
$I = new WebGuy($scenario); |
$I = new WebGuy($scenario); |
||||||
$I->wantTo('ensure that about works'); |
$I->wantTo('ensure that about works'); |
||||||
$I->amOnPage('?r=site/about'); |
$I->amOnPage(AboutPage::$URL); |
||||||
$I->see('About', 'h1'); |
$I->see('About', 'h1'); |
||||||
|
@ -1,23 +1,29 @@ |
|||||||
<?php |
<?php |
||||||
|
|
||||||
|
use tests\_pages\LoginPage; |
||||||
|
|
||||||
$I = new WebGuy($scenario); |
$I = new WebGuy($scenario); |
||||||
$I->wantTo('ensure that login works'); |
$I->wantTo('ensure that login works'); |
||||||
$I->amOnPage('?r=site/login'); |
$loginPage = LoginPage::of($I); |
||||||
|
|
||||||
|
$I->amOnPage(LoginPage::$URL); |
||||||
$I->see('Login', 'h1'); |
$I->see('Login', 'h1'); |
||||||
|
|
||||||
$I->submitForm('#login-form', []); |
$I->amGoingTo('try to login with empty credentials'); |
||||||
$I->dontSee('Logout (admin)'); |
$loginPage->login('', ''); |
||||||
$I->see('Username cannot be blank'); |
$I->expectTo('see validations errors'); |
||||||
$I->see('Password cannot be blank'); |
$I->see('Username cannot be blank.'); |
||||||
|
$I->see('Password cannot be blank.'); |
||||||
|
|
||||||
$I->submitForm('#login-form', [ |
$I->amGoingTo('try to login with wrong credentials'); |
||||||
'LoginForm[username]' => 'admin', |
$loginPage->login('admin', 'wrong'); |
||||||
'LoginForm[password]' => 'wrong', |
$I->expectTo('see validations errors'); |
||||||
]); |
$I->see('Incorrect username or password.'); |
||||||
$I->dontSee('Logout (admin)'); |
|
||||||
$I->see('Incorrect username or password'); |
|
||||||
|
|
||||||
$I->submitForm('#login-form', [ |
$I->amGoingTo('try to login with correct credentials'); |
||||||
'LoginForm[username]' => 'admin', |
$loginPage->login('admin', 'admin'); |
||||||
'LoginForm[password]' => 'admin', |
if (method_exists($I, 'wait')) { |
||||||
]); |
$I->wait(3); // only for selenium |
||||||
|
} |
||||||
|
$I->expectTo('see user info'); |
||||||
$I->see('Logout (admin)'); |
$I->see('Logout (admin)'); |
||||||
|
File diff suppressed because it is too large
Load Diff
@ -1,2 +1,8 @@ |
|||||||
<?php |
<?php |
||||||
// Here you can initialize variables that will for your tests |
|
||||||
|
$config = yii\helpers\ArrayHelper::merge( |
||||||
|
require(__DIR__ . '/../../config/web.php'), |
||||||
|
require(__DIR__ . '/../../config/codeception/acceptance.php') |
||||||
|
); |
||||||
|
|
||||||
|
$application = new yii\web\Application($config); |
||||||
|
@ -1,5 +1,8 @@ |
|||||||
<?php |
<?php |
||||||
|
|
||||||
|
use tests\_pages\AboutPage; |
||||||
|
|
||||||
$I = new TestGuy($scenario); |
$I = new TestGuy($scenario); |
||||||
$I->wantTo('ensure that about works'); |
$I->wantTo('ensure that about works'); |
||||||
$I->amOnPage('?r=site/about'); |
$I->amOnPage(AboutPage::$URL); |
||||||
$I->see('About', 'h1'); |
$I->see('About', 'h1'); |
||||||
|
@ -1,23 +1,26 @@ |
|||||||
<?php |
<?php |
||||||
|
|
||||||
|
use tests\functional\_pages\LoginPage; |
||||||
|
|
||||||
$I = new TestGuy($scenario); |
$I = new TestGuy($scenario); |
||||||
$I->wantTo('ensure that login works'); |
$I->wantTo('ensure that login works'); |
||||||
$I->amOnPage('?r=site/login'); |
$loginPage = LoginPage::of($I); |
||||||
|
|
||||||
|
$I->amOnPage(LoginPage::$URL); |
||||||
$I->see('Login', 'h1'); |
$I->see('Login', 'h1'); |
||||||
|
|
||||||
$I->submitForm('#login-form', []); |
$I->amGoingTo('try to login with empty credentials'); |
||||||
$I->dontSee('Logout (admin)'); |
$loginPage->login('', ''); |
||||||
$I->see('Username cannot be blank'); |
$I->expectTo('see validations errors'); |
||||||
$I->see('Password cannot be blank'); |
$I->see('Username cannot be blank.'); |
||||||
|
$I->see('Password cannot be blank.'); |
||||||
|
|
||||||
$I->submitForm('#login-form', [ |
$I->amGoingTo('try to login with wrong credentials'); |
||||||
'LoginForm[username]' => 'admin', |
$loginPage->login('admin', 'wrong'); |
||||||
'LoginForm[password]' => 'wrong', |
$I->expectTo('see validations errors'); |
||||||
]); |
$I->see('Incorrect username or password.'); |
||||||
$I->dontSee('Logout (admin)'); |
|
||||||
$I->see('Incorrect username or password'); |
|
||||||
|
|
||||||
$I->submitForm('#login-form', [ |
$I->amGoingTo('try to login with correct credentials'); |
||||||
'LoginForm[username]' => 'admin', |
$loginPage->login('admin', 'admin'); |
||||||
'LoginForm[password]' => 'admin', |
$I->expectTo('see user info'); |
||||||
]); |
|
||||||
$I->see('Logout (admin)'); |
$I->see('Logout (admin)'); |
||||||
|
File diff suppressed because it is too large
Load Diff
@ -1,2 +1,8 @@ |
|||||||
<?php |
<?php |
||||||
// Here you can initialize variables that will for your tests |
|
||||||
|
$config = yii\helpers\ArrayHelper::merge( |
||||||
|
require(__DIR__ . '/../../config/web.php'), |
||||||
|
require(__DIR__ . '/../../config/codeception/functional.php') |
||||||
|
); |
||||||
|
|
||||||
|
$application = new yii\web\Application($config); |
||||||
|
@ -0,0 +1,51 @@ |
|||||||
|
<?php |
||||||
|
|
||||||
|
namespace tests\functional\_pages; |
||||||
|
|
||||||
|
class ContactPage extends \tests\_pages\ContactPage |
||||||
|
{ |
||||||
|
/** |
||||||
|
* contact form name text field locator |
||||||
|
* @var string |
||||||
|
*/ |
||||||
|
public $name = 'ContactForm[name]'; |
||||||
|
/** |
||||||
|
* contact form email text field locator |
||||||
|
* @var string |
||||||
|
*/ |
||||||
|
public $email = 'ContactForm[email]'; |
||||||
|
/** |
||||||
|
* contact form subject text field locator |
||||||
|
* @var string |
||||||
|
*/ |
||||||
|
public $subject = 'ContactForm[subject]'; |
||||||
|
/** |
||||||
|
* contact form body textarea locator |
||||||
|
* @var string |
||||||
|
*/ |
||||||
|
public $body = 'ContactForm[body]'; |
||||||
|
/** |
||||||
|
* contact form verification code text field locator |
||||||
|
* @var string |
||||||
|
*/ |
||||||
|
public $verifyCode = 'ContactForm[verifyCode]'; |
||||||
|
|
||||||
|
/** |
||||||
|
* |
||||||
|
* @param array $contactData |
||||||
|
*/ |
||||||
|
public function submit(array $contactData) |
||||||
|
{ |
||||||
|
if (empty($contactData)) { |
||||||
|
$this->guy->submitForm('#contact-form', []); |
||||||
|
} else { |
||||||
|
$this->guy->submitForm('#contact-form', [ |
||||||
|
$this->name => $contactData['name'], |
||||||
|
$this->email => $contactData['email'], |
||||||
|
$this->subject => $contactData['subject'], |
||||||
|
$this->body => $contactData['body'], |
||||||
|
$this->verifyCode => $contactData['verifyCode'], |
||||||
|
]); |
||||||
|
} |
||||||
|
} |
||||||
|
} |
@ -0,0 +1,30 @@ |
|||||||
|
<?php |
||||||
|
|
||||||
|
namespace tests\functional\_pages; |
||||||
|
|
||||||
|
class LoginPage extends \tests\_pages\LoginPage |
||||||
|
{ |
||||||
|
/** |
||||||
|
* login form username text field locator |
||||||
|
* @var string |
||||||
|
*/ |
||||||
|
public $username = 'LoginForm[username]'; |
||||||
|
/** |
||||||
|
* login form password text field locator |
||||||
|
* @var string |
||||||
|
*/ |
||||||
|
public $password = 'LoginForm[password]'; |
||||||
|
|
||||||
|
/** |
||||||
|
* |
||||||
|
* @param string $username |
||||||
|
* @param string $password |
||||||
|
*/ |
||||||
|
public function login($username, $password) |
||||||
|
{ |
||||||
|
$this->guy->submitForm('#login-form', [ |
||||||
|
$this->username => $username, |
||||||
|
$this->password => $password, |
||||||
|
]); |
||||||
|
} |
||||||
|
} |
@ -1,30 +0,0 @@ |
|||||||
<?php |
|
||||||
// This class was automatically generated by build task |
|
||||||
// You should not change it manually as it will be overwritten on next build |
|
||||||
// @codingStandardsIgnoreFile |
|
||||||
|
|
||||||
|
|
||||||
use \Codeception\Maybe; |
|
||||||
use Codeception\Module\CodeHelper; |
|
||||||
|
|
||||||
/** |
|
||||||
* Inherited methods |
|
||||||
* @method void execute($callable) |
|
||||||
* @method void wantToTest($text) |
|
||||||
* @method void wantTo($text) |
|
||||||
* @method void expectTo($prediction) |
|
||||||
* @method void expect($prediction) |
|
||||||
* @method void amGoingTo($argumentation) |
|
||||||
* @method void am($role) |
|
||||||
* @method void lookForwardTo($achieveValue) |
|
||||||
* @method void offsetGet($offset) |
|
||||||
* @method void offsetSet($offset, $value) |
|
||||||
* @method void offsetExists($offset) |
|
||||||
* @method void offsetUnset($offset) |
|
||||||
*/ |
|
||||||
|
|
||||||
class CodeGuy extends \Codeception\AbstractGuy |
|
||||||
{ |
|
||||||
|
|
||||||
} |
|
||||||
|
|
@ -1,2 +1,8 @@ |
|||||||
<?php |
<?php |
||||||
// Here you can initialize variables that will for your tests |
|
||||||
|
// add unit testing specific bootstrap code here |
||||||
|
|
||||||
|
yii\codeception\TestCase::$applicationConfig = yii\helpers\ArrayHelper::merge( |
||||||
|
require(__DIR__ . '/../../config/web.php'), |
||||||
|
require(__DIR__ . '/../../config/codeception/unit.php') |
||||||
|
); |
@ -0,0 +1,10 @@ |
|||||||
|
<?php |
||||||
|
|
||||||
|
namespace tests\unit\models; |
||||||
|
|
||||||
|
use yii\codeception\TestCase; |
||||||
|
|
||||||
|
class ContactFormTest extends TestCase |
||||||
|
{ |
||||||
|
// TODO add test methods here |
||||||
|
} |
@ -0,0 +1,10 @@ |
|||||||
|
<?php |
||||||
|
|
||||||
|
namespace tests\unit\models; |
||||||
|
|
||||||
|
use yii\codeception\TestCase; |
||||||
|
|
||||||
|
class LoginFormTest extends TestCase |
||||||
|
{ |
||||||
|
// TODO add test methods here |
||||||
|
} |
@ -0,0 +1,20 @@ |
|||||||
|
<?php |
||||||
|
|
||||||
|
namespace tests\unit\models; |
||||||
|
|
||||||
|
use yii\codeception\TestCase; |
||||||
|
use yii\test\DbTestTrait; |
||||||
|
|
||||||
|
class UserTest extends TestCase |
||||||
|
{ |
||||||
|
use DbTestTrait; |
||||||
|
|
||||||
|
protected function setUp() |
||||||
|
{ |
||||||
|
parent::setUp(); |
||||||
|
// uncomment the following to load fixtures for table tbl_user |
||||||
|
//$this->loadFixtures(['tbl_user']); |
||||||
|
} |
||||||
|
|
||||||
|
// TODO add test methods here |
||||||
|
} |
@ -0,0 +1,17 @@ |
|||||||
|
<?php |
||||||
|
|
||||||
|
// NOTE: Make sure this file is not accessable when deployed to production |
||||||
|
|
||||||
|
defined('YII_DEBUG') or define('YII_DEBUG', true); |
||||||
|
defined('YII_ENV') or define('YII_ENV', 'test'); |
||||||
|
|
||||||
|
require(__DIR__ . '/../vendor/autoload.php'); |
||||||
|
require(__DIR__ . '/../vendor/yiisoft/yii2/yii/Yii.php'); |
||||||
|
|
||||||
|
$config = yii\helpers\ArrayHelper::merge( |
||||||
|
require(__DIR__ . '/../config/web.php'), |
||||||
|
require(__DIR__ . '/../config/codeception/acceptance.php') |
||||||
|
); |
||||||
|
|
||||||
|
$application = new yii\web\Application($config); |
||||||
|
$application->run(); |
@ -0,0 +1,11 @@ |
|||||||
|
<?php |
||||||
|
|
||||||
|
// this file is used as the entry script for codeception functional testing |
||||||
|
|
||||||
|
$config = yii\helpers\ArrayHelper::merge( |
||||||
|
require(__DIR__ . '/../config/web.php'), |
||||||
|
require(__DIR__ . '/../config/codeception/functional.php') |
||||||
|
); |
||||||
|
|
||||||
|
$config['class'] = 'yii\web\Application'; |
||||||
|
return $config; |
@ -1,24 +0,0 @@ |
|||||||
<?php |
|
||||||
|
|
||||||
if (!in_array(@$_SERVER['REMOTE_ADDR'], ['127.0.0.1', '::1'])) { |
|
||||||
die('You are not allowed to access this file.'); |
|
||||||
} |
|
||||||
|
|
||||||
defined('YII_DEBUG') or define('YII_DEBUG', true); |
|
||||||
|
|
||||||
defined('YII_ENV') or define('YII_ENV', 'test'); |
|
||||||
|
|
||||||
require_once(__DIR__ . '/../vendor/autoload.php'); |
|
||||||
require_once(__DIR__ . '/../vendor/yiisoft/yii2/yii/Yii.php'); |
|
||||||
|
|
||||||
$config = require(__DIR__ . '/../config/web-test.php'); |
|
||||||
|
|
||||||
if (isset($this)) { |
|
||||||
// run in functional tests |
|
||||||
$config['class'] = 'yii\web\Application'; |
|
||||||
return $config; |
|
||||||
} else { |
|
||||||
// run in acceptance tests |
|
||||||
$application = new yii\web\Application($config); |
|
||||||
$application->run(); |
|
||||||
} |
|
@ -0,0 +1,55 @@ |
|||||||
|
<?php |
||||||
|
|
||||||
|
namespace yii\codeception; |
||||||
|
|
||||||
|
/** |
||||||
|
* Represents a web page to test |
||||||
|
* |
||||||
|
* Pages extend from this class and declare UI map for this page via |
||||||
|
* static properties. CSS or XPath allowed. |
||||||
|
* |
||||||
|
* Here is an example: |
||||||
|
* |
||||||
|
* ```php |
||||||
|
* public static $usernameField = '#username'; |
||||||
|
* public static $formSubmitButton = "#mainForm input[type=submit]"; |
||||||
|
* ``` |
||||||
|
* |
||||||
|
* @author Mark Jebri <mark.github@yandex.ru> |
||||||
|
* @since 2.0 |
||||||
|
*/ |
||||||
|
abstract class BasePage |
||||||
|
{ |
||||||
|
/** |
||||||
|
* @var string include url of current page. This property has to be overwritten by subclasses |
||||||
|
*/ |
||||||
|
public static $URL = ''; |
||||||
|
/** |
||||||
|
* @var \Codeception\AbstractGuy |
||||||
|
*/ |
||||||
|
protected $guy; |
||||||
|
|
||||||
|
public function __construct($I) |
||||||
|
{ |
||||||
|
$this->guy = $I; |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* Basic route example for your current URL |
||||||
|
* You can append any additional parameter to URL |
||||||
|
* and use it in tests like: EditPage::route('/123-post'); |
||||||
|
*/ |
||||||
|
public static function route($param) |
||||||
|
{ |
||||||
|
return static::$URL.$param; |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* @param $I |
||||||
|
* @return static |
||||||
|
*/ |
||||||
|
public static function of($I) |
||||||
|
{ |
||||||
|
return new static($I); |
||||||
|
} |
||||||
|
} |
@ -0,0 +1,7 @@ |
|||||||
|
Yii Framework 2 Codeception extension Change Log |
||||||
|
================================================ |
||||||
|
|
||||||
|
2.0.0 beta under development |
||||||
|
---------------------------- |
||||||
|
|
||||||
|
- Initial release. |
@ -0,0 +1,32 @@ |
|||||||
|
The Yii framework is free software. It is released under the terms of |
||||||
|
the following BSD License. |
||||||
|
|
||||||
|
Copyright © 2008-2013 by Yii Software LLC (http://www.yiisoft.com) |
||||||
|
All rights reserved. |
||||||
|
|
||||||
|
Redistribution and use in source and binary forms, with or without |
||||||
|
modification, are permitted provided that the following conditions |
||||||
|
are met: |
||||||
|
|
||||||
|
* Redistributions of source code must retain the above copyright |
||||||
|
notice, this list of conditions and the following disclaimer. |
||||||
|
* Redistributions in binary form must reproduce the above copyright |
||||||
|
notice, this list of conditions and the following disclaimer in |
||||||
|
the documentation and/or other materials provided with the |
||||||
|
distribution. |
||||||
|
* Neither the name of Yii Software LLC nor the names of its |
||||||
|
contributors may be used to endorse or promote products derived |
||||||
|
from this software without specific prior written permission. |
||||||
|
|
||||||
|
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
||||||
|
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
||||||
|
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS |
||||||
|
FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE |
||||||
|
COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, |
||||||
|
INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, |
||||||
|
BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; |
||||||
|
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER |
||||||
|
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT |
||||||
|
LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN |
||||||
|
ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
||||||
|
POSSIBILITY OF SUCH DAMAGE. |
@ -0,0 +1,128 @@ |
|||||||
|
Codeception Extension for Yii 2 |
||||||
|
=============================== |
||||||
|
|
||||||
|
This extension provides a `Codeception` mail solution for Yii 2. It includes some classes that are useful |
||||||
|
for unit-testing (```TestCase```) or for codeception page-objects (```BasePage```). |
||||||
|
|
||||||
|
When using codeception page-objects they have some similar code, this code was extracted and put into the ```BasePage``` |
||||||
|
class to reduce code duplication. Simply extend your page object from this class, like it is done in ```yii2-basic``` and |
||||||
|
```yii2-advanced``` boilerplates. |
||||||
|
|
||||||
|
For unit testing there is a ```TestCase``` class which holds some common features like application creation before each test |
||||||
|
and application destroy after each test. You can configure your application by this class. ```TestCase``` is extended from ```PHPUnit_Framework_TestCase``` so all |
||||||
|
methods and assertions are available. |
||||||
|
|
||||||
|
```php |
||||||
|
SomeConsoleTest extends yii\codeception\TestCase |
||||||
|
{ |
||||||
|
# by default it is @tests/unit/_bootstrap.php which holds some basic things like: |
||||||
|
# including composer autoload, include BaseYii class. |
||||||
|
public $baseConfig = '@app/config/console.php'; |
||||||
|
|
||||||
|
public $applicationClass = 'yii\console\Application'; |
||||||
|
} |
||||||
|
``` |
||||||
|
Dont forget that you still need to include autoload and BaseYii class, like in the _bootstrap.php file (comments above). |
||||||
|
|
||||||
|
You also can reconfigure some components for tests, for this purpose there is a ```$config``` property in the testcase. |
||||||
|
|
||||||
|
```php |
||||||
|
SomeOtherTest extends yii\codeception\TestCase |
||||||
|
{ |
||||||
|
public $config = [ |
||||||
|
'components' => [ |
||||||
|
'mail' => [ |
||||||
|
'useFileTransport' => true, |
||||||
|
], |
||||||
|
] |
||||||
|
]; |
||||||
|
} |
||||||
|
``` |
||||||
|
|
||||||
|
Because of Codeception buffers all output you cant make simple ```var_dump()``` in the TestCase, instead you need to use |
||||||
|
```Codeception\Util\Debug::debug()``` function and then run test with ```--debug``` key, for example: |
||||||
|
|
||||||
|
```php |
||||||
|
|
||||||
|
use \Codeception\Util\Debug; |
||||||
|
|
||||||
|
SomeDebugTest extends yii\codeception\TestCase |
||||||
|
{ |
||||||
|
|
||||||
|
public function testSmth() |
||||||
|
{ |
||||||
|
Debug::debug('some my string'); |
||||||
|
Debug::debug($someArray); |
||||||
|
Debug::debug($someObject); |
||||||
|
} |
||||||
|
|
||||||
|
} |
||||||
|
``` |
||||||
|
|
||||||
|
Then run command ```php codecept.phar run --debug unit/SomeDebugTest``` (Codeception also available through composer) and you will see in output: |
||||||
|
|
||||||
|
```html |
||||||
|
some my string |
||||||
|
|
||||||
|
Array |
||||||
|
( |
||||||
|
[0] => 1 |
||||||
|
[1] => 2 |
||||||
|
[2] => 3 |
||||||
|
[3] => 4 |
||||||
|
[4] => 5 |
||||||
|
) |
||||||
|
|
||||||
|
yii\web\User Object |
||||||
|
( |
||||||
|
[identityClass] => app\models\User |
||||||
|
[enableAutoLogin] => |
||||||
|
[loginUrl] => Array |
||||||
|
( |
||||||
|
[0] => site/login |
||||||
|
) |
||||||
|
|
||||||
|
[identityCookie] => Array |
||||||
|
( |
||||||
|
[name] => _identity |
||||||
|
[httpOnly] => 1 |
||||||
|
) |
||||||
|
|
||||||
|
[authTimeout] => |
||||||
|
[autoRenewCookie] => 1 |
||||||
|
[idVar] => __id |
||||||
|
[authTimeoutVar] => __expire |
||||||
|
[returnUrlVar] => __returnUrl |
||||||
|
[_access:yii\web\User:private] => Array |
||||||
|
( |
||||||
|
) |
||||||
|
|
||||||
|
[_identity:yii\web\User:private] => |
||||||
|
[_events:yii\base\Component:private] => |
||||||
|
[_behaviors:yii\base\Component:private] => |
||||||
|
) |
||||||
|
|
||||||
|
``` |
||||||
|
|
||||||
|
|
||||||
|
For further instructions refer to the related section in the Yii Definitive Guide (https://github.com/yiisoft/yii2/blob/master/docs/guide/testing.md). |
||||||
|
|
||||||
|
|
||||||
|
Installation |
||||||
|
------------ |
||||||
|
|
||||||
|
The preferred way to install this extension is through [composer](http://getcomposer.org/download/). |
||||||
|
|
||||||
|
Either run |
||||||
|
|
||||||
|
``` |
||||||
|
php composer.phar require yiisoft/yii2-codeception "*" |
||||||
|
``` |
||||||
|
|
||||||
|
or add |
||||||
|
|
||||||
|
```json |
||||||
|
"yiisoft/yii2-codeception": "*" |
||||||
|
``` |
||||||
|
|
||||||
|
to the require section of your composer.json. |
@ -0,0 +1,56 @@ |
|||||||
|
<?php |
||||||
|
|
||||||
|
namespace yii\codeception; |
||||||
|
|
||||||
|
use Yii; |
||||||
|
use yii\helpers\ArrayHelper; |
||||||
|
|
||||||
|
/** |
||||||
|
* TestCase is the base class for all codeception unit tests |
||||||
|
* |
||||||
|
* @author Mark Jebri <mark.github@yandex.ru> |
||||||
|
* @since 2.0 |
||||||
|
*/ |
||||||
|
class TestCase extends \PHPUnit_Framework_TestCase |
||||||
|
{ |
||||||
|
/** |
||||||
|
* @var array|string Your application base config that will be used for creating application each time before test. |
||||||
|
* This can be an array or alias, pointing to the config file. For example for console application it can be |
||||||
|
* '@tests/unit/console_bootstrap.php' that can be similar to existing unit tests bootstrap file. |
||||||
|
*/ |
||||||
|
public static $applicationConfig = '@app/config/web.php'; |
||||||
|
/** |
||||||
|
* @var array|string Your application config, will be merged with base config when creating application. Can be an alias too. |
||||||
|
*/ |
||||||
|
protected $config = []; |
||||||
|
|
||||||
|
/** |
||||||
|
* Created application class |
||||||
|
* @var string |
||||||
|
*/ |
||||||
|
protected $applicationClass = 'yii\web\Application'; |
||||||
|
|
||||||
|
protected function tearDown() |
||||||
|
{ |
||||||
|
$this->destroyApplication(); |
||||||
|
parent::tearDown(); |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* Sets up `Yii::$app`. |
||||||
|
*/ |
||||||
|
protected function mockApplication() |
||||||
|
{ |
||||||
|
$baseConfig = is_array(static::$applicationConfig) ? static::$applicationConfig : require(Yii::getAlias(static::$applicationConfig)); |
||||||
|
$config = is_array($this->config)? $this->config : require(Yii::getAlias($this->config)); |
||||||
|
new $this->applicationClass(ArrayHelper::merge($baseConfig,$config)); |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* Destroys an application created via [[mockApplication]]. |
||||||
|
*/ |
||||||
|
protected function destroyApplication() |
||||||
|
{ |
||||||
|
\Yii::$app = null; |
||||||
|
} |
||||||
|
} |
@ -0,0 +1,26 @@ |
|||||||
|
{ |
||||||
|
"name": "yiisoft/yii2-codeception", |
||||||
|
"description": "The Codeception integration for the Yii framework", |
||||||
|
"keywords": ["yii", "codeception"], |
||||||
|
"type": "yii2-extension", |
||||||
|
"license": "BSD-3-Clause", |
||||||
|
"support": { |
||||||
|
"forum": "http://www.yiiframework.com/forum/", |
||||||
|
"wiki": "http://www.yiiframework.com/wiki/", |
||||||
|
"irc": "irc://irc.freenode.net/yii", |
||||||
|
"source": "https://github.com/yiisoft/yii2" |
||||||
|
}, |
||||||
|
"authors": [ |
||||||
|
{ |
||||||
|
"name": "Mark Jebri", |
||||||
|
"email": "mark.github@yandex.ru" |
||||||
|
} |
||||||
|
], |
||||||
|
"require": { |
||||||
|
"yiisoft/yii2": "*" |
||||||
|
}, |
||||||
|
"autoload": { |
||||||
|
"psr-0": { "yii\\codeception\\": "" } |
||||||
|
}, |
||||||
|
"target-dir": "yii/codeception" |
||||||
|
} |
Loading…
Reference in new issue