hautelook/frankenstein

通过混合PHPUnit、Prophecy、Atoum召唤出的生物。

该软件包的规范仓库似乎已不存在,因此该软件包已被冻结。

0.1.2 2014-06-03 04:34 UTC

This package is not auto-updated.

Last update: 2022-01-17 01:54:07 UTC


README

Build Status Scrutinizer Quality Score Latest Unstable Version

这使得您可以与Prophecy模拟和Atoum断言器一起使用PHPUnit。

用法

您的测试类必须扩展 Hautelook\Frankenstein\TestCase

<?php

namespace AcmeDemoBundle\Tests\Foo;

use Hautelook\Frankenstein\TestCase;

class BarTest extends TestCase
{

}

从提供的 TestCase 扩展时,除了 Atoum 断言器和 Prophecy 模拟之外的所有内容都被限制。

您必须使用 Prophecy 进行模拟,使用 $this->prophesize()

public function test()
{
    $routerProphecy = $this->prophesize('Symfony\Component\Routing\Generator\UrlGeneratorInterface');
    $routerProphecy
        ->generate('acme_demo_index')
        ->willReturn('/acme')
    ;

    $foo = new Foo($routerProphecy->reveal());
}

您必须使用 atoum 断言器而不是 phpunit 的

public function test()
{
    $foo = new Foo();

    $this
        ->string($foo->getName())
            ->isEqualTo('foo foo foo')
    ;
}

Prophecy 参数

测试类允许您通过 $this->arg$this->arg() 访问 Prophecy\Argument 短路方法。

public function test()
{
    $routerProphecy = $this->prophesize('Symfony\Component\Routing\Generator\UrlGeneratorInterface');
    $routerProphecy
        ->generate($this->arg->type('string'))
        ->willReturn('/acme')
    ;

    $foo = new Foo($routerProphecy->reveal());
}

运行测试

安装Composer dev 依赖

php composer.phar install

然后,使用phpunit运行测试套件

bin/phpunit

许可

Frankenstein在MIT许可证下发布。有关详细信息,请参阅捆绑的LICENSE文件。

致谢

此库包含https://github.com/atoum/atoum的代码副本,并使用https://github.com/phpspec/prophecy-phpunit