Skip to main content
Version: Next
PlatformNextopen-dxp/opendxpGitHub

Testing

This chapter shows you how to test an OpenDXP project or bundle. You write the tests with Pest and create their data with factories. Core, every bundle and every project use the same setup.

The layers​

The testing tools of OpenDXP are built in layers. Each layer builds on the layer below it. Its documentation does not repeat the layers below:

LayerWhat it gives youDocumentation
open-dxp/test-foundationThe test kernel, the test cases, the browser and the commands that build the application.README of the test foundation
OpenDxp\Test in OpenDXPFactories for the models of OpenDXP, Pest expectations and installers for definitions.This chapter
The test API of a bundleFactories, bricks and expectations for the models of one bundle.The testing page of the bundle
Your projectThe tests of your own code, with the test APIs of the bundles you use.Testing a Project

The classes of OpenDxp\Test ship with OpenDXP itself. They need Pest and Foundry, which the test foundation brings in.

The pieces​

PieceWhat it gives you
PestThe test framework. A test is a function with a sentence as its name.
FoundryThe factories that create test data.
open-dxp/test-foundationEverything a package needs to run tests, and the setup of a package.
Test APIThe reference of OpenDxp\Test.
OpenDXP TestkitRuns your tests and static checks on your machine.
OpenDXP workflowsRun the tests and static checks of a bundle in CI.

Set up and run​

The test foundation describes the setup in Set up a bundle and Set up a project. Run the tests describes how you run the tests.

A first test​

use OpenDxp\Model\Document;
use OpenDxp\Test\Factory\DocumentPageFactory;

it('finds a page by its path', function () {
$page = DocumentPageFactory::createOne(['key' => 'about-us']);

$found = Document::getByPath('/about-us');

expect($found?->getId())->toBe($page->getId());
});

The test runs against a real OpenDXP installation with a real database. The factory creates the page and saves it. Everything the test writes is rolled back when it ends, so the next test starts clean.

The name of the test is a sentence that says what OpenDXP guarantees. The body has three blocks: it prepares, it acts, and it checks. Writing Tests explains this form.

Next​

PageRead it when
Writing Testsyou write your first tests
Factories and Storiesyour tests need data
Test APIyou look for a factory, a state or an expectation
Shipping a Test APIyour bundle offers test classes to other packages
Testing a Projectyou test a project that uses several bundles
Core Testsyou contribute to the test suite of OpenDXP