franckysolo/unitest

PHP 单元测试

安装: 7

依赖: 0

建议者: 0

安全: 0

星标: 0

关注者: 2

分支: 0

开放问题: 0

类型:php-unit-test

dev-master / 0.1.0.x-dev 2016-05-18 15:40 UTC

This package is auto-updated.

Last update: 2024-08-28 06:24:43 UTC


README

Unitest 是一个简单的 PHP 单元测试微框架。
适用于小型应用开发,
提供智能的 HTML 渲染,
使用 Jquery 和 Bootstrap。

要求

  • PHP >= 5.4
  • Xdebug 扩展已启用

安装

composer require franckysolo/unitest

使用

您的项目中的测试目录将包含所有应用测试。
创建一些测试,然后浏览您的项目以显示报告器
https:///your-project/tests/_reporter
您可以创建自己的渲染页面,示例提供在 _reporter 目录中。

运行所有测试的 bootstrap index.php 文件

<?php
// Bootstrap test file

// First require autoloader
require_once __DIR__ . '/../../vendor/autoload.php';

// Call uses
use Unitest\Series;
use Unitest\Reporter;

// Defined your test series
$serie = new Series(array(
    'tests\classes\TestClasses',
    // 'tests\functions\FunctionsTest', //... Another functions test
    // 'tests\MyTest', //... Another class test
));

// {@see Reporter}
// Run and render it
Reporter::newInstance()->render($serie->run());
?>

一个简单的测试示例

<?php
namespace tests;

use Unitest\Test;

class MyTest extends Test {

    protected $data = array();

    public function init() {

        $this->setTitle('Simple example testing data array');

        $this->data = array (
            'PHP',
            'JavaScript',
            'HTML'
        );
    }

    public function run() {
      #1 - assertion
      $actual     = count($this->data);
      $expected   = 3;
      $this->assert('Count array elements', $actual === $expected);

      #2 - assertion with output
      $pop = array_pop($this->data);
      $actual     = count($this->data);
      $expected   = 2;
      $this->assert('Pop an element and count', $actual === $expected);
      echo $pop;

      #3 - assertion with an exception for example
      $this->assert('Raised an exception', false);
      $iterator = new \ArrayIterator('exception raised');
    }
}

HTML 智能渲染

Screen shot