Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
tree: 0a4205dbf4
Fetching contributors…

Cannot retrieve contributors at this time

file 44 lines (41 sloc) 1.032 kb
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44
<?php
/**
* Inspired from redunit
*/
namespace shozu\Controller;
class Testing extends \shozu\Controller\CLI
{
    protected $tests = 0;
    public function allAction()
    {
        $methods = get_class_methods($this);
        foreach ($methods as $method) {
            if (substr($method, 0, 4) == 'test') {
                try {
                    $this->$method();
                } catch (\Exception $e) {
                    die(get_class($e) . ' on ' . $method . ': ' . $e->getMessage() . "\n" . $e->getTraceAsString() . "\n");
                }
            }
        }
        echo "\nPassed all {$this->tests} tests\n";
    }

    protected function pass()
    {
        $this->tests++;
    }

    protected function fail($message = '')
    {
        echo "\nFailed ! $message\n";
        debug_print_backtrace();
        die;
    }

    protected function asrt($a, $b)
    {
        if ($a === $b) {
            $this->pass();
        } else {
            $this->fail('Expected '.$b.' but got '.$a);
        }
    }
}
Something went wrong with that request. Please try again.