PHPackages                             cds-uwb/nette-presenter-tests - 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. cds-uwb/nette-presenter-tests

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

cds-uwb/nette-presenter-tests
=============================

Library based on PHPUnit framework to test Nette presenters via simple API

v1.0.1(3mo ago)036[1 issues](https://github.com/CDS-UWB/nette-presenter-tests/issues)MITPHPPHP &gt;=8.2CI passing

Since Mar 17Pushed 3mo agoCompare

[ Source](https://github.com/CDS-UWB/nette-presenter-tests)[ Packagist](https://packagist.org/packages/cds-uwb/nette-presenter-tests)[ RSS](/packages/cds-uwb-nette-presenter-tests/feed)WikiDiscussions main Synced 3w ago

READMEChangelog (2)Dependencies (14)Versions (4)Used By (0)

[ ![](https://camo.githubusercontent.com/b004a33a75fe2a27a8432648d719202a59b2510855507e591e47f9d842158582/68747470733a2f2f6364732e7a63752e637a2f696d616765732f6c6f676f2e737667)](https://cds.zcu.cz)

Nette Presenter Tests
=====================

[](#nette-presenter-tests)

[![Tests](https://github.com/CDS-UWB/nette-presenter-tests/actions/workflows/tests.yml/badge.svg)](https://github.com/CDS-UWB/nette-presenter-tests/actions/workflows/tests.yml)

Library based on PHPUnit framework to test Nette presenters via simple API.

The main functionality of Nette presenters is in their actions invoked by requests. The library allows to simply invoke presenter actions like as called from browser. Another functionality is handling form submission that can be also tested.

The easiest way to use the library is to extend `Cds\NettePresenterTests\PresenterTestCase`which provides all traits and also contains abstract method `configureContainer` that must be implemented to provide DI container for presenter creation.

Example of test class that extends `PresenterTestCase`:

```
final class PresenterTest extends Cds\NettePresenterTests\PresenterTestCase
{
    protected function setUp() : void
    {
        parent::setUp();

        // Initialize presenter for all following tests
        $this->presenter = $this->createPresenter(MyPresenter::class);
    }

    public function testAction(): void
    {
        // Invoke MyPresenter:default action with parameters
        $response = $this->request('default', [
            'param1' => 'value1',
        ]);

        // Check the presenter response is TextResponse with non-empty result
        self::assertNonEmptyTextResponse($response);
    }

    public function testActionRedirect(): void
    {
        // Invoke MyPresenter:redirect action
        $response = $this->request('redirect');

        // Check the presenter response is RedirectResponse with given target
        self::assertRedirectResponseTo('MyPresenter:default', $response);
    }

    public function testFormSubmit(): void
    {
        // Submit form 'testForm' via action default
        $response = $this->submitForm('default', [], [
            'key1' => 'value1',
            'key2' => [1, 2, 3],
        ], 'testForm');

        // Check the presenter response is RedirectResponse with given target
        self::assertRedirectResponseTo('MyPresenter:default', $response);
    }

    // Presenter instance is created from the Nette DI container.
    // In this function you can configure the container as needed for your tests.
    // This is the simplest example how to create the container.
    protected function configureContainer(): Container
    {
        $tempDirectory = __DIR__ . '/temp';

        $configurator = new Configurator();
        $configurator->setDebugMode(true);
        $configurator->setTempDirectory($tempDirectory);

        return $configurator->createContainer();
    }
}
```

If you don't want to extend `Cds\NettePresenterTests\PresenterTestCase`, you can use the traits directly. When using traits only you must create the DI container yourself and expose it as a protected `Container $container` property because `PresenterCreate` uses `$this->container` to instantiate presenters.

```
final class PresenterTest extends \PHPUnit\Framework\TestCase
{
    // Whole functionality is available via traits
    use \Cds\NettePresenterTests\Traits\Presenter;

    // Provide container for the traits
    protected Container $container;

    protected function setUp() : void
    {
        parent::setUp();

        $tempDirectory = __DIR__ . '/temp';

        $configurator = new Configurator();
        $configurator->setDebugMode(true);
        $configurator->setTempDirectory($tempDirectory);

        // Create and store the container so traits can use it
        $this->container = $configurator->createContainer();

        // Initialize presenter for all following tests
        $this->presenter = $this->createPresenter(MyPresenter::class);
    }

    // Tests ...
}
```

Available traits
----------------

[](#available-traits)

- `AssertResponse` - adds assertions that allow to check presenter responses.
- `ExpectErrors` - adds expectations to check raising presenter error via `error` method.
- `Presenter` - union trait that includes all other traits.
- `PresenterCreate` - add method to create instance of presenter from class name via Nette DI container.
- `PresenterRequest` - simple API for invoking requests on property `presenter` (uses `PresenterRun` methods).
- `PresenterRun` - main request API for invoking requests on given presenter.

Presenter mapping
-----------------

[](#presenter-mapping)

The library require mapping from presenter class to presenter name which is used in request. In normal application the name is built by router and then passed to presenter factory which create presenter instance. The library works directly on presenter instance, so it needs to convert presenter class to presenter name which is then passed to presenter request. Default implementation uses some predefined rules to convert class to name but if something else is needed, own implementation of `buildNameFromPresenter` can be implemented to provide required mapping.

```
final class MyTest extends \PHPUnit\Framework\TestCase
{
    use \Cds\NettePresenterTests\Traits\Presenter;

    protected function buildNameFromPresenter(string $class) : string
    {
        // All request are from TestPresenter
        return 'Test';
    }
}
```

It's also possible to use Nette's presenter factory to provide class to name mapping but `unformatPresenterClass` is marked as internal and deprecated. Alternatively `nepada/presenter-mapping` can be used which provides this method (for now).

More examples
-------------

[](#more-examples)

### File upload testing

[](#file-upload-testing)

The library also allows test file uploading as part of form submission. The definition of file upload is specified as part of form data only using `$this->uploadFile` method that specifies file name, and it's content. It's also possible to specify upload result code (PHP's `UPLOAD_ERR_*` constants).

```
final class PresenterTest extends \PHPUnit\Framework\TestCase
{
    // Whole functionality is available via traits
    use \Cds\NettePresenterTests\Traits\Presenter;

    protected function setUp() : void
    {
        parent::setUp();

        // Initialize presenter for all following tests
        $this->presenter = $this->createPresenter(MyPresenter::class);
    }

    public function testFileUpload(): void
    {
        $response = $this->submitForm('default', [], [
            'file1' => $this->uploadFile('file1.txt', 'Hello World!'),
            // Upload failure can be tested via error argument
            'file2' => $this->uploadFile(error: UPLOAD_ERR_CANT_WRITE),
        ], 'testForm');

        // Check the presenter response is RedirectResponse with given target
        self::assertRedirectResponseTo('MyPresenter:default', $response);
    }
}
```

### Testing without presenter property

[](#testing-without-presenter-property)

It's possible test multiple different presenters without `presenter` property. Testing is done by `PresenterRequest` trait and its function `runPresenter` that allow to pass any presenter as argument.

```
final class PresenterTest extends \PHPUnit\Framework\TestCase
{
    use \Cds\NettePresenterTests\Traits\PresenterRequest;
    use \Cds\NettePresenterTests\Traits\PresenterCreate;

    public function testAction(): void
    {
        $presenter = $this->createPresenter(MyPresenter::class);

        // Invoke MyPresenter:default action with parameters
        $response = $this->runPresenter($presenter, 'default', [
            'param1' => 'value1',
        ]);

        // Check the presenter response is TextResponse with non-empty result
        self::assertNonEmptyTextResponse($response);
    }

}
```

###  Health Score

39

—

LowBetter than 85% of packages

Maintenance81

Actively maintained with recent releases

Popularity10

Limited adoption so far

Community8

Small or concentrated contributor base

Maturity48

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 83.3% 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 ~1 days

Total

2

Last Release

99d ago

PHP version history (2 changes)v1.0.0PHP ^8.4

v1.0.1PHP &gt;=8.2

### Community

Maintainers

![](https://www.gravatar.com/avatar/4ff9ecec714558288e706225720ad1015776936ccbb8d85e1ab814e37e36e1f6?d=identicon)[cds](/maintainers/cds)

---

Top Contributors

[![fifal](https://avatars.githubusercontent.com/u/54062667?v=4)](https://github.com/fifal "fifal (5 commits)")[![NTSFka](https://avatars.githubusercontent.com/u/6008678?v=4)](https://github.com/NTSFka "NTSFka (1 commits)")

###  Code Quality

TestsPHPUnit

Static AnalysisPHPStan

Code StylePHP CS Fixer

Type Coverage Yes

### Embed Badge

![Health badge](/badges/cds-uwb-nette-presenter-tests/health.svg)

```
[![Health](https://phpackages.com/badges/cds-uwb-nette-presenter-tests/health.svg)](https://phpackages.com/packages/cds-uwb-nette-presenter-tests)
```

###  Alternatives

[ublaboo/datagrid

DataGrid for Nette Framework: filtering, sorting, pagination, tree view, table view, translator, etc

2972.0M24](/packages/ublaboo-datagrid)

PHPackages © 2026

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