1

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);
    }
}
2
  • What directories are being searched in: phpunit.xml.dist Commented May 15, 2015 at 1:16
  • Depending on the configuration the local (to the project, installed by Composer) phpunit executable may be in the ./bin/ or vendor/bin/ directories. This is set by an (optional) bin json configuration in composer.json. The default is to put executable commands into vendor/bin/ Commented Aug 27, 2015 at 21:46

2 Answers 2

3

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>
Sign up to request clarification or add additional context in comments.

Comments

1

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.