---
title: PHPUnit configuration
description: Configuration for Allure PHPUnit | Change allure-results directory | Configure link templates | Set up hooks
---

# Allure PHPUnit configuration

This page describes the configuration options that can be set in the configuration file for [Allure PHPUnit](/docs/phpunit/).

By default, the configuration file is looked up at `config/allure.config.php`, but this location can be overridden, see [Prepare your project](/docs/phpunit/#1-prepare-your-project).

## outputDirectory

Path to the directory where Allure PHPUnit will save the test results, see [How it works](/docs/how-it-works/). If the directory does not exist, it will be created. Defaults to `build/allure-results`.

```php
<?php

return [
    'outputDirectory' => 'build/allure-results',
];
```

## linkTemplates

A mapping of templates that can be used to construct full URLs from short identifiers, see the [reference](/docs/phpunit-reference/#link).

Each key must be a link type identifier, and each value must be a class implementing the `LinkTemplateInterface` interface, or an object of such a class. When processing a link of the given type, Allure PHPUnit will call the `buildUrl()` method of the class.

```php
<?php

use Qameta\Allure\Setup\LinkTemplateInterface;

return [
    'linkTemplates' => [

        'issue' =>
            new class implements LinkTemplateInterface {
                public function buildUrl(?string $name): ?string
                {
                    return "https://issues.example.com/$name";
                }
            },

        'tms' =>
            new class implements LinkTemplateInterface {
                public function buildUrl(?string $name): ?string
                {
                    return "https://tms.example.com/$name";
                }
            },

        'jira' =>
            new class implements LinkTemplateInterface {
                public function buildUrl(?string $name): ?string
                {
                    return "https://jira.example.com/browse/$name";
                }
            },
    ],
];
```

## setupHook

A function that will be called before initializing the Allure PHPUnit lifecycle.

```php
<?php

return [
    'setupHook' => function () {
        // ...
    },
];
```

## lifecycleHooks

An array of one or more classes, each implementing one or more [lifecycle hook interfaces](https://github.com/allure-framework/allure-php-commons2/tree/main/src/Hook) for Allure PHPUnit. For example, such a class can modify test results before or after Allure PHPUnit's standard processing.

```php
<?php

use Qameta\Allure\Hook\AfterTestStopHookInterface;
use Qameta\Allure\Hook\BeforeTestStartHookInterface;
use Qameta\Allure\Model\TestResult;

return [
   'lifecycleHooks' => [
        new class implements BeforeTestStartHookInterface, AfterTestStopHookInterface {

            public function beforeTestStart(TestResult $test): void
            {
                // ...
            }

            public function afterTestStop(TestResult $test): void
            {
                // ...
            }
        },
    ],
];
```

## threadDetector

A class implementing the `ThreadDetectorInterface` interface, or an object of such a class. If set, Allure PHPUnit will use its `getHost()` and `getThread()` methods to determine the host and thread identifiers for a current test. The test results will be placed on the [Timeline tab](/docs/timeline/) accordingly.

The example below assumes that you use [pthreads](https://www.php.net/manual/en/book.pthreads.php) for running your PHPUnit tests in parallel.

```php
<?php

use Qameta\Allure\PHPUnit\Setup\ThreadDetectorInterface;

return [
    'threadDetector' => new class implements ThreadDetectorInterface {

        function getHost(): ?string
        {
            return gethostname();
        }

        function getThread(): ?string
        {
            return strval(Thread::getCurrentThread() . getThreadId());
        }
    },
];
```
