Cakephp phpunit.xml blacklist gets ignored while testing

198 views Asked by At

When I run my tests on cakephp 2.6 the /plugin folder tests get included. I tried to set the blacklist option in the phpunit.xml and the test uses the file, but the plugins will still be included.

The command I am using and the following text from the command promt

$ Console/cake test app All --stderr --configuration phpunit.xml

Welcome to CakePHP v2.6.13 Console
---------------------------------------------------------------
App : site
Path: /var/www/MYPAGE/site/
---------------------------------------------------------------
CakePHP Test Shell
---------------------------------------------------------------
PHPUnit 3.7.38 by Sebastian Bergmann.

Configuration read from /var/www/MYPAGE/phpunit.xml

My phpunit.xml file.

<?xml version="1.0" encoding="UTF-8"?>
<phpunit>
    <php>
        <ini name="memory_limit" value="2048M" />
    </php>
    <filter>
        <blacklist>
            <directory suffix=".php">./plugins</directory>
            <directory suffix=".ctp">./plugins</directory>
            <directory suffix=".php">./vendor</directory>
        </blacklist>
    </filter>
</phpunit>

As you can see I would like to ignore tests from the vendor and plugin folder next to the app/src folder.

I also tried without the configuration option

$ Console/cake test App all --stderr

The plugins that gets automatically called are:

/plugins
--Authenticate
--Crud
--DebugKit
--..
/src

1

There are 1 answers

2
ndm On

The <filter> section is solely ment to filter files/locations from code coverage analysis.

If you were to narrow down what is being tested in a PHPUnit configuration file, then you'd need to configure <testsuites> accordingly. However, as you know, in CakePHP 2.x you do not run PHPUnit directly, but use the CakePHP test shell, and that requires to programmatically create test suites - which seem to exist in your setup, otherwise passing all should result in an error (at least that's the case in the latest 2.x).

Taken from the docs, a test suite that would only test your apps tests could look like this:

// app/Test/Case/AllModelTest.php

class AllTestsTest extends CakeTestSuite {
    public static function suite() {
        $suite = new CakeTestSuite('All tests');
        $suite->addTestDirectoryRecursive(TESTS . 'Case');
        return $suite;
    }
}

and you'd run it like:

Console/cake test app AllTests

See also