Mark
11 years ago
4 changed files with 102 additions and 0 deletions
@ -0,0 +1,45 @@ |
|||||||
|
<?php |
||||||
|
|
||||||
|
namespace yii\codeception; |
||||||
|
|
||||||
|
class BasePage |
||||||
|
{ |
||||||
|
|
||||||
|
// include url of current page |
||||||
|
public static $URL = ''; |
||||||
|
|
||||||
|
/** |
||||||
|
* Declare UI map for this page here. CSS or XPath allowed. |
||||||
|
* public static $usernameField = '#username'; |
||||||
|
* public static $formSubmitButton = "#mainForm input[type=submit]"; |
||||||
|
*/ |
||||||
|
|
||||||
|
/** |
||||||
|
* 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; |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* @var |
||||||
|
*/ |
||||||
|
protected $guy; |
||||||
|
|
||||||
|
public function __construct($I) |
||||||
|
{ |
||||||
|
$this->guy = $I; |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* @return $this |
||||||
|
*/ |
||||||
|
public static function of($I) |
||||||
|
{ |
||||||
|
return new static($I); |
||||||
|
} |
||||||
|
|
||||||
|
} |
@ -0,0 +1,54 @@ |
|||||||
|
<?php |
||||||
|
|
||||||
|
namespace yii\codeception; |
||||||
|
|
||||||
|
use Yii; |
||||||
|
|
||||||
|
class TestCase extends \PHPUnit_Framework_TestCase |
||||||
|
{ |
||||||
|
|
||||||
|
/** |
||||||
|
* 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. |
||||||
|
* @var mixed |
||||||
|
*/ |
||||||
|
protected $baseConfig = '@tests/unit/_bootstrap.php'; |
||||||
|
|
||||||
|
/** |
||||||
|
* Your application config, will be merged with base config when creating application. Can be an alias too. |
||||||
|
* @var mixed |
||||||
|
*/ |
||||||
|
protected $config = array(); |
||||||
|
|
||||||
|
/** |
||||||
|
* Created application class |
||||||
|
* @var string |
||||||
|
*/ |
||||||
|
protected $appClass = '\yii\web\Application'; |
||||||
|
|
||||||
|
protected function setUp() |
||||||
|
{ |
||||||
|
parent::setUp(); |
||||||
|
$this->mockApplication(); |
||||||
|
} |
||||||
|
|
||||||
|
protected function tearDown() |
||||||
|
{ |
||||||
|
$this->destroyApplication(); |
||||||
|
parent::tearDown(); |
||||||
|
} |
||||||
|
|
||||||
|
protected function mockApplication() |
||||||
|
{ |
||||||
|
$baseConfig = is_array($this->baseConfig)? $this->baseConfig : require(Yii::getAlias($this->baseConfig, true)); |
||||||
|
$config = is_array($this->config)? $this->config : require(Yii::getAlias($this->config, true)); |
||||||
|
new $this->appClass(\yii\helpers\ArrayHelper::merge($baseConfig,$config)); |
||||||
|
} |
||||||
|
|
||||||
|
protected function destroyApplication() |
||||||
|
{ |
||||||
|
\Yii::$app = null; |
||||||
|
} |
||||||
|
|
||||||
|
} |
Loading…
Reference in new issue