PHPackages                             contao/test-case - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Testing &amp; Quality](/categories/testing)
4. /
5. contao/test-case

ActiveLibrary[Testing &amp; Quality](/categories/testing)

contao/test-case
================

Contao test case

5.7.3(4mo ago)6296.7k↑18.3%420LGPL-3.0-or-laterPHPPHP ^8.3

Since Nov 3Pushed 2mo ago3 watchersCompare

[ Source](https://github.com/contao/test-case)[ Packagist](https://packagist.org/packages/contao/test-case)[ Fund](https://to.contao.org/donate)[ RSS](/packages/contao-test-case/feed)WikiDiscussions main Synced 1mo ago

READMEChangelogDependencies (12)Versions (271)Used By (20)

Contao test case
================

[](#contao-test-case)

Contao is an open source PHP content management system for people who want a professional website that is easy to maintain. Visit the [project website](https://contao.org) for more information.

The Contao test case provides a PHPUnit test case with some useful methods for testing Contao. Run `php composer.phar require --dev contao/test-case` to install the package and then use it in your test classes:

```
use Contao\TestCase\ContaoTestCase;

class MyTest extends ContaoTestCase
{
}
```

Symfony container
-----------------

[](#symfony-container)

The `getContainerWithContaoConfiguration()` method creates a Symfony container builder object with the default configuration of the Contao core extension.

```
$container = $this->getContainerWithContaoConfiguration();

echo $container->getParameter('contao.upload_path'); // will output "files"
```

You can also set a project directory:

```
$container = $this->getContainerWithContaoConfiguration('/tmp');

echo $container->getParameter('kernel.project_dir'); // will output "/tmp"
echo $container->getParameter('kernel.root_dir'); // will output "/tmp/app"
echo $container->getParameter('kernel.cache_dir'); // will output "/tmp/var/cache"
```

Contao framework
----------------

[](#contao-framework)

The `createContaoFrameworkMock()` and `createContaoFrameworkStub()` methods create a mock or stub object of an initialized Contao framework.

```
$framework = $this->createContaoFrameworkMock();
$framework
    ->expect($this->atLeastOnce())
    ->method('initialize')
;
```

The method automatically adds a Config adapter with the Contao settings:

```
$framework = $this->createContaoFrameworkStub();
$config = $framework->getAdapter(Contao\Config::class);

echo $config->get('datimFormat'); // will output "'Y-m-d H:i'"
```

You can optionally add more adapters as argument:

```
$adapters = [
    Contao\Config::class => $configAdapter,
    Contao\Encryption::class => $encryptionAdapter,
];

$framework = $this->createContaoFrameworkStub($adapters);
```

A given Config adapter will overwrite the default Config adapter.

Adapters
--------

[](#adapters)

The `createAdapterMock()` and `createAdapterStub()` methods will create an adapter mock or stub object with the given methods.

```
$adapter = $this->createAdapterStub(['findById']);
$adapter
    ->method('findById')
    ->willReturn($model)
;

$framework = $this->createContaoFrameworkStub([Contao\FilesModel::class => $adapter]);
```

Adapters with a simple return value like above can be further simplified:

```
$adapter = $this->createConfiguredAdapterStub(['findById' => $model]);
```

This code does exactly the same as the code above.

Classes with magic properties
-----------------------------

[](#classes-with-magic-properties)

The `createClassWithPropertiesMock()` and `createClassWithPropertiesStub()` methods will create a mock or stub object of a class that uses magic `__set()` and `__get()` methods to manage properties.

```
$mock = $this->createClassWithPropertiesStub(Contao\PageModel::class);
$mock->id = 2;
$mock->title = 'Home';

echo $mock->title; // will output "Home"
```

If the class is read-only, you can optionally pass the properties as constructor argument:

```
$properties = [
    'id' => 2,
    'title' => 'Home',
];

$mock = $this->createClassWithPropertiesStub(Contao\PageModel::class, $properties);

echo $mock->title; // will output "Home"
```

Token storage
-------------

[](#token-storage)

The `createTokenStorageStub()` creates a token storage stub object with a token returning either a Contao back end or front end user.

```
$tokenStorage = $this->createTokenStorageStub(Contao\BackendUser::class);
$user = $tokenStorage->getToken()->getUser();
```

Temporary directory
-------------------

[](#temporary-directory)

The `getTempDir()` method creates a temporary directory based on the test class name and returns its path.

```
$fs = new Filesystem();
$fs->mkdir($this->getTempDir().'/var/cache');
```

The directory will be removed automatically after the tests have been run. For this to work, please make sure to always call the parent `tearDownAfterClass()` method if you define the method in your test class!

```
use Contao\TestCase\ContaoTestCase;

class MyTest extends ContaoTestCase
{
    public static function tearDownAfterClass()
    {
        // The temporary directory would not be removed without this call!
        parent::tearDownAfterClass();
    }
}
```

###  Health Score

68

—

FairBetter than 100% of packages

Maintenance83

Actively maintained with recent releases

Popularity41

Moderate usage in the ecosystem

Community37

Small or concentrated contributor base

Maturity98

Battle-tested with a long release history

 Bus Factor1

Top contributor holds 71.9% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~11 days

Recently: every ~0 days

Total

270

Last Release

126d ago

Major Versions

4.13.15 → 5.0.72022-11-14

4.13.16 → 5.0.102023-02-15

4.13.31 → 5.2.0-RC52023-07-24

4.13.43 → 5.3.82024-04-25

4.13.51 → 5.6.82025-07-14

PHP version history (7 changes)1.0.0PHP ^7.1

4.0.0PHP ^7.2

4.2.1PHP ^7.2 || ^8.0

4.13.2PHP ^7.4 || ^8.0

5.0.1PHP ^8.1

5.5.16PHP ^8.2

5.7.0-RC3PHP ^8.3

### Community

Maintainers

![](https://www.gravatar.com/avatar/3de3a0dd7c29df679eb280585220c17c1a7340b46c2792d5e8298be859acfbba?d=identicon)[leofeyer](/maintainers/leofeyer)

![](https://www.gravatar.com/avatar/8c7bdddffcaec444b7891b633f45fe2713d2b04ff21a6362fd748720d0822d58?d=identicon)[ausi](/maintainers/ausi)

---

Top Contributors

[![leofeyer](https://avatars.githubusercontent.com/u/1192057?v=4)](https://github.com/leofeyer "leofeyer (82 commits)")[![ausi](https://avatars.githubusercontent.com/u/367169?v=4)](https://github.com/ausi "ausi (12 commits)")[![aschempp](https://avatars.githubusercontent.com/u/1073273?v=4)](https://github.com/aschempp "aschempp (8 commits)")[![fritzmg](https://avatars.githubusercontent.com/u/4970961?v=4)](https://github.com/fritzmg "fritzmg (4 commits)")[![Toflar](https://avatars.githubusercontent.com/u/481937?v=4)](https://github.com/Toflar "Toflar (4 commits)")[![m-vo](https://avatars.githubusercontent.com/u/5305677?v=4)](https://github.com/m-vo "m-vo (2 commits)")[![bytehead](https://avatars.githubusercontent.com/u/754921?v=4)](https://github.com/bytehead "bytehead (2 commits)")

---

Tags

cmscontaophpphpunitsymfonytestcase

### Embed Badge

![Health badge](/badges/contao-test-case/health.svg)

```
[![Health](https://phpackages.com/badges/contao-test-case/health.svg)](https://phpackages.com/packages/contao-test-case)
```

###  Alternatives

[orchestra/testbench

Laravel Testing Helper for Packages Development

2.2k39.1M32.1k](/packages/orchestra-testbench)[codeception/codeception

All-in-one PHP Testing Framework

4.9k86.2M2.9k](/packages/codeception-codeception)[behat/behat

Scenario-oriented BDD framework for PHP

4.0k96.8M2.0k](/packages/behat-behat)[ergebnis/phpunit-slow-test-detector

Provides facilities for detecting slow tests in phpunit/phpunit.

1468.1M72](/packages/ergebnis-phpunit-slow-test-detector)[webmozarts/strict-phpunit

Enables type-safe comparisons of objects in PHPUnit

31252.7k5](/packages/webmozarts-strict-phpunit)[lastzero/test-tools

Increases testing productivity by adding a service container and self-initializing fakes to PHPUnit

2244.3k13](/packages/lastzero-test-tools)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
