2

I have started a composer project and have included phpspec-st,

when I run the command:

/var/www/yii-video-site/vendor$ bin/phpspec desc videosite/test

I get the message:

Specification for videosite\test created in /var/www/yii-video-site/vendor/spec/videosite/testSpec.php.

But when I run phpspec, it says test

test
10 ! it is initializable class test does not exist.

videosite/test                                      
  10  ! it is initializable
      class videosite\test does not exist.


  Do you want me to create `test` for you?                            

Why isnt it seeing the classes that are already created?

Paul Preibisch
  • 4,115
  • 2
  • 27
  • 32

2 Answers2

4

You probably need to set-up your PSR-0/PSR-4 autoloading in your composer.json file. For example, if you had your namespaced classes in a "src" directory: something like src/Videosite/Test.php then you'd set the following for the autoloading in your composer.json:

"autoload": {
    "psr-0": { "": "src/" }
}

Also, you are running phpspec from within the vendor/bin, so it may not know where the root of your project is. If you set your bin directory in composer.json, you can run phpspec from the bin directory in the root of your project, instead of from inside vendor/bin:

"config": {
    "bin-dir": "bin"
}
Damon Jones
  • 219
  • 1
  • 3
  • Just to clarify, the paths for the specs and classes are related to each other. With the autoloading given above, the class would be src/Videosite/Test.php and the spec would be spec/Videosite/TestSpec.php. Also, you may want to follow the convention where your namespaces and classes start with an uppercase letter: Videosite/Test gives src/Videosite/Test.php and spec/Videosite/TestSpec.php. – Damon Jones Jun 05 '14 at 20:32
  • Using the above answer and composer dumpautoload worked for me, thanks! – user115014 Feb 03 '15 at 13:57
4

I came across the same problem today. I tried to run composer dumpautoload on my terminal and it did solve the problem.

John Dave Decano
  • 128
  • 1
  • 1
  • 5