githubEdit

Testing

PHP Testing

Chamilo uses PHPUnit for backend testing.

Test Database Setup

Tests require a dedicated database. Create .env.test.local with your test database credentials:

DATABASE_HOST='127.0.0.1'
DATABASE_PORT='3306'
DATABASE_NAME='chamilo_test'
DATABASE_USER='root'
DATABASE_PASSWORD='root'

Then initialise the test database:

php bin/console --env=test cache:clear
php bin/console --env=test doctrine:database:create
php bin/console --env=test doctrine:schema:create
php bin/console --env=test doctrine:fixtures:load --no-interaction

To reset after schema changes:

php bin/console --env=test doctrine:schema:update --force --complete

Running Tests

Test Location

Tests are in the tests/ directory:

Test Types

  • Unit/Integration tests — PHPUnit tests in CoreBundle/ and CourseBundle/; most hit a real database (via dama/doctrine-test-bundle)

  • Functional (API) tests — Extend AbstractApiTest and test HTTP endpoints end-to-end

  • Behat tests — Browser-level acceptance tests in tests/behat/features/ (see below)

Behat (End-to-End) Tests

Chamilo has a Behat test suite for browser-level acceptance testing. It requires a running Chamilo instance, Chrome, and ChromeDriver.

Configure the base URL in tests/behat/behat.yml before running.

Frontend Checks

PHP Code Quality

Chamilo uses ECS (Easy Coding Standard), PHPStan, and Psalm for code quality. Composer shortcuts are available for each:

Note: there is no php-cs-fixer in this project. ECS (symplify/easy-coding-standard) is the code style tool.

Continuous Integration

Pull requests are automatically checked by four GitHub Actions workflows:

Workflow
What it runs

phpunit.yml

PHPUnit test suite

format_code.yml

ECS code style check

php_analysis.yml

Psalm, Doctrine schema validation, security checker

behat.yml

Behat end-to-end tests

Last updated

Was this helpful?