Skip to content

Testing with Pest

Pyxis CMS focuses on high data integrity and routing security. The entire API business logic is covered by functional feature tests using the Pest v4 framework (built on PHPUnit 12).

Tests should be executed within the Docker environment (admin container).

Run all tests:

Terminal window
./vendor/bin/pest

Run a specific test file:

Terminal window
./vendor/bin/pest tests/Feature/Api/PageControllerTest.php

Watch mode (TDD):

Terminal window
./vendor/bin/pest --watch

Database: Tests utilize an isolated SQLite in-memory database (:memory:). This ensures tests are extremely fast and do not interfere with your local development data.

Database State: We use the RefreshDatabase trait. This means migrations are run before each test, and the database is wiped immediately after the test completes.

Cache: The application cache (including global settings and localization) is flushed before each test case to prevent data leakage between tests.


We verify that the API correctly hides or shows content. A page is only accessible if:

  • Status is published.
  • Visibility is NOT set to private.
  • Publication date (published_at) is in the past or null.

Pyxis CMS supports nested pages (e.g., /about-us/team). We test:

  • Slug Resolution: Ensuring the system finds the correct page based on the final segment of the URL.
  • Path Mismatch: Ensuring that attempting to access a child page while bypassing the parent slug in the URL returns a 404 error.

We verify that the homepage_id stored in the settings table correctly maps the root API request to the specific homepage model.


Never insert data manually into the database during tests. Always use Factories to ensure proper relationship handling and UUID generation.

Example of creating a draft page: [INSERT CODE: Page::factory()->create([‘status’ => ‘draft’])]

UserFactory automatically handles the creation of required roles in the test database to maintain foreign key integrity.


No such table: settings Usually means a middleware (like SetLocale) is trying to fetch data before migrations have finished. Ensure your test uses the RefreshDatabase trait.

Unique constraint failed: roles.slug Occurs when multiple tests try to create a role with the same slug (e.g., “admin”). Use unique slugs in your RoleFactory.

Integrity constraint violation: users.role_id Every user in Pyxis CMS must have a role. Ensure your UserFactory always returns a valid role_id.