0

I want to automate CakePHP tests with Grunt, and found grunt.loadNpmTasks('grunt-phpunit');, which can automate PHPUnit, but I'm sure it can't handle cake test.

I'm also satisfied with a solution that runs cake test from Grunt, but I'm really interested in a way to run the PHPUnit command, which can execute CakePHP tests.

Edit: I'm using the current stable release of CakePHP, which is 2.5.4 now.

Tamás Barta
  • 1,617
  • 1
  • 19
  • 23

2 Answers2

0

I assume that grunt-phpunit expects a default a standard phpunit execution, if that's true you can't run it that way and you will have to adept this tool. I guess it is parsing the test output. CakePHP2 doesn't let you simply run "phpunit" like you can with CakePHP now and other libs. CakePHP2 extends the phpunit test classes so I doubt you can run them without using the cakephp test shell.

We use Jenkins and our own custom made scripts to automate tests.

floriank
  • 25,546
  • 9
  • 42
  • 66
  • Thanks for the answer. I'm quite disappointed, because FuelPHP also uses its own test cases, but it has a `bootstrap_phpunit.php` that takes care of this. I'm sure CakePHP also has something analogous to that, but if I can't find any, I'll just accept your answer. – Tamás Barta Nov 07 '14 at 09:44
0

I found a solution.

On a Japanese site I found an interesting idea:

First I had to duplicate webroot/test.php as webroot/phpunit.php, and replace the last line:

--- a/webroot/test.php
+++ b/webroot/phpunit-bootstrap.php
@@ -86,4 +86,4 @@ if (Configure::read('debug') < 1) {

 require_once CAKE . 'TestSuite' . DS . 'CakeTestSuiteDispatcher.php';

-CakeTestSuiteDispatcher::run();
+App::load('CakeTestSuiteCommand');

This makes it possible to use this as a bootstrap for PHPUnit.

Then you can create a phpunit.xml to ease the testing process.

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

<phpunit colors="true" stopOnFailure="false" bootstrap="webroot/phpunit-bootstrap.php">
    <testsuites>
        <testsuite name="AllTests">
            <directory suffix=".php">Test/Case</directory>
        </testsuite>
    </testsuites>
</phpunit>

Now I only need to add grunt-phpunit config to my Gruntfile.js:

phpunit: {
    options: {
        bin: 'phpunit',
        configuration: 'phpunit.xml',
        colors: true,
    },
    app: {
        options: {
            testsuite: 'AllTests',
        },
    },
}

Now if I run grunt phpunit, (or configure grunt watch to run the phpunit task upon changes, and change a file) PHPUnit runs my tests.

Tamás Barta
  • 1,617
  • 1
  • 19
  • 23