Skip to main content

Extension unit testing

Pre-requests

  1. Install vanilla Magento CE 1.9 with magento_sample_data_for_1.9.1.0
  2. Install extension and switch to correct branch (currently phpunit for 2.0, 2.1.0 for 2.0+

How to run

  1. Install phpunit v4.8.x or later. 
    Get it from https://phpunit.de/, and include it in your path: mv phpunit.phar /usr/local/bin/phpunit

  2. Copy file app/etc/local.xml.phpunit.template into app/etc/local.xml.phpunit and edit the file (fields: dbname, secure_base_url, unsecure_base_url)
    Same DB has to be configured in both local.xml and local.xml.phpunit
  3. Run

    cd /magento_root/
    
    # run all tests
    phpunit
     
    # run with debug info, will show all test parameters
    phpunit --debug
     
    # include HTML report in the local.dev/report/index.html
    phpunit --coverage-html report
     
    # run through XDebug, and debug your tests in the IDE (works for PhpStorm 10)
    export XDEBUG_CONFIG="remote_enable=1 remote_mode=req remote_port=9000 remote_host=127.0.0.1 remote_connect_back=0"
    phpunit
     
    # disable XDebug
    export XDEBUG_CONFIG=""
  4. Expected result:

    $ phpunit
    PHPUnit 4.7.6 by Sebastian Bergmann and contributors.
    ..................
    Time: 7.9 seconds, Memory: 54.50Mb
    OK (18 tests, 18 assertions)

How to add test for: