Giter Site home page Giter Site logo

enhanced-drupal-phpunit-results's Introduction

Enhanced Drupal PHPUnit Results

Codecov GitHub branch checks state License

Provides tooling to improve the output of PHPUnit tests with Drupal.

After

Spotlight After

Before

Spotlight Before

Highlights

  • Command-click/control click URL to open artifact in web browser.
  • Command-click/control click file+line to open in IDE (PHPStorm / VSCode / MacVim / Emacs / Sublime Text / Textmate)
  • The URL fetched is shown.
  • drupalGet/drupalLogin/htmlOutput/submitForm page loads are detected,
  • Icon shown indicating whether artifact is associated with a page load: ๐Ÿ“„ drupalGet ๐Ÿ›‚ drupalLogin โšก๏ธ htmlOutput ๐Ÿ– submitForm
  • Test method is green or red depending on test pass/failure.
  • Execution stack is shown between the test method and the point of page load.
  • For direct invocations of page load from a test, a short stack is shown.

The project is intended for use with functional tests, specifically projects utilizing Drupal Test Traits. Its recommended to utilize phpunit --printer or create a new phpunit.xml to separate Kernel and Unit tests.

Tests will need to use the included trait. Out of the box this enhancement cannot be used with tests out of your control, unless base test classes are patched, such as \Drupal\Tests\BrowserTestBase.

Drupal is a registered trademark of Dries Buytaert.

Installation and setup

composer require dpi/enhanced-drupal-phpunit-results

In PHPUnit configuration files such as phpunit.xml, phpunit.xml.dist, etc, modify printerClass to reference the class from this library:

<phpunit printerClass="\dpi\EnhancedDrupalPhpunitResults\EnhancedResultPrinter" />

In base test files, replace use \Drupal\Tests\UiHelperTrait with use \dpi\EnhancedDrupalPhpunitResults\CombinedEnhancedUiHelperTrait.

Or if there are collisions,

use EnhancedUiHelperTrait {
    EnhancedUiHelperTrait::htmlOutput insteadof UiHelperTrait;
}

Configuration

Optional configuration is available.

Set these values as environment variables in the executor or phpunit.ini file.

IDE launch links

Will trigger control/command-clicks on file paths to open in an editor of choice.

Possible values:

  • emacs
  • macvim
  • phpstorm
  • sublime
  • textmate
  • vscode

export ENHANCED_RESULTS_IDE=phpstorm

<php>
    <env name="ENHANCED_RESULTS_IDE" value="phpstorm" />
</php>

IDE Launch Links

Repeat context

Will repeat the executing test at the top of the stack. Normally the executed test is only printed once at the beginning. This option will print the test in context for each drupalGet at the top of the stack. This is useful for tests with many drupalGets.

export ENHANCED_RESULTS_USE_REPEAT_CONTEXT=TRUE

<php>
    <env name="ENHANCED_RESULTS_USE_REPEAT_CONTEXT" value="TRUE" />
</php>

IDE Launch Links

Disable trimming columns to terminal width

Disable trimming file and URL text strings to terminal width. Instead strings will display untruncated.

export ENHANCED_RESULTS_DISABLE_TRIM_COLUMNS=TRUE

<php>
    <env name="ENHANCED_RESULTS_DISABLE_TRIM_COLUMNS" value="TRUE" />
</php>

IDE Launch Links

Use sequential IDS instead of artifact numbers

Display numbers next to each drupalGet, starting from 1, relative to the current test run. Instead of artifact numbers.

export ENHANCED_RESULTS_USE_SEQUENTIAL_IDS=TRUE

<php>
    <env name="ENHANCED_RESULTS_USE_SEQUENTIAL_IDS" value="TRUE" />
</php>

Change file prefix

Changes file prefix so clickable files work, useful when used with Docker mounts or symlinks.

export ENHANCED_RESULTS_FILE_PREFIX=/home/user/www

<php>
    <env name="ENHANCED_RESULTS_FILE_PREFIX" value="/home/user/www" />
</php>

Other notes

  • Utilize Drupal's builtin BROWSERTEST_OUTPUT_BASE_URL if artifacts are accessed by a different URL by the host OS, than the test runner. This helps to resolve issues with incorrect clickable artifact URLs.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.