Laravel和PHPUnit-耗尽的内存大小为134217728字节

时间:2019-06-04 16:39:32

标签: laravel phpunit

我在编写的单个PHPUnit测试中看到一个奇怪的错误。我有346个测试的测试套件。当我使用vendor/bin/phpunit运行所有测试时,一切正常。所有测试都使用68.00 MB内存。套件中的测试类之一是tests/Unit/Jobs/ProcessShipStationAmazonSFWebhookTest.php。本课程有一个测试。当我自己运行该测试时,它也可以正常运行:

vendor/bin/phpunit tests/Unit/Jobs/ProcessShipStationAmazonSFWebhookTest.php

现在,这是该课程测试的节选:

Queue::assertPushedOn('webhooks', ProcessShipStationSFShipment::class, function ($job) {
    return $job->shipment['shipmentId'] == 1;
});

Queue::assertPushedOn('webhooks', ProcessShipStationSFShipment::class, function ($job) {
    return $job->shipment['shipmentId'] == 2;
});

Queue::assertPushedOn('webhooks', ProcessShipStationSFShipment::class, function ($job) {
    return $job->shipment['shipmentId'] == 3;
});

同样,这很好。现在,我所做的唯一更改是转到最后一个断言,并将其从assertPushedOn更改为assertNotPushedOn,如下所示:

Queue::assertNotPushedOn('webhooks', ProcessShipStationSFShipment::class, function ($job) {
    return $job->shipment['shipmentId'] == 3;
});

执行此操作,然后再次运行测试时,出现有关内存大小的错误:

vendor/bin/phpunit tests/Unit/Jobs/ProcessShipStationAmazonSFWebhookTest.php

Fatal error: Allowed memory size of 134217728 bytes exhausted (tried to allocate 20480 bytes) in /root/vendor/laravel/framework/src/Illuminate/Queue/QueueManager.php on line 0

Fatal error: Allowed memory size of 134217728 bytes exhausted (tried to allocate 20480 bytes) in /root/vendor/laravel/framework/src/Illuminate/Foundation/Bootstrap/HandleExceptions.php on line 122

为什么这种简单的方法更改突然导致内存问题?有人知道吗?

1 个答案:

答案 0 :(得分:0)

Laravel的框架中未定义Variable "$minusFiveDays" of required type "Date!" was not provided.方法。也许错误是因为PHP尝试引发异常吗?

或者,如果您定义了该方法,则可以看到该方法的实现。