我正在尝试为 phpunit 模拟一个类。PHP 单元因错误而失败Could not load mock ... class already exists
。这是我正在运行的唯一测试,因此不可能已经模拟了该类。
任何建议将不胜感激。
这是错误案例:
namespace Tests\Feature;
use Tests\TestCase;
class DeactivateACSTest extends TestCase
{
public function testDeactivateAcs()
{
$deviceController = \Mockery::mock('overload:App\Http\Controllers\Cloud\DeviceController');
$deviceController
->shouldReceive('deactivateACS')
->andReturn('hilfehilfehilfe');
$devCon = new \App\Http\Controllers\Cloud\DeviceController();
$this->assertEquals('hilfehilfehilfe', $devCon->deactivateACS());
}
}
在没有它的情况下运行它--code-coverage
时:
[13:10:15] vagrant@homestead [~/Code/ekp] $ phpunit --filter DeactivateACS
PHPUnit 6.5.10 by Sebastian Bergmann and contributors.
==> Tests\Feature\DeactivateACSTest ✓
Time: 1.08 seconds, Memory: 16.00MB
OK (1 test, 3 assertions)
但是,当使用它运行它时--code-coverage
会失败:
[13:10:23] vagrant@homestead [~/Code/ekp] $ phpunit --coverage-html coverage --coverage-text=code_coverage.txt --filter DeactivateACSTest
PHPUnit 6.5.10 by Sebastian Bergmann and contributors.
==> Tests\Feature\DeactivateACSTest ⚈
Time: 5.79 seconds, Memory: 44.00MB
There was 1 error:
1) Tests\Feature\DeactivateACSTest::testDeactivateAcs
Mockery\Exception\RuntimeException: Could not load mock \App\Http\Controllers\Cloud\DeviceController, class already exists
/home/vagrant/Code/ekp/vendor/mockery/mockery/library/Mockery/Container.php:220
/home/vagrant/Code/ekp/vendor/mockery/mockery/library/Mockery.php:116
/home/vagrant/Code/ekp/tests/Feature/DeactivateACSTest.php:11
ERRORS!
Tests: 1, Assertions: 0, Errors: 1.
Generating code coverage report in HTML format ... done