Opigno LMS User manual


How to run unit tests

1. Install PHPUnit and Selenium (for FunctionalJavascript tests);

  • you can install PHPUnit with Composer:

    composer require phpunit/phpunit
  • NOTE: For Selenium you need to install first npm. Then you can install Selenium with these commands:

    npm install selenium-standalone@latest -g
    selenium-standalone install
    • When Selenium is installed run command:

      selenium-standalone start
  • You need to apply this patch contrib-modules-issues-test-running.patch.zip (Our modules depend on many contrib modules and some of these modules have issues (which can be fixed in future)

2. Check PHPUnit configuration for testing:

  • Find core/phpunit.xml (if not exist just copy phpunit.xml.dist and rename to phpunit.xml)
  • In this file you need to specify these settings:

    <!-- Example SIMPLETEST_BASE_URL value: http://localhost -->
    <env name="SIMPLETEST_BASE_URL" value=""/>
    <!-- Example SIMPLETEST_DB value: mysql://username:password@localhost/databasename#table_prefix -->
    <env name="SIMPLETEST_DB" value=""/>
    <!-- Example BROWSERTEST_OUTPUT_DIRECTORY value: /path/to/webroot/sites/simpletest/browser_output -->
    <env name="BROWSERTEST_OUTPUT_DIRECTORY" value=""/>
  • For Selenium running you need to add this line in phpunit.xml:

    <env name="MINK_DRIVER_ARGS_WEBDRIVER" value='["chrome", null, "http://localhost:4444/wd/hub"]'/>

3. Enable Simpletest module with drush command:

drush en simpletest

4. Run tests:

  • Run this test (for example):

    sudo -u www-data -E vendor/bin/phpunit -c core --group opigno_learning_path
    
    # Or the same with debug info:
    sudo -u www-data -E vendor/bin/phpunit -c core --group opigno_learning_path --printer="\Drupal\Tests\Listeners\HtmlOutputPrinter

Copyright 2021 Connect-i. All Rights Reserved - https://www.opigno.org