Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

donkfather's avatar

Basic php project with phpunit

Hi guys and girls :) . I am trying to build a simple project in php with tests. the folder structure is as follows:

 root/
    src/
         Primes.php
    tests/
     PrimesTest.php
    vendor/
    composer.json
    phpunit.xml

The problem is .. when I run phpunit it says No tests executed

PrimesTest.php

use PHPUnit\Framework\TestCase;

class PrimesTest extends TestCase
{
    /**
     * @test
     */
    public function test_should_return_false()
    {
        $this->assertTrue(true);
    }
}

composer.json

{
  "require": {
    "tightenco/collect": "^5.4"
  },
  "require-dev": {
    "phpunit/phpunit": "^6.0"
  },
  "autoload": {
    "classmap": [
      "src",
      "tests"
    ],
    "psr-4": {
      "Tests\\": "tests/",
      "App\\": "src/"
    }
  }
}

phpunit.xml

<?xml version="1.0" encoding="UTF-8"?>
<phpunit backupGlobals="false"
         backupStaticAttributes="false"
         bootstrap="./vendor/autoload.php"
         colors="true"
         convertErrorsToExceptions="true"
         convertNoticesToExceptions="true"
         convertWarningsToExceptions="true"
         processIsolation="false"
         stopOnFailure="false">
    <testsuites>
        <testsuite name="Application Test Suite">
            <directory>./tests/</directory>
        </testsuite>
    </testsuites>
</phpunit>

I am stuck.. I have no clue why it doesn't run the test

0 likes
3 replies
tykus's avatar
tykus
Best Answer
Level 104
// use PHPUnit\Framework\TestCase;

class PrimesTest extends PHPUnit_Framework_TestCase
{
    /**
     * @test
     */
    public function test_should_return_false()
    {
        $this->assertTrue(true);
    }
}
1 like
donkfather's avatar

Thank you @tykus . it works with extends \PHPUnit_Framework_TestCase Could you explain why is that instead of TestCase ?

tykus's avatar

PHPUnit\Framework\Testcase.php contains an abstract class named PHPUnit_Framework_TestCase - so that is what you are extending. You could alias it whenever it is imported if you prefer your original syntax:

use PHPUnit\Framework\TestCase as TestCase;

Please or to participate in this conversation.