Tomazi
Tomazi

Reputation: 847

Cannot get PHPUnit working on Symfony 2

I am working with Symfony 2 and trying to get PHPunit to work with it so I've added this to my composer.json under required-dev:

"phpunit/phpunit": "4.6.*"

runned this command in my terminal:

composer update --dev

after doing the above PHPUnit appears under the vendor directory.

According to the docs Symfony 2 has PHPUnit pre configured and can be executed by: phpunit -c app/

But it never works and my terminal message is:

 Unknown command “phpunit”
The program 'phpunit' is currently not installed. You can install it by typing:
sudo apt-get install phpunit

Even through this ./bin/phpunit -c app seems to trigger phpunit no matter what test I write I always get this:

Configuration read from /home/tomazi/Dev/api.test/app/phpunit.xml.dist



Time: 66 ms, Memory: 4.25Mb

No tests executed!

My Test:

<?php

namespace BoltMail\User\InteractionBundle\Tests\Dto\Template;

class TestTemplateTest extends \PHPUnit_Framework_TestCase
{
    public function testIndex()
    {
        $this->assertTrue(true);
    }
}

Upvotes: 1

Views: 1707

Answers (2)

Evgeniy Kuzmin
Evgeniy Kuzmin

Reputation: 2462

as you installed phpunit from composer you should run it from the project directory as

$./bin/phpunit -c app

or if you want it be runned globally:

For a system-wide installation via Composer, you can run:

composer global require "phpunit/phpunit=3.7.*" Make sure you have ~/.composer/vendor/bin/ in your path.

Update to your question:

I suppose that you already solved the issue with empty tests by specifying target of tests. Just second way is specify target at app/phpunit.xml

<?xml version="1.0" encoding="UTF-8"?>

<!-- http://www.phpunit.de/manual/current/en/appendixes.configuration.html -->
<phpunit
    backupGlobals               = "false"
    backupStaticAttributes      = "false"
    colors                      = "true"
    convertErrorsToExceptions   = "true"
    convertNoticesToExceptions  = "true"
    convertWarningsToExceptions = "true"
    processIsolation            = "false"
    stopOnFailure               = "false"
    syntaxCheck                 = "false"
    verbose                     = "true"
    bootstrap                   = "bootstrap.php.cache" >
<!-- more settings here -->
    <testsuites>
        <testsuite name="My Test Suite">
            <directory>../src/*/*Bundle/Tests</directory>
            <directory>../src/*/Bundle/*Bundle/Tests</directory>
        </testsuite>
    </testsuites>
    <filter>
      <whitelist>
        <directory>../src</directory>
        <exclude>
            <directory>../src/*/*Bundle/Resources</directory>
            <directory>../src/*/*Bundle/Tests</directory>
            <directory>../src/*/Bundle/*Bundle/Resources</directory>
            <directory>../src/*/Bundle/*Bundle/Tests</directory>
        </exclude>
      </whitelist>
    </filter>    
</phpunit>

Upvotes: 3

Nawfal Serrar
Nawfal Serrar

Reputation: 2263

You either have to specify your directories in your phpunit config file phpunit.xml.dist or run the command with specific directory or file

./bin/phpunit -c app/ path/to/your/test/folder

Upvotes: 1

Related Questions