Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/319.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Laravel在另一个测试中模拟了类,并将其视为存在_Laravel_Mockery - Fatal编程技术网

Laravel在另一个测试中模拟了类,并将其视为存在

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($

使用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($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)并同时运行它们?