0
votes

I'm trying to create a build process using phing. During this process I want to run the composer install script and phpunit, which is installed by composer

Inside my buildfile I have 2 targets.

<target name="composer">
    <composer command="install" composer="./composer.phar" />
    <autoloader autoloaderpath="./vendor/autoload.php" />
</target>
<target name="phpunit" depends="composer">
    <if>
        <os family="windows" />
        <then>
            <property name="phpunit.executable" value="phpunit.bat" />
        </then>
        <else>
            <property name="phpunit.executable" value="phpunit" />
        </else>
    </if>
    <exec executable="vendor/bin/${phpunit.executable}"
      dir="${project.basedir}" level="debug"
      returnProperty="phpunit.return">
        <arg line="--configuration" />
        <arg file="${project.basedir}/phpunit.xml" />
    </exec>
</target>

The composer.phar and phpunit.xml are in my project base. Now if I run the phpunit target I can see that the dependencies are checked and installed if needed. But PHPUnit only returns

PHPUnit 5.7.21 by Sebastian Bergmann and contributors.

and that is it. No tests are actually run. It seems like the configuration file is never read.

If I remove the depends from the phpunit target and run then, the tests are actually completed and logs and coverage report created. I'm using exec instead of the phpunit task because phings code coverage seems to have trouble with the backslashes in namespaces.

This is actually a Symfony project and calling

bin/console cache:warmup -e test

fixes the problem

Though calling PHPUnit from command line after composer install does actually run the tests.

Is there anywhere in phing or PHPUnit where I can change that timeout? The max execution time for php is set to 0.

2
How about removing <autoloader autoloaderpath="./vendor/autoload.php" />?localheinz
@localheinz I already tried removinig the depends and adding the <composer> task to the phpunit target, without the autoloader. I also tried running composer via <exec>. PHPUnit still failed.Ronald

2 Answers

1
votes

How about adjusting build.xml to create a task to warm up the cache:

<target name="cache-warmup">
    <exec command="bin/console cache:warmup -e test" />
</target> 

and then have the phpunit task also depend on that task:

<target name="phpunit" depends="composer cache-warmup">
    ...
</target> 
0
votes

As of Phing 3.x you can also use the SymfonyConsoleTask

<project name="symfony-cmd" default="phpunit" basedir=".">

    <target name="setup">

        <composer command="install" composer="./composer.phar" />

        <autoloader autoloaderpath="./vendor/autoload.php" />

        <symfonyconsole console="./bin/console" command="cache:warmup">
            <arg name="env" value="test" />
        </symfonyconsole>

    </target>

    <target name="phpunit" depends="setup">
        <!-- ... -->
    </target>

</project>