Executes @example docBlock params as test cases

2.2.1-beta.1 2015-11-04 09:20 UTC


If you don't have a time to write tests.


This extension is for testing without test writing. It doe few things. 1. 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.

  1. It takes your docblock @example tag and runs its content as assert expression. See examples below.

  2. 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.

Unit tests:

  1. define @example docblock in your tested class method descriptions:
     * Returns user default name
     * @return string name.
     * @example $this->getDefaultName() == "Mr. Smith"
    protected function getDefaultName()
        return "Mr. Smith"
  1. Call UnitTest from your test script:
    $docTester = new \bariew\docTest\UnitTest("app\models\User");

Url tests:

  1. define @example docblocks in your target class method descriptions:
    $this->post("", ["myParam"=>"MyValue"]) == '{"code":200, "message":"OK"}'
  1. Call DocTest from your test script:
    $docTester = new \bariew\docTest\UrlTest("app\controllers\UserController");
  1. Click tests. See in examples folder.