A
A
Alexey Verkhovtsev2017-12-13 14:03:31
PHP
Alexey Verkhovtsev, 2017-12-13 14:03:31

How to properly connect PHPUnit?

Hello. I installed PHPUnit via Composer, but the command "vendor\bin\phpunit tests" does not work - "vendor is not recognized as an internal..." Only if I go to the bin folder, I can work with phpunit, which I did. I saw that there is a bat file in this folder, I copied it to the root and changed the path to "vendor/phpunit/phpunit/phpunit". Now everything works from the project root. Does this option take place or should it be better to register a variable in PATH or install PHPUnit globally right away?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
J
jaxel, 2017-12-14
@seftomsk

First, you can add to composer.json:

"config": {
        "bin-dir": "bin"
    }

Then symlinks for all console packages will be created in the bin folder at the root of the project.
Secondly, you need to create a phpunit.xml config file at the root, which might look something like this:
<phpunit bootstrap="vendor/autoload.php">
  <testsuites>
    <testsuite name="Unit test">
      <directory>tests</directory>
    </testsuite>
  </testsuites>
</phpunit>

And it already describes the settings in detail. Then, when executed bin/phpunit, tests will be launched with the settings specified in the config.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question