4

I want to install PHPUnit with composer and followed this tutorial: https://jtreminio.com/2013/03/unit-testing-tutorial-introduction-to-phpunit/

I added

{
    "require-dev": {
        "phpunit/phpunit": "3.7.14"
    },
    "autoload": {
        psr-0": {
           "phpUnitTutorial": ""
        }
 }
}

to the file composer.json. Entering ./vendor/bin/phpunit shows me that phpunit is installed.

This is my folder structure:

composer.json
composer.phar
phpUnitTutorial/
vendor/

I created a phpunit.xml file inside the phpUnitTutorial folder with the content

<?xml version="1.0" encoding="UTF-8"?>
<phpunit colors="true">
    <testsuites>
        <testsuite name="Application Test Suite">
            <directory>./phpUnitTutorial/Test/</directory>
        </testsuite>
    </testsuites>
</phpunit>

Further I created an file at phpUnitTutorial/Test/StupidTest.php with the content

<?php

namespace phpUnitTutorial\Test;

class StupidTest extends \PHPUnit_Framework_TestCase
{
    public function testTrueIsTrue(){
      $foo = ture;
      $this->assertTrue($foo);
    }
}

In the tutorial it is advised to do the following:

From project root, run PHPUnit: $ vendor/bin/phpunit

with the following screenshot:

enter image description here

If I execute $ vendor/bin/phpunit inside the phpUnitTutorial folder then I receive the error

bash: vendor/bin/phpunit: No such file or directory

which makes sense to me because the folder vendor is on the same level as the folder phpUnitTutorial. If I execute $ ../vendor/bin/phpunit I get

enter image description here

It says no test executed and it doesn't confirm that my configuration file was read. Why is it not executing the test?

Adam
  • 25,960
  • 22
  • 158
  • 247

1 Answers1

4

First, the phpunit.xml file should be in the root folder /bin/ then the command $ vendor/bin/phpunit will work and the tests will actually be executed.

Secondly you need to change in the file StupidTest.php

the line

class StupidTest extends \PHPUnit_Framework_TestCase

to

class StupidTest extends \PHPUnit\Framework\TestCase

see https://stackoverflow.com/a/42561590/2311074

Adam
  • 25,960
  • 22
  • 158
  • 247