0

我正在使用 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;
    }

我不知道出了什么问题,并且在 Internet / stackoverflow 上找不到任何资源。提前为您提供帮助:)

4

1 回答 1

-1

也许您忘记了use规范文件中的说明:

use Test\Bundle\TestBundle\Repository\TestRepository;

class TestServiceSpec
{
   ...
于 2014-11-05T11:51:40.983 回答