mezzio | PSR-15 Middleware Microframework | Runtime Evironment library
kandi X-RAY | mezzio Summary
kandi X-RAY | mezzio Summary
mezzio builds on laminas-stratigility to provide a minimalist PSR-7 middleware framework for PHP, with the following features:.
Support
Quality
Security
License
Reuse
Top functions reviewed by kandi - BETA
- Inject routes from configuration .
- Get all dependencies .
- Checks if the configuration service provides a valid response factory .
- Inject the editor .
- Prepare a middleware .
- Get a middleware .
- Prepare the Whoops handler .
- Register the JSON exception handler .
- Prepare templated response .
- Generate a plain text response .
mezzio Key Features
mezzio Examples and Code Snippets
Community Discussions
Trending Discussions on mezzio
QUESTION
I'm trying to write a PHP UnitTest for my AddHandler::class
in Mezzio (Zend Expressive) but I'm not sure I've done it right or wrong. Although the Test passes but I'm not really convinced that's the way to do it. The requirement is to basically mock the output of service (new CrmApiService())->getUsers()
and (new CustomHydrator())->getHydrated($this->usersJson)
which can be saved in a text file for that matter. I've another one ViewHandler::class
which also uses a service for data for listing, which I'm sure I can implement if I get a clue for this one.
My AddHandler Class
...ANSWER
Answered 2021-Jun-26 at 09:52Although the Test passes but I'm not really convinced that's the way to do it.
If you've written that test and this is your judgement, I suggest you temporarily rewrite the test (e.g. in another test-method) where you test for your expectations in testing to verify they are addressed.
Otherwise it seems the test is not of your benefit as you don't understand what it tests for and therefore is superfluous code and waste (in the agile sense) and you can cleanly just remove it and not let it lurk there open to lying around.
Who needs a test that is unclear in what it tests? Especially in unit tests there should be only one reason why a test fails. Not possible with an unclear test.
Is it already cleanup time and then back to drawing board? Maybe. I'd suggest incremental improvement and some sandboxing personally first. Like adding a much reduced test-case-method for verifying your own expectation of the test-suite-framework and the (two?) mocking library/ies in use.
This will also help you get going with the framework in use and gain a deeper understanding - this normally immediately pays off.
I've another one ViewHandler::class which also uses a service for data for listing, which I'm sure I can implement if I get a clue for this one.
Your code your tests. Only you can say whether or not your tests full-fill your requirements.
And if you allow me a personal comment, I hate to do mocking in tests. Even for code mocking technically works it becomes cumbersome pretty soon and has the tendency that the tests are only testing the mocks that have been written for the test only so entirely needless work.
Instead I try to either have the code under test straight forward and if a certain abstraction requires a lot of set-up upfront, create a factory for it and then that factory can be used in tests, too, reducing the overhead to a minimum.
Then some specialization of the factory can be done for testing automatically inject the testing configuration (e.g. in form of mocks if it must be to set blank other systems the test should not reach into) and then just let it pass. But this is just exemplary.
In a system where you like to test system($request, $response)->assert(diverse on $response afterwards)
where system
is *
of concrete classes you write (your implementation), you may want to have a tester for *
so that your test-procedure remains clear on all the interfacing that system
offers and *
implements and you don't need to set-up internals of all of system
for *
only to test any *
, e.g. a HandlerTester
.
Also check if Mezzio itself is not offering a tester if there is a higher level abstraction implementation necessary for handlers. A good library normally ships with good testing utilities (and even in this case not, you can fork it anytime).
Testing should be before development, this is oh so true for libraries, so actually I would personally expect the stuff is already there in 0.0.1. But this can vary.
Enable code coverage also for your tests so you can more easily review if your tests do run the way it's intended and put also all collaborators under test and coverage. This can help to gain more understanding what a test does and maybe already clarifies if it is of use or not.
QUESTION
I am using Mezzio/Laminas (newer version of Zend) and want to check whether an id is less than a number. If it is not, another form element is required. Is it possible to access the set data in a laminas-filter in any way?
...ANSWER
Answered 2021-Jun-03 at 14:35In your input filter class, you can override setData
Community Discussions, Code Snippets contain sources that include Stack Exchange Network
Vulnerabilities
No vulnerabilities reported
Install mezzio
You can install Mezzio standalone using Composer:.
a router.
a dependency injection container.
Aura.Router: composer require mezzio/mezzio-aurarouter
FastRoute: composer require mezzio/mezzio-fastroute
laminas-router: composer require mezzio/mezzio-laminasrouter
laminas-servicemanager: composer require laminas/laminas-servicemanager
Pimple (see docs for more details): composer require laminas/laminas-pimple-config
Aura.Di (see docs for more details): composer require laminas/laminas-auradi-config
Support
Reuse Trending Solutions
Find, review, and download reusable Libraries, Code Snippets, Cloud APIs from over 650 million Knowledge Items
Find more librariesStay Updated
Subscribe to our newsletter for trending solutions and developer bootcamps
Share this Page