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

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

mangoweb/presenter-tester
=========================

v0.3(7y ago)18173.5k↑23.1%6[2 issues](https://github.com/mangoweb-backend/presenter-tester/issues)MITPHPPHP ~7.1

Since Mar 14Pushed 5y ago8 watchersCompare

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

READMEChangelog (3)Dependencies (9)Versions (4)Used By (0)

Mango Presenter Tester
======================

[](#mango-presenter-tester)

[![Build Status](https://camo.githubusercontent.com/b74bbaf5fe8de3361858b714f85a88460e84abc1bbbe195c05930355e3690a87/68747470733a2f2f7472617669732d63692e6f72672f6d616e676f7765622d6261636b656e642f70726573656e7465722d7465737465722e7376673f6272616e63683d6d6173746572)](https://travis-ci.org/mangoweb-backend/presenter-tester)

Testing tool for Nette presenter with easy to use API.

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

[](#installation)

The recommended way to install is via Composer:

```
composer require mangoweb/presenter-tester

```

It requires PHP version 7.1.

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

[](#integration--configuration)

If you are using 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:
	- Mangoweb\Tester\PresenterTester\PresenterTester(baseUrl: "http://my-app.dev")
```

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

```
services:
	- Mangoweb\Tester\PresenterTester\PresenterTester(
		baseUrl: "http://my-app.dev"
		listeners: [
			MyListener()
		]
	)
```

Other way is to use Presenter Tester together with [mangoweb/tester-infrastructure](https://github.com/mangoweb-backend/tester-infrastructure). In that case you have to register DI extension in infrastructure `.neon` file:

```
extensions:
	mango.presenterTester: Mangoweb\Tester\PresenterTester\Bridges\Infrastructure\PresenterTesterExtension

```

In configuration of the extension you can set a base url and custom [identity factory](#identity-factory).

```
mango.presenterTester:
	baseUrl: http://my-app.dev
	identityFactory: MyIdentityFactory()

```

Usage
-----

[](#usage)

In Mango Tester Infrastructure environment, service `PresenterTester` is available in infrastructure 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 given pattern. You probably already know the pattern format from [Tester\\Assert::match()](https://tester.nette.org/en/writing-tests#toc-assert-match) function.

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 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 = [], string $componentClass = null)`

[](#withsignalstring-signal-array-componentparameters---string-componentclass--null)

With Presenter Tester, you can also easily test signal method. The componentClass is only required in the case you are using `nextras/secured-links` (which you should). It is also recommended to install [mangoweb/tester-http-mocks](https://github.com/mangoweb-backend/tester-http-mocks) package.

### `withAjax`

[](#withajax)

(Not only) signals often uses 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 identity of 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 given pattern or strings were not rendered.

### `assertJson($expected)`

[](#assertjsonexpected)

Checks that response is JSON. You can optionally pass 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)

Checks 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 a perform some custom checks.

Listeners
---------

[](#listeners)

You can hook to some events by implementing `Mangoweb\Tester\PresenterTester\IPresenterTesterListener` 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

35

—

LowBetter than 80% of packages

Maintenance18

Infrequent updates — may be unmaintained

Popularity43

Moderate usage in the ecosystem

Community19

Small or concentrated contributor base

Maturity50

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 64.5% 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 ~195 days

Total

3

Last Release

2597d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/24237c1135d761c9477a0b3da5fa8a105a1f21984b4b2e2ae0ba2083ba6f825f?d=identicon)[matej21](/maintainers/matej21)

---

Top Contributors

[![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 (2 commits)")[![petrparolek](https://avatars.githubusercontent.com/u/6066243?v=4)](https://github.com/petrparolek "petrparolek (2 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)")

### Embed Badge

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

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

###  Alternatives

[contributte/forms-bootstrap

Nette extension for Bootstrap forms

211.1M4](/packages/contributte-forms-bootstrap)[nasext/dependent-select-box

Dependent Select Box for Nette Framework.

21262.8k2](/packages/nasext-dependent-select-box)

PHPackages © 2026

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