mover-io/phpusable-phpunit

这个软件包的官方仓库似乎已不存在,因此该软件包已被冻结。

1.1.4 2017-06-20 17:02 UTC

This package is not auto-updated.

Last update: 2019-05-28 11:34:42 UTC


README

动机

该项目的目标是提供一个在PHPUnit之上更易用的语法,同时保持与PHPUnit的兼容性。

该DSL和语法的灵感大部分来源于Ruby测试框架RSpec

安装

可以使用Composer安装PHPUsable。

首先,将以下内容保存为项目根目录下的composer.json

{
    "require": {
        "mover-io/phpusable-phpunit": "dev-master"
    }
}

然后运行以下命令。

$ wget https://getcomposer.org.cn/composer.phar
$ php composer.phar install

之后,PHPUsable将被安装在./vendor目录中,并且还会生成./vendor/autoload.php

用法

PHPUsable与PHPUnit几乎完全兼容。要运行PHPUsable测试文件,只需使用phpunit运行它即可。

$ phpunit test/test.php
PHPUnit 3.7.20 by Sebastian Bergmann.

....

Time: 0 seconds, Memory: 4.50Mb

OK (4 tests, 4 assertions)

它甚至支持phpunit的调试输出。

$ phpunit --debug test/test.php
PHPUnit 3.7.20 by Sebastian Bergmann.


Starting test 'with esperance style assertions::with a true value::should be true'.
.
Starting test 'with esperance style assertions::with a false value::should be false'.
.
Starting test 'with phpunit style assertions::with a true value::should be true'.
.
Starting test 'with phpunit style assertions::with a false value::should be false'.
.

Time: 0 seconds, Memory: 4.50Mb

OK (4 tests, 4 assertions)

用法示例

<?php
namespace PHPUsable;
require 'vendor/autoload.php';


class PHPTest extends PHPUsableTest {
    public function tests() {
        PHPUsableTest::$current_test = $this;

        describe('with esperance style assertions', function($test) {
            describe('with a true value', function($test) {
                before(function($test) {
                    //Arbitratry variables can be stored on test to pass between blocks
                    $test->my_value = true;
                });

                it ('should be true', function($test) {
                    $test->expect($test->my_value)->to->be->ok();
                });
            });

            describe('with a false value', function($test) {
                before(function($test) {
                    $test->my_value = false;
                });

                it ('should be false', function($test) {
                    $test->expect($test->my_value)->to->be(false);
                });
            });
        });

        describe('with phpunit style assertions', function($test) {
            describe('with a true value', function($test) {
                before(function($test) {
                    $test->my_value = true;
                });

                it ('should be true', function($test) {
                    $test->assertTrue($test->my_value);
                });
            });

            describe('with a false value', function($test) {
                before(function($test) {
                    $test->my_value = false;
                });

                it ('should be false', function($test) {
                    $test->assertFalse($test->my_value);
                });
            });
        });
    }
}

团队

这个库是由Mover团队创建的,用于测试我们的PHP代码库,因为我们厌倦了PHPUnit的语法。

期望

PHPUsable使用Esperance提供基于期望的断言语法。

许可证

MIT许可证(或者买我一杯啤酒)