1

I want to run a AllModelTest with phpunit command.
But when I try to run, there is nothing to test as a result.
Of course, there are many test codes.

$vendors/bin/phpunit --configuration app/Test/phpunit.xml
PHPUnit 3.7.38 by Sebastian Bergmann.

Configuration read from /Develop/web/app/Test/phpunit.xml




Time: 30 ms, Memory: 3.75Mb


No tests executed!

Also when I use a "Console/cake" command, it looks fine.

$ app/Console/cake test app AllModel --stderr

Welcome to CakePHP v2.5.8 Console
---------------------------------------------------------------
App : app
Path: /Develop/web/app/
---------------------------------------------------------------
CakePHP Test Shell
---------------------------------------------------------------
PHPUnit 3.7.38 by Sebastian Bergmann.

...
/app/Test/Case/Model/JanTest.php

I wrote the phpunit.xml like this.

<?xml version="1.0" encoding="utf-8" ?>
<phpunit bootstrap="phpunit-bootstrap.php"
    colors="true"
    convertErrorsToExceptions="true"
    convertNoticesToExceptions="true"
    convertWarningsToExceptions="true"
    stopOnFailure="false">

    <testsuites>
        <testsuite name="Project Test Suite">
            <directory suffix="Test.php">Test/Case/</directory>
        </testsuite>
    </testsuites>

</phpunit>

And the phpunit-bootstrap.php is like this.

<?php

$file = __DIR__.'/../../vendors/autoload.php';
if (!file_exists($file)) {
    throw new RuntimeException('Install dependencies to run test suite.');
}
$autoload = require_once $file;

And the target test file "AllModelTest.php" is like this.

<?php

class AllModelTest extends CakeTestSuite {
    public static function suite() {
        $suite = new CakeTestSuite('All model tests');
        $suite->addTestDirectory(TESTS . 'Case/Model');
        return $suite;
    }
}

What should I do to run the test from phpunit command ?

Thanks!

4 Answers 4

1

For CakePHP 2.x please just follow the documentation - there is a built-in shell that does the testing for you, as CakePHP 2.x is NOT compatible to PHPUnit4.0, you need to stick to 3.7 via this shell and not try to invoke the tests manually.

The command as documented is

cake test [...]

So from your app dir, to test app tests:

Console/cake test app

It will then show you a list of available tests.

Sign up to request clarification or add additional context in comments.

Comments

0

The path specified by <directory suffix="Test.php">Test/Case/</directory> is relative to the location of the phpunit.xml file.

Also note:

  • PHPUnit 3.7 is no longer activeley maintained by the PHPUnit project
  • Organizing test suites by subclassing PHPUnit_Framework_TestSuite (which CakeTestSuite seems to be used for) is discouraged by the PHPUnit project for several years
  • You are likely to run into issues if you use both CakeTestSuite to organize your tests and the <testsuites> / <testsuite> elements of PHPUnit's XML configuration file

Comments

0

I have encountered this issue, and sometimes the flexibility that phpunit.xml provides is useful and a valid use case. In both my case and the original question, we needed to add some simple bootstrap code.

After a lot of tinkering around, I discovered that if PHPUnit is running from a phar file by cake's design, it will also automatically look for a phpunit.xml file from the directory where you are running the tests.

For the command line, this is the app folder. So the file should be located at app/phpunit.xml.

For the web test runner, this is the app/webroot folder. So the file should be located at app/webroot/phpunit.xml.

Comments

0

This works fine with Cake 2, assuming you have a phpunit.xml file in your app's Config directory:

Console/cake test app AllModel --configuration=Config/phpunit.xml

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.