Giter Site home page Giter Site logo

cybercog / yii2-doctest-extension Goto Github PK

View Code? Open in Web Editor NEW

This project forked from bariew/yii2-doctest-extension

0.0 3.0 0.0 101 KB

Executes @example docBlock params as test cases

License: BSD 3-Clause "New" or "Revised" License

PHP 100.00%

yii2-doctest-extension's Introduction

Doc test Yii2 extension

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

Description

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.

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

  3. It also runs you url get and post requests, e.g. you can test your controller, eg API. with @example tags for each method.

Installation

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");
    $docTester->test();

Url tests:

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

yii2-doctest-extension's People

Watchers

 avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.