Run unit tests with Phpunit in lumen

0

Hi, I have a project of lumen with the file phpunit that comes by default that is just like this one

<?xml version="1.0" encoding="UTF-8"?>
<phpunit backupGlobals="false"
     backupStaticAttributes="false"
     bootstrap="bootstrap/app.php"
     colors="true"
     convertErrorsToExceptions="true"
     convertNoticesToExceptions="true"
     convertWarningsToExceptions="true"
     processIsolation="false"
     stopOnFailure="false"
     syntaxCheck="false">
<testsuites>
    <testsuite name="Application Test Suite">
        <directory suffix="Test.php">./tests</directory>
    </testsuite>
</testsuites>
<filter>
    <whitelist processUncoveredFilesFromWhitelist="true">
        <directory suffix=".php">./app</directory>
    </whitelist>
</filter>
<php>
    <env name="APP_ENV" value="testing"/>
    <env name="CACHE_DRIVER" value="array"/>
    <env name="QUEUE_DRIVER" value="sync"/>
</php>

The file .env I have it this way

APP_ENV=local
APP_DEBUG=true
APP_KEY=
APP_TIMEZONE=UTC

Now I go to the console and I execute phpunit from the project directory and what I receive by screen is the following

PHPUnit 5.4.6 by Sebastian Bergmann and contributors.
  

Time: 37 ms, Memory: 8.00MB

     

No tests executed!

If I look at the test folder I see the following files

edu@pc1:/var/www/html/proyecto1/tests$ ls -alh
total 20K
drwxr-xr-x  2 edu edu 4,0K feb 28 13:40 .
drwxr-xr-x 14 edu edu 4,0K feb 28 13:23 ..
-rwxr-xr-x  1 edu edu  390 feb 16 16:53 ExampleTest.php
-rwxr-xr-x  1 edu edu  279 feb 16 16:53 TestCase.php
-rwxr-xr-x  1 edu edu  324 feb 28 13:35 UserTest.php
edu@pc1:/var/www/html/proyecto1/tests$ 

I've also tried running phpunit of a single file and I get this error:

  

edu @ pc1: / var / www / html / project1 $ phpunit tests / TestCase.php   Class 'tests / TestCase' could not be found in '/var/www/html/project1/tests/TestCase.php'.

    
asked by ilernet 28.02.2018 в 14:01
source

1 answer

1

You are not recognizing the tests because you are naming them upside down.
The names of the classes have to end in Test and the names of the methods have to start with test or have the annotation @test
I hope I have been helpful

will rename TestCase.php by CaseTest.php and should work

    
answered by 10.03.2018 / 12:14
source