Comments (4)
@scaraveos can you provide me a good template to write test for restful service in zf2. Thanks a lot :)
from zf2-restful-module-skeleton.
@nXqd I suggest that you code your application logic in library package/classes. In my opinion the controller should be doing something very simple as instantiating a library object, feeding it with data, calling a method to fulfill a specific request and finally returning the method result.
If you do that, you do not need to test the controller but the library which is much more straight forward and you keep your code tidy.
If you still want to test your controller you need to instantiate the controller and call the right action. Ie:
$event = new \Zend\Mvc\MvcEvent();
$event->setRouteMatch(new \Zend\Mvc\Router\RouteMatch(array()));
$controller = new \Main\Controller\TestController();
$controller->setEvent($event);
$routeMatch = $controller->getEvent()->getRouteMatch();
$routeMatch->setMatchedRouteName('restful');
$result = $controller->getList();
..... assert $result data ....
from zf2-restful-module-skeleton.
I use angularJS as front end and zf2 as restful webservice only. So I think it's still best to test restful resource. Since I'm quite new to zf2 so I'm open for any suggestions.
In your example, it seems to take care the result but I want to test the request and response status as well. I come up with a small unit test but it doesn't seem to work. Can you help me :
http://stackoverflow.com/questions/14210463/restful-controller-in-zendframework-2-how-does-its-parameter-work
from zf2-restful-module-skeleton.
I gave a brief explanation (at the above link) of how ZF2 internally calls the controller methods. I am closing this issue as it is not related with this module but rather it's a general ZF2 question.
from zf2-restful-module-skeleton.
Related Issues (16)
- Missing instance/object for parameter route for Zend\Mvc\Router... HOT 1
- Extra data when issueing Status Code HOT 1
- Support for longer (or more complex) URLs HOT 7
- This module does not work with ZendDeveloperTools HOT 3
- not composer friendly
- Do we have Unit tests for this module?
- multiple get method HOT 2
- getVariables() method issue HOT 1
- Service with name "json-pp" could not be created. HOT 1
- The requested URL could not be matched by routing HOT 4
- Fatal error HOT 2
- Question about posible reason not function HOT 2
- unable to fetch or create an instance for info HOT 3
- Error Processor takes over all application, not just Rest Module HOT 14
- Response format in URI HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from zf2-restful-module-skeleton.