Paul Preibisch
Paul Preibisch

Reputation: 4332

PHPSpec always says my spec doesnt exist

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?

Upvotes: 2

Views: 1608

Answers (2)

John Dave Decano
John Dave Decano

Reputation: 128

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

Upvotes: 4

Damon Jones
Damon Jones

Reputation: 219

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

Upvotes: 4

Related Questions