0

PHPSpec で次のテスト メソッドごとに表現する方法を探しています。各テストには、このように作成されたクラス コンストラクターが必要です。

$config = new Config( 'path_to_config' );
$client = new SOAPService( $config );
$debtor = new Debtor( $client );

そして、次のようなものをテストできます

class DebtorSpec extends ObjectBehavior
{
function it_has_method_getDebtor()
{
$debtor->getDebtor( '123' )->shouldReturn( TRUE );
}
}

その種のクラスコンストラクターをphpspecに渡すにはどうすればよいですか?

4

1 に答える 1

0

メソッドを使用let()して呼び出すことができますbeConstructedWith()。ここでそれを読んでください

クラス

class Hello
{
    private $writer;

    public function __construct(Writer $write)
    {
        $this->write = $writer;
    }

    // You methods
}

スペック

namespace spec;

use PhpSpec\ObjectBehavior;
use Markdown\Writer;

class HelloSpec extends ObjectBehavior
{
    function let(Writer $writer)
    {
        $this->beConstructedWith($writer);
    }

    // Write your method test
}
于 2015-05-10T20:21:23.323 に答える