running phpspec from windows CMD creates the spec and src folders in vendor/bin instead of the project root

828 views Asked by At

Lately I've been learning about phpspec and gulp and decided to integrate them in my workflow. When I installed phpspec via composer, I get the file structure of:

  • vendor
    • bin
      • phpspec

there are more files but and folders but these are the relevant.

In my CMD I'm currently pointing the root of my project and trying to run:

vendor/bin/phpspec

However, I get an error saying 'vendor' isn't recognizes as internal or external command... so I moved into my bin folder by doing cd vendor/bin and then run phpspec and it indeed works. However, when I try to describe a class phpspec describe SeatsHandler it creates my files not in the root directory it creates them inside the vendor/bin folder:

  • vendor
    • bin
      • phpspec
      • spec
      • src

I tried to see how I can configure that and read about phpspec.yml. I've created such file along with app directory in my main folder (would love to get rid of app directory):

    suites:
      app_suite:
        src_path: app

I tried putting this file in my main directory, but it didn't work, I got the same result as before. I also tried moving this file into vendor/bin but no avail.

How can I make phpspec create the files in my root directory instead of inside vendor/bin? Also, why does it ignore the phpspec.yml?

EDIT:

I managed to make it work by modifying my phpspec.yml into:

    suites:
      app_suite:
        src_path: ../../src/
        spec_path: ../../

And put it in vendor/bin. However, a question still remains, how can I run phpspec without going inside the vendor/bin directory in CMD?

2

There are 2 answers

0
anagnam On

in your composer.json file, just add the "bin-dir": "bin" under config like so:

{
"require-dev": {
    "phpspec/phpspec": "~2.0"
},
"config": {
    "bin-dir": "bin"
},
"autoload": {"psr-0": {"": "bin/src"}}
}

and youll get a bin folder on your root directory along with the vendor directory.

  • bin
  • vendor

then you can run phpspec on your root directory exactly as you want.

0
Tuncay Elvanagac On

You can install it globally as following;

composer global require phpspec/phpspec

now you can call it phpspec