Download the PHP package cds-uwb/nette-presenter-tests without Composer
On this page you can find all versions of the php package cds-uwb/nette-presenter-tests. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download cds-uwb/nette-presenter-tests
More information about cds-uwb/nette-presenter-tests
Files in cds-uwb/nette-presenter-tests
Package nette-presenter-tests
Short Description Library based on PHPUnit framework to test Nette presenters via simple API
License MIT
Informations about the package nette-presenter-tests
Nette Presenter Tests
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:
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.
Available traits
AssertResponse- adds assertions that allow to check presenter responses.ExpectErrors- adds expectations to check raising presenter error viaerrormethod.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 propertypresenter(usesPresenterRunmethods).PresenterRun- main request API for invoking requests on given presenter.
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.
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
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).
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.
All versions of nette-presenter-tests with dependencies
latte/latte Version ^3.1
nette/application Version ^3.2
nette/bootstrap Version ^3.2
nette/di Version ^3.2
nette/forms Version ^3.2
nette/security Version ^3.2
nette/utils Version ^4.1