从结论开始,我得到这个错误:
[ErrorException]
Argument 1 passed to SomeValidatorTest::__construct() must be an instance of App\Services\Validators\SomeValidator, none given, called in ....vendor/phpunit/phpunit/src/Framework/TestSuite.php on line 475 and defined
Run Code Online (Sandbox Code Playgroud)
在Laravel应用程序中,我有一个名为"SomeValidator.php"的脚本,如下所示:
<?php namespace App\Services\Validators;
use App\Services\SomeDependency;
class SomeValidator implements ValidatorInterface
{
public function __construct(SomeDependency $someDependency)
{
$this->dependency = $someDependency;
}
public function someMethod($uid)
{
return $this->someOtherMethod($uid);
}
}
Run Code Online (Sandbox Code Playgroud)
哪个运行没有错误.
然后测试脚本SomeValidatorTest.php看起来像这样:
<?php
use App\Services\Validators\SomeValidator;
class SomeValidatorTest extends TestCase
{
public function __construct(SomeValidator $validator)
{
$this->validator = $validator;
}
public function testBasicExample()
{
$result = $this->validator->doSomething();
}
}
Run Code Online (Sandbox Code Playgroud)
仅当测试脚本通过'./vendor/bin/phpunit'运行时才会显示错误.测试类似乎在没有声明依赖项的情况下启动并引发错误.有谁知道如何解决这一问题?提前致谢.