If you don't have a time to write tests.
This extension is for testing without test writing. It doe few things.
It uses Curl to visit all your app pages (it finds them too) and submits all found forms just to make sure they are generally ok. It is useful to avoid critical errors like 404 or 500 error pages.
It takes your docblock @example tag and runs its content as assert expression. See examples below.
It also runs you url get and post requests, e.g. you can test your controller, eg API. with @example tags for each method.
The preferred way to install this extension is through composer.
Either run
php composer.phar require --prefer-dist bariew/yii2-doctest-extension "*"
or add
"bariew/yii2-doctest-extension": "*"
to the require section of your composer.json
file.
/**
* Returns user default name
* @return string name.
* @example $this->getDefaultName() == "Mr. Smith"
*/
protected function getDefaultName()
{
return "Mr. Smith"
}
$docTester = new \bariew\docTest\UnitTest("app\models\User");
$docTester->test();
define @example docblocks in your target class method descriptions:
$this->post("http://mySite.com/myPath", ["myParam"=>"MyValue"]) == '{"code":200, "message":"OK"}'
Call DocTest from your test script:
$docTester = new \bariew\docTest\UrlTest("app\controllers\UserController");
$docTester->test();
Click tests. See in examples folder.
Comments