Laravel在另一个测试中模拟了类,并将其视为存在
使用Laravel 5.8,我在同一测试类别中进行了以下两项测试:Laravel在另一个测试中模拟了类,并将其视为存在,laravel,mockery,Laravel,Mockery,使用Laravel 5.8,我在同一测试类别中进行了以下两项测试: /** * @test */ public function a_procurement_group_can_be_created_or_fetched_from_odoo_for_this_shipment() { $shipment = InboundShipment::make(); $group = $this->mock(ProcurementGroup::class, function($
/**
* @test
*/
public function a_procurement_group_can_be_created_or_fetched_from_odoo_for_this_shipment()
{
$shipment = InboundShipment::make();
$group = $this->mock(ProcurementGroup::class, function($group) {
$group->shouldReceive('findByNameOrCreate')
->with('foo')
->andReturnSelf();
});
$this->assertSame($group, $shipment->getProcurementGroup('foo'));
}
/**
* @test
*/
public function a_procurement_can_be_created_for_an_item_in_the_shipment()
{
$shipment = InboundShipment::make();
$group = app(ProcurementGroup::class);
$procurement = app(ProcurementOrder::class);
$item = $this->mock(InboundShipmentItem::class);
$item->shouldReceive('createProcurement')
->once()
->with($group)
->andReturn($procurement);
$result = $shipment->createProcurementForItem($item, $group);
$this->assertSame($procurement, $result);
}
ProcurementGroup
类实际上还不存在,但是,在第一次测试中,我能够模拟它并使用它。太好了
现在,在第二个测试中,我希望从$group=app(ProcurementGroup::class)收到一个错误代码>行,因为类不存在,但两个测试都通过
但是,如果我只运行第二个测试本身,那么我会收到一个错误,ProcurementGroup
类不存在
因此,在第一个测试中模仿类似乎会导致第二个测试认为该类实际上存在。这是预期的行为吗
我的印象是,由于Laravel在其基本测试用例的tearDown
方法中调用了mockry::close()
,因此所有模拟信息都应该在每次测试之间销毁
这里发生了什么事?您是否更改了此测试类中的设置/拆卸方法?@Borisu没有。您可以尝试dd($group)在第二个测试中使用code>并同时运行它们?