eddiejaoude/phpunit-wrapper

此软件包已被 废弃 并不再维护。未建议替代软件包。

PHPUnit 包装器 - 使用简单的英文包装 PHPUnit 的功能

0.2.1 2014-03-09 06:25 UTC

This package is not auto-updated.

Last update: 2020-02-21 16:02:56 UTC


README

Build Status Coverage Status Total Downloads

PHPUnitWrapper / phpunit-wrapper

PHPUnit 包装器 - 使用简单易懂的 plain & simple English 包装 PHPUnit 的功能

注意:您的现有标准 PHPUnit 测试不会失败,它们将继续正常工作

通过 Composer 安装

    "require" : {
        "EddieJaoude\PHPUnitWrapper" : "0.*"
    }

使用

而不是扩展 \PHPUnit_Framework_TestCase,扩展 \EddieJaoude\PHPUnitWrapper\Assert

Assert 类扩展了 PHPUnit,因此您将获得所有先前功能,并且您的先前单元测试不会失败。

断言等于

标准 PHPUnit

    $this->assertEquals($expected, $actual);

    // or with custom message

    $this->assertEquals($expected, $actual, $message);

PHPUnit 包装器

    $this->expectedValue('abc')
                ->equals('abc');

    // or with custom message

    $this->expectedValue('abc')
            ->setMessage('Failure, these are not equal!') // optional
            ->equals('abc');

断言不等于

标准 PHPUnit

    $this->assertNotEquals($expected, $actual, $message);

PHPUnit 包装器

    $this->expectedValue('abc')
            ->notEquals('abcd');

包含

标准 PHPUnit

    $this->assertContains($needle, $haystack);

    // or with custom message

    $this->assertContains($needle, $haystack, $message);

PHPUnit 包装器

    $this->expectedValue($needle)
            ->existsIn($haystack);

    $this->expectedValue('b')
            ->existsIn(
                array('a', 'b', 'c')
            );

    // or with custom message

    $this->expectedValue('b')
            ->setMessage('Failure, does not exist!') // optional
            ->existsIn(
                array('a', 'b', 'c')
            );

不包含

标准 PHPUnit

    $this->assertNotContains($needle, $haystack);

    // or with custom message

    $this->assertNotContains($needle, $haystack, $message);

PHPUnit 包装器

    $this->expectedValue($needle)
            ->notExistsIn($haystack);

    $this->expectedValue('b')
            ->notExistsIn(
                array('a', 'c')
            );

    // or with custom message

    $this->expectedValue('b')
            ->setMessage('Failure, does exist!') // optional
            ->notExistsIn(
                array('a', 'c')
            );

完整使用简单示例

<?php
namespace EddieJaoude\PHPUnitWrapperTest;

use EddieJaoude\PHPUnitWrapper\Assert;

/**
 * Class ExampleTest
 *
 * @package EddieJaoude\PHPUnitWrapperTest
 */
class ExampleTest extends Assert
{

    /*
     * Example of 'assert' & 'equals'
     */
    public function testAssertEquals()
    {
        $this->expectedValue('abc')
            ->equals('abc');
    }

    /*
     * Example of 'assert' & 'equals'
     */
    public function testAssertNotEquals()
    {
        $this->expectedValue('abc')
            ->notEquals('abcd');
    }
}

贡献

分支,拉取请求 - 请附带 Tests 以及 更新 README 并添加示例

建议 / 想法

请创建一个 问题