PHPackages                             forrest79/presenter-tester - 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. forrest79/presenter-tester

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

forrest79/presenter-tester
==========================

Testing tool for Nette presenter

v0.7.0(7mo ago)26.9k↓46%(BSD-3-Clause and MIT)PHPPHP ^8.3CI passing

Since Jul 16Pushed 2mo agoCompare

[ Source](https://github.com/forrest79/presenter-tester)[ Packagist](https://packagist.org/packages/forrest79/presenter-tester)[ RSS](/packages/forrest79-presenter-tester/feed)WikiDiscussions master Synced 1mo ago

READMEChangelogDependencies (11)Versions (20)Used By (0)

Forrest79/PresenterTester
=========================

[](#forrest79presentertester)

[![Latest Stable Version](https://camo.githubusercontent.com/080395df3d0bd9026937d87c4dc6ce4d6c5661f56d2ce098ed1df84ba9a4bc48/68747470733a2f2f706f7365722e707567782e6f72672f666f727265737437392f70726573656e7465722d7465737465722f76)](//packagist.org/packages/forrest79/presenter-tester)[![Monthly Downloads](https://camo.githubusercontent.com/0c7fd06f599e7c650825e9efbd43d268bc006c67b6bb3e01203b2c06e7c0c0ad/68747470733a2f2f706f7365722e707567782e6f72672f666f727265737437392f70726573656e7465722d7465737465722f642f6d6f6e74686c79)](//packagist.org/packages/forrest79/presenter-tester)[![License](https://camo.githubusercontent.com/e9d565c7333a4864179463db29bd3a62fd210b630659d3801fa24b0db20a82a8/68747470733a2f2f706f7365722e707567782e6f72672f666f727265737437392f70726573656e7465722d7465737465722f6c6963656e7365)](//packagist.org/packages/forrest79/presenter-tester)[![Build](https://github.com/forrest79/presenter-tester/actions/workflows/build.yml/badge.svg?branch=master)](https://github.com/forrest79/presenter-tester/actions/workflows/build.yml)

> [Mango Presenter Tester](https://github.com/mangoweb-backend/presenter-tester) fork just for personal use with some tweaks.

Testing tool for Nette presenter with easy to use API.

Installation
------------

[](#installation)

The recommended way to install is via Composer:

```
composer require --dev forrest79/presenter-tester

```

It requires PHP version 8.1.

Integration &amp; configuration
-------------------------------

[](#integration--configuration)

If you are using the power of Nette DI Container in your tests, you can use Presenter Tester in your current testing environment. All you need is to register PresenterTester service in `.neon` configuration for tests.

```
services:
	- Forrest79\PresenterTester\PresenterTester(baseUrl: "http://my-app.test")
```

You can also specify a list of [listeners](#listeners):

```
parameters:
	baseUrl: 'http://my-app.dev'

services:
	- Forrest79\PresenterTester\PresenterTester(
		baseUrl: %baseUrl%
		listeners: [
			MyListener()
		]
	)
```

Usage
-----

[](#usage)

Get `PresenterTester` service from DI container. When you get the service, you can start testing your presenters:

```
$testRequest = $presenterTester->createRequest('Admin:Article')
	->withParameters([
		'action' => 'edit',
		'id' => 1,
	]);
$testResult = $presenterTester->execute($testRequet);
$testResult->assertRenders('%A%Hello world article editation%A%');
```

As you can see, you first create a `TestPresenterRequest` using `createRequest` method on `PresenterTester`. You pass a presenter name (without an action) and later you configure the test request. You can set additional request parameters like `action` or your own application parameters. There are many other things you can configure on the request, like form values or headers.

After the test request is configured, you pass it to `execute` method, which performs presenter execution and returns `TestPresenterResult`, which wraps `Nette\Application\IResponse` with some additional data collected during execution.

The `TestPresenterResult` contains many useful assert functions like render check or form validity check. In our example there is `assertRenders` method, which asserts that presenter returns `TextResponse` and that the text contains a given pattern. You probably already know the pattern format from [Tester\\Assert::match()](https://tester.nette.org/en/writing-tests#toc-assert-match) function.

### Sample test DI setup

[](#sample-test-di-setup)

For newer `Nette\Http` with readonly properties, you must define also `Forrest79\PresenterTester\HttpRequestFactory` in your test DI (if you use some own `Nette\Http\IRequest` implementation with a different constructor from the `Nette\Http\Request` you must extend `Forrest79\PresenterTester\HttpRequestFactory` and return your object that implements `Nette\Http\IRequest` interface). You can set some common properties here:

```
parameters:
	url: 'https://local.test/'

services:
    - Forrest79\PresenterTester\HttpRequestFactory(
        remoteAddress: %tests.remoteAddress% # dynamic parameter
    )
    - Forrest79\PresenterTester\PresenterTester(
        baseUrl: %url%
    )
    http.response:
        factory: Forrest79\PresenterTester\Mocks\Http\Response
        alteration: true
    session.session:
        factory: Forrest79\PresenterTester\Mocks\Http\Session
        alteration: true

database:
    config:
        password: %database.password% # dynamic parameter
        dbname: %database.dbname% # dynamic parameter

di:
    export:
        types: true
```

Helpers
-------

[](#helpers)

### MemorySessionHandler

[](#memorysessionhandler)

To bypass PHP session, you can use it for testing saving session just to memory. To do this, simply call this before running tests:

```
Forrest79\PresenterTester\Helpers\MemorySessionHandler::install();
```

Or use mocked `Session`.

Mocks
-----

[](#mocks)

> Some mocks are taken from

### Http\\Request

[](#httprequest)

> This is not working for actual `Nette\Http` with readonly properties. You can use `Forrest79\PresenterTester\Mocks\Http\Request` as simple mock but not as `Nette\Http\Request` in your test request. `Forrest79\PresenterTester\HttpRequestFactory` must be defined in your test DI.

To correct set SameSite cookie you need to redefine `Http\Request` for testing. You can use the original one from Nette:

```
services:
	http.request: Nette\Http\Request(
		url: Nette\Http\UrlScript(%baseUrl%)
		cookies: ['_nss': true] # Nette\Http\Helpers::STRICT_COOKIE_NAME
		remoteAddress: '255.254.253.252' # you can set also some other values, for example, REMOTE_ADDRESS
	)
```

Or you can use mocked `Http\Request` like this:

```
services:
	http.request: Forrest79\PresenterTester\Mocks\Http\Request(
		url: Nette\Http\UrlScript('http://my-app.dev')
		remoteAddress: '255.254.253.252' # you can set also some other values, for example, REMOTE_ADDRESS
	)
```

### Http\\Response

[](#httpresponse)

If you want to test cookies, that are sent, use mocked `Http\Response`:

```
services:
	http.response:
		factory: Forrest79\PresenterTester\Mocks\Http\Response
		alteration: true
```

Then get `Forrest79\PresenterTester\Mocks\Http\Response` service from DI container and read cookies by `getCookies()` method.

### Http\\Session

[](#httpsession)

Fake testing session. When you use this, you don't need to install `MemorySessionHandler`.

```
services:
	session.session:
		factory: Forrest79\PresenterTester\Mocks\Http\Session
```

### Mail\\Mailer

[](#mailmailer)

Fake mailer. All send emails via `Nette\Mail` are saved to the memory, and you can check them in tests.

```
services:
	mail.mailer:
		factory: Forrest79\PresenterTester\Mocks\Mail\Mailer
		alteration: true
```

Then get `Forrest79\PresenterTester\Mocks\Mail\Mailer` service from DI container and read last message with `getLastMessage()` method, all messages with `getMessages()` method or check sent message count with `count()` method or use `Countable` interface.

TestPresenterRequest API
------------------------

[](#testpresenterrequest-api)

**Beware that `TestPresenterRequest` is immutable object.**

### `withParameters(array $parameters)`

[](#withparametersarray-parameters)

Set application request parameters.

### `withForm(string $formName, array $post, array $files)`

[](#withformstring-formname-array-post-array-files)

Add form submission data to request. You have to specify a full component tree path to in `$formName`.

Presenter Tester supports forms with CSRF protection, but since it uses session, it is recommended to install [mangoweb/tester-http-mocks](https://github.com/mangoweb-backend/tester-http-mocks) package.

### `withSignal(string $signal, array $componentParameters = [])`

[](#withsignalstring-signal-array-componentparameters--)

With Presenter Tester, you can also easily test signal method.

### `withAjax`

[](#withajax)

(Not only) signals often use AJAX, which you can enable using this method.

### `withMethod(string $methodName)`

[](#withmethodstring-methodname)

Change the HTTP method. The default is `GET`. You don't have to explicitly set a method for forms.

### `withHeaders(array $headers)`

[](#withheadersarray-headers)

Pass additional HTTP headers.

### `withIdentity(Nette\Security\IIdentity $identity)`

[](#withidentitynettesecurityiidentity-identity)

Change the identity of the User, which is executing given request. This is useful when login is required to perform the action. You can implement [identity factory](#identity-factory), which provides a default identity for each request.

### `withPost(array $post)`

[](#withpostarray-post)

### `withFiles(array $files)`

[](#withfilesarray-files)

### `withRawBody(string$rawBody)`

[](#withrawbodystringrawbody)

TestPresenterResult API
-----------------------

[](#testpresenterresult-api)

It is a result of test execution. It wraps `Nette\Application\IResponse` and adds few methods to check the response easily.

### `assertRenders($match)`

[](#assertrendersmatch)

Checks that response is `TextResponse`. Also, you can provide a `$match` parameter to check that response contains some text. You can either pass [pattern](https://tester.nette.org/en/writing-tests#toc-assert-match) or an array plain strings.

### `assertNotRenders($matches)`

[](#assertnotrendersmatches)

Checks that have given pattern or strings were not rendered.

### `assertJson($expected)`

[](#assertjsonexpected)

Check that response is JSON. You can optionally pass the expected payload.

### `assertBadRequest($code)`

[](#assertbadrequestcode)

Checks that requests terminates with bad request exception (e.g., 404 not found).

### `assertRedirects(string $presenterName, array $parameters)`

[](#assertredirectsstring-presentername-array-parameters)

Check that request redirects to given presenter. You can also pass parameters to check. Extra parameters in redirect request are ignored.

### `assertRedirectsUrl($url)`

[](#assertredirectsurlurl)

### `assertFormValid($formName)`

[](#assertformvalidformname)

### `assertFormHasErrors($formName, $formErrors)`

[](#assertformhaserrorsformname-formerrors)

Also, there are methods like `getResponse` or `getPresenter` to access original data and perform some custom checks.

Listeners
---------

[](#listeners)

You can hook to some events by implementing `Forrest79\PresenterTester\PresenterTesterListener` interface. Then you can, e.g., modify test request or execute some implicit result checks.

To register a listener, simply register it as a service in DI container (infrastructure container if you are using Mango Tester Infrastructure).

Identity factory
----------------

[](#identity-factory)

Using identity factory, you can implement a factory which creates a default identity. The factory is a simple PHP callback, which accepts `PresenterTestRequest` and returns `Nette\Security\IIdentity`.

###  Health Score

49

—

FairBetter than 95% of packages

Maintenance74

Regular maintenance activity

Popularity27

Limited adoption so far

Community12

Small or concentrated contributor base

Maturity69

Established project with proven stability

 Bus Factor1

Top contributor holds 60% 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 ~105 days

Recently: every ~146 days

Total

19

Last Release

234d ago

PHP version history (6 changes)v0.0.1PHP ~7.1

v0.0.4PHP ~7.1 | ~8.0

v0.1PHP ^7.4 | ^8.0

v0.2.0PHP ^8.0

0.4.0PHP ^8.1

v0.7.0PHP ^8.3

### Community

Maintainers

![](https://www.gravatar.com/avatar/d979cd353c6593b44b50f90ff5a5eb4be224f501a70f7cce89d0735867e488e5?d=identicon)[forrest79](/maintainers/forrest79)

---

Top Contributors

[![forrest79](https://avatars.githubusercontent.com/u/160766?v=4)](https://github.com/forrest79 "forrest79 (42 commits)")[![matej21](https://avatars.githubusercontent.com/u/1276059?v=4)](https://github.com/matej21 "matej21 (20 commits)")[![KuceraMartin](https://avatars.githubusercontent.com/u/3159068?v=4)](https://github.com/KuceraMartin "KuceraMartin (5 commits)")[![JanTvrdik](https://avatars.githubusercontent.com/u/175109?v=4)](https://github.com/JanTvrdik "JanTvrdik (1 commits)")[![jiripudil](https://avatars.githubusercontent.com/u/1042159?v=4)](https://github.com/jiripudil "jiripudil (1 commits)")[![trejjam](https://avatars.githubusercontent.com/u/3594540?v=4)](https://github.com/trejjam "trejjam (1 commits)")

---

Tags

testingtestpresenter

###  Code Quality

Static AnalysisPHPStan

Type Coverage Yes

### Embed Badge

![Health badge](/badges/forrest79-presenter-tester/health.svg)

```
[![Health](https://phpackages.com/badges/forrest79-presenter-tester/health.svg)](https://phpackages.com/packages/forrest79-presenter-tester)
```

###  Alternatives

[mockery/mockery

Mockery is a simple yet flexible PHP mock object framework

10.7k497.0M23.6k](/packages/mockery-mockery)[php-mock/php-mock

PHP-Mock can mock built-in PHP functions (e.g. time()). PHP-Mock relies on PHP's namespace fallback policy. No further extension is needed.

36918.1M98](/packages/php-mock-php-mock)[brain/monkey

Mocking utility for PHP functions and WordPress plugin API

33812.5M350](/packages/brain-monkey)[ta-tikoma/phpunit-architecture-test

Methods for testing application architecture

10745.9M13](/packages/ta-tikoma-phpunit-architecture-test)[php-mock/php-mock-phpunit

Mock built-in PHP functions (e.g. time()) with PHPUnit. This package relies on PHP's namespace fallback policy. No further extension is needed.

1718.2M399](/packages/php-mock-php-mock-phpunit)[fr3d/swagger-assertions

Test your API requests and responses against your swagger definition

138850.9k5](/packages/fr3d-swagger-assertions)

PHPackages © 2026

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