我正在用phpspec重构一个symfony2应用程序。但是当我尝试测试它的时候,我总是在第一步得到相同的错误。
bin/phpspec run -v
Test/Bundle/TestBundle/Service/TestService
36 ! it is initializable
class TestRepository not found.
0 vendor/phpspec/prophecy/src/Prophecy/Doubler/LazyDouble.php:58
throw new Prophecy\Exception\Doubler\ClassNotFoundException("Class TestRepository"...)
1 vendor/phpspec/prophecy/src/Prophecy/Prophecy/ObjectProphecy.php:63
Prophecy\Doubler\LazyDouble->setParentClass("TestRepository")我在前面使用了正确的名称空间,并将let()添加到了我的规范中。
use Test\Bundle\TestBundle\Service\TestService;
class TestServiceSpec extends ObjectBehavior
{
/**
* @param TestRepository $repository
*/
function let(
TestRepository $repository,
)
{
$this->beConstructedWith($repository, $validator, $eventDay, $log);
}
/**
*
*/
function it_is_initializable()
{
$this->shouldHaveType('Test\Bundle\TestBundle\Service\TestService');
}我的服务是:
use Test\Bundle\TestBundle\Repository\TestRepository;
/**
* Test service class.
*/
class TestService
{
/**
* Repository
* @var \Test\Bundle\TestBundle\Repository\TestRepository
*/
protected $repository;
/**
* Constructor.
*
* @param TestRepository $repository Doctrine mongodb object mapper.
*/
public function __construct(TestRepository $repository)
{
$this->repository = $repository;
}我不知道出了什么问题,也找不到互联网/ stackoverflow上的任何资源。感谢您的帮助:)
发布于 2014-11-05 19:51:41
也许您忘记了规范文件中的use指令:
use Test\Bundle\TestBundle\Repository\TestRepository;
class TestServiceSpec
{
...https://stackoverflow.com/questions/24301657
复制相似问题