<?php

class Designer_Tests_TestCase
{
    private $_assertions;

    public function run($report)
    {
        $class = new ReflectionClass(get_class($this));
        $methods = $class->getMethods(ReflectionMethod::IS_PUBLIC);
        $tests = array();
        foreach ($methods as $method) {
            if (0 !== $method->getNumberOfParameters())
                continue;
            ob_start();
            $this->_assertions = 0;
            $entry = array(
                'name' => $method->class . '::' . $method->name,
                'status' => 'fail'
            );
            try {
                $method->invoke($this);
                $entry['status'] = 'success';
            } catch (Exception $e) {
                $entry['status'] = 'fail';
                echo $e;
            }
            $entry['assertions'] = $this->_assertions;
            $entry['output'] = ob_get_clean();
            $report[] = $entry;
        }
    }

    public function assertEquals($expected, $actual, $message = 'assertEquals fails')
    {
        $this->_assertions++;
        if ($expected !== $actual)
            throw new Exception($message);
    }

    public function assertNotEquals($expected, $actual, $message = 'assertEquals fails')
    {
        $this->_assertions++;
        if ($expected === $actual)
            throw new Exception($message);
    }

    public function assertSoftEquals($expected, $actual, $message = 'assertSoftEquals fails')
    {
        $this->_assertions++;
        if ($expected != $actual)
            throw new Exception($message);
    }

    public function assertSoftNotEquals($expected, $actual, $message = 'assertSoftEquals fails')
    {
        $this->_assertions++;
        if ($expected == $actual)
            throw new Exception($message);
    }

    public function assertTrue($actual)
    {
        $this->_assertions++;
        if (true !== $actual)
            throw new Exception('assertTrue fails');
    }

    public function assertFileExists($file)
    {
        $this->_assertions++;
        if (!file_exists($file))
            throw new Exception('assertFileExists fails');
    }
}