Search code examples
phpunit-testingdeploymentphpunitibm-cloud

How to use Bluemix Build and Deploy Test Job with PHP Unit Testing


I am trying to setup a build and deploy pipeline on Bluemix for my PHP application. I am using PHPUnit for testing but can't seem to get the test stage to call PHPUnit because it isn't installed. The Build and Deploy stages work perfectly for me I am just trying to add a test stage between them. The problem is that PHP isn't even installed in the test stage. I quick php -v will give a command not found error. Do I have to install php, apache, composer, and phpunit just to get this test stage to work? Is there a better way to do this?


Solution

  • I ended up installing apache, php7, and composer in order to get phpunit working. Here are the commands I ran during a test stage. There are some echo and ls statements that I was using to help me debug the installations. My tests are under the tests folder in the root of my directory like test/exampleTest.php and I have phpunit create an xml output file called tests/Test.xml and then supply that file to the box asking "Test Result File Pattern" so then Bluemix can read that file to know if the Tests succeeded or failed.

    #!/bin/bash
    # invoke tests here
    echo "  adding repo"
    sudo add-apt-repository ppa:ondrej/php
    echo "  updating apt-get"
    sudo apt-get -y update
    echo " installing apache2"
    sudo apt-get -y install apache2
    echo " installing php7.0"
    sudo apt-get -y --force-yes install php7.0 libapache2-mod-php7.0 php7.0-xml php7.0-cli php7.0-common php7.0-fpm php7.0-curl php7.0-gd php7.0-bz2
    echo " PHP TESTING"
    php -v
    echo " PHP TESTING 2"
    php -r 'echo "\n\nYour PHP installation is working fine.\n\n\n";'
    echo "  downloading composer"
    curl -sS https://getcomposer.org/installer | php
    echo "  installing composer"
    php composer.phar install
    echo "  ls"
    ls
    echo "  ls ../"
    ls ../
    echo "  ls vendor"
    ls vendor
    echo "  running tests"
    vendor/bin/phpunit --log-junit tests/Test.xml --bootstrap vendor/autoload.php tests