Skip to content

Latest commit

 

History

History
104 lines (80 loc) · 2.59 KB

File metadata and controls

104 lines (80 loc) · 2.59 KB

Running Tests in MODX-CLI

Test Suite Overview

The project has three test suites configured in phpunit.xml.dist:

  1. default - Unit tests only

    • Excludes integration tests
    • Fast execution
    • No external dependencies required
  2. integration - Integration tests only

    • Requires MODX installation or mocked environment
    • Most tests are skipped unless MODX_INTEGRATION_TESTS=1 is set
  3. all - Complete test suite

    • Includes both unit and integration tests
    • Recommended for comprehensive testing

Running Tests

Run Unit Tests Only (Default)

./vendor/bin/phpunit
# or explicitly:
./vendor/bin/phpunit --testsuite default

Run Integration Tests Only

./vendor/bin/phpunit --testsuite integration

Run Integration Tests via Dedicated Config

MODX_INTEGRATION_TESTS=1 ./vendor/bin/phpunit -c phpunit.integration.xml

Run All Tests (Unit + Integration)

./vendor/bin/phpunit --testsuite all

Running Tests with Coverage

Generate Coverage for All Tests

XDEBUG_MODE=coverage ./vendor/bin/phpunit --testsuite all --coverage-html=var/coverage/html

Generate Coverage for Unit Tests Only

XDEBUG_MODE=coverage ./vendor/bin/phpunit --testsuite default --coverage-html=var/coverage/html

Quick Coverage Summary (Text Only)

XDEBUG_MODE=coverage ./vendor/bin/phpunit --testsuite all --coverage-text

Generate Coverage Reports (HTML + Text + Clover)

XDEBUG_MODE=coverage ./vendor/bin/phpunit --testsuite all

This generates:

  • HTML report: var/coverage/html/index.html
  • Text report: var/coverage/coverage.txt
  • Clover XML: var/coverage/clover.xml

Test Count Reference

Test counts change as coverage expands. Use the PHPUnit output (or --list-tests) for current totals.

Troubleshooting

Issue: Not all tests are running

Solution: Make sure you're using --testsuite all to run both unit and integration tests.

Issue: Integration tests are skipped

Reason: Integration tests require a live MODX environment or the MODX_INTEGRATION_TESTS=1 flag. Solution: Set the environment variable:

MODX_INTEGRATION_TESTS=1 ./vendor/bin/phpunit --testsuite integration

Issue: Coverage takes too long

Solution: Run coverage on unit tests only:

XDEBUG_MODE=coverage ./vendor/bin/phpunit --testsuite default

View Coverage Reports

Open HTML Coverage Report

open var/coverage/html/index.html
# or on Linux:
xdg-open var/coverage/html/index.html

View Text Coverage Summary

cat var/coverage/coverage.txt