Download the PHP package mangoweb/presenter-tester without Composer

On this page you can find all versions of the php package mangoweb/presenter-tester. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package presenter-tester

Mango Presenter Tester

Build Status

Testing tool for Nette presenter with easy to use API.

Installation

The recommended way to install is via Composer:

It requires PHP version 7.1.

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.

You can also specify list of listeners:

Other way is to use Presenter Tester together with mangoweb/tester-infrastructure. In that case you have to register DI extension in infrastructure .neon file:

In configuration of the extension you can set a base url and custom identity factory.

Usage

In Mango Tester Infrastructure environment, service PresenterTester is available in infrastructure container. When you get the service, you can start testing your presenters:

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() function.

TestPresenterRequest API

Beware that TestPresenterRequest is immutable object.

withParameters(array $parameters)

Set application request parameters.

withForm(string $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 package.

withSignal(string $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 package.

withAjax

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

withMethod(string $methodName)

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

withHeaders(array $headers)

Pass additional HTTP headers.

withIdentity(Nette\Security\IIdentity $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, which provides a default identity for each request.

withPost(array $post)

withFiles(array $files)

withRawBody(string$rawBody)

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)

Checks that response is TextResponse. Also, you can provide a $match parameter to check that response contains some text. You can either pass pattern or an array plain strings.

assertNotRenders($matches)

Checks that given pattern or strings were not rendered.

assertJson($expected)

Checks that response is JSON. You can optionally pass expected payload.

assertBadRequest($code)

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

assertRedirects(string $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)

assertFormValid($formName)

assertFormHasErrors($formName, $formErrors)


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

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

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.


All versions of presenter-tester with dependencies

PHP Build Version
Package Version
Requires php Version ~7.1
nette/application Version ~3.0
nette/security Version ~3.0
nette/forms Version ~3.0
nette/tester Version ~2.0
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package mangoweb/presenter-tester contains the following files

Loading the files please wait ....