我正在寻找一种方法来表示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?
答案 0 :(得分:0)
您可以使用let()
方法并在其中调用beConstructedWith()
。阅读here。
CLASS
class Hello
{
private $writer;
public function __construct(Writer $write)
{
$this->write = $writer;
}
// You methods
}
SPEC
namespace spec;
use PhpSpec\ObjectBehavior;
use Markdown\Writer;
class HelloSpec extends ObjectBehavior
{
function let(Writer $writer)
{
$this->beConstructedWith($writer);
}
// Write your method test
}