Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

  • you can install PHPUnit with Composer:

    Code Block
    languagebash
    composer require phpunit/phpunit


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

    Code Block
    languagebash
    npm install selenium-standalone@latest -g
    selenium-standalone install


    • When Selenium is installed run command:

      Code Block
      languagebash
      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:

    Code Block
    languagexml
    <!-- 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:

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


3. Enable Simpletest module with drush command:

Code Block
languagebash
drush en simpletest


4. Run tests:

  • Run this test (for example):

    Code Block
    languagebash
    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