0

I'm a refactoring a symfony2 application with phpspec. But when i try to test it i keep getting the same error on the first step.

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")

I have used the correct namespace in front and added the let() to my spec.

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');
}

And my service:

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;
    }

I have no clue what is wrong and cna't find any resources on the internet / stackoverflow. Thnx in advance for your help :)

Pindabeer
  • 21
  • 4
  • Problem solved, the comment was not pointing to the full path of the serviceclass. /** * @param Test\Bundle\TestBundle\Repository\TestRepository $repository */ function let( TestRepository $repository, ) { $this->beConstructedWith($repository, $validator, $eventDay, $log); } – Pindabeer Jun 19 '14 at 14:00

1 Answers1

-1

Maybe you forgot the use instruction in your spec file:

use Test\Bundle\TestBundle\Repository\TestRepository;

class TestServiceSpec
{
   ...