3

Right now, on Composer, I am trying to run PHP Unit Tests. Here is my composer.json

{
    "require-dev": {
        "phpunit/phpunit": "^5.7"
    },
    "autoload": {
        "classmap": ["src"]
    }
}

and to run this, I have to do: php vendor/bin/phpunit --colors tests

When in reality, I'd like to remove the php prefix and just do phpunit --colors tests

I have seen it done the 2nd way so many times in video tutorials, how do they do this?

I am running PHP 7.1.0RC6 on a MBPr.

4
  • 1
    Sorry if this is the wrong place but I would not know how I would begin to search for an answer so I finally gave up. Commented Dec 19, 2016 at 1:06
  • 1
    I think they just add the vendor/bin/phpunit to their path? Commented Dec 19, 2016 at 1:11
  • After a quick google Let me know if this link helps Commented Dec 19, 2016 at 1:13
  • 1
    You could make an alias that runs php vendor/bin/phpunit --colors tests is that what you want? Commented Dec 19, 2016 at 1:13

1 Answer 1

2

php is not a prefix but a name of the interpreter.

If you ls -al vendor/bin/phpunit you can see it is executable, and if you head vendor/bin/phpunit -n1 you will see the hashbang which points to the interpreter. This way the php prefix is redundant. ./vendor/bin/phpunit --colors tests does equally well.

To turn it to phpunit --colors tests you you can use simlinks, aliases, etc mentioned in the comments. It may be quite handy in dockerized app, but I wouldn't recommend it if you have more than one project with potentially different versions of phpunit installed.

As to online docs or video tutorials, they might come from stone ages of phpunit when it was available as pear package.

Sign up to request clarification or add additional context in comments.

2 Comments

Yup. And for most scripts, you can put the interpreter at the top of the file, like #!/bin/bash for a shell script or #!/usr/bin/perl for a perl script, then simply set the execute bit on the file. IIRC PHP started complaining about this a while back,but I just checked with a simple phpinfo() script and no errors or warnings.
Right, I meant the prefix of the command. But thank you. I see what you mean, I am following along Jefferey Way's laracasts and he is doing as the 2nd command I described. I used your way, it works. Thank you.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.