PHPUnit: 404 code on every request - zend-framework2

I have project A and project B in my vagrant machine. Both working and accessible via http://a.local/ and http//b.local/ . These are Apigility APIs.
I am now writing tests with PHPUnit.
I want to test that project A can call services on project B and check that:
Response code is 200.
Response is JSON.
etc...
PHPUnit keeps on failing because the response is 404 when calling any service (from a to b or from b to a):
{404 => string(54) "http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html"
'title' =>
string(9) "Not Found"
'status' =>
int(404)
'detail' =>
string(15) "Page not found."}
All URLs are accesible via browser.
All URLs are accesible via Curl.
Browser and Curl return the same (identical) responses and http codes.
/etc/hosts file is properly configured.
PHP.ini file are identical for cli and fmp.
Any ideas what am I doing wrong? Thanks!

php-unit is probably more suitable for testing smaller parts of your application (unit testing). You can also do Curl tests of course but there are probably much better solutions (REST testing solutions/frameworks) to do this.
If you want to test your full application using Curl, you have to make sure that your php-unit bootstrap loads all the application dependencies.
It would also be a good idea to write a abstract wrapper or a test case specifically for testing your rest-api with Curl requests so you don't have to repeat too much code. Check this answer on stackoverflow to get an idea on how you could do this. But I bet there are a lot more examples available online and maybe you should do some googling.

You don't have ZF\Rest installed. The abstract factory to create rest resources, including doctrine controllers, is in that module.

Related

Routing in Symfony 1.4: Is there a way to allow sf_method = OPTIONS for preflight HTTP requests

you all might know that browsers do preflighted HTTP requests in some cases:
https://developer.mozilla.org/en-US/docs/Web/HTTP/Access_control_CORS#Preflighted_requests
My web application is still on Symfony1. I want to implement a RESTful service and therefore using Symfony routing to allow specific HTTP request methods like GET or POST (http://symfony.com/legacy/doc/reference/1_4/en/10-Routing#chapter_10_sub_sf_method).
Example:
login:
url: /v1/login
class: sfRequestRoute
param: { module: rest, action: login }
requirements:
sf_method: [post, put, delete]
#sf_method: [options] NOT WORKING
It seems to me that OPTIONS requests cannot be defined/handled as sf_method value. Because I couldn't find any information if my idea is right, I'm wondering if I'm right or maybe there is a solution I couldn't find, too.
Thanks in advance!
Sorry to revive this old question but I found a solution. I ran into the same issue and I added the request method OPTIONS to the allowed methods in lib/sfRequest.class.php and lib/sfWebRequest.class.php You can check the latest commit here to see the differences: 6ad018c
Since I cannot update the original Symfony1 GitHub repository, I created a copy with additional fixes needed due to the various PHP upgrades. This fixes the PHP deprecated warnings due to use of the /e modifier in preg_replace calls as well.
Note that this still doesn't make Symfony1 PHP7 compatible. I'm running this successfully with PHP 5.6.30
The repository is https://github.com/diem-project/symfony.git
Background: Diem uses Symfony1 (1.4.20), hence the GitHub organisation diem-project

How do I handle post requests from my dart app ran from the dart editor?

I have code that looks something like this (_http is the angular Http object)
var httpFuture = _http.post('/api/items', {
'ids': JSON.encode(new List.from(nonLoadedIds))
});
httpFuture.catchError((e) {
Logger.root.severe('Unable to load items!', e);
});
It is making a post request to load a bunch of things. Potentially more ids than the http get header can handle.
The nice development experience would be if I could fire up the dart editor, mock up some fake response data, run my app, and see the data in the end. I would also accept being able to start up a separate web app and somehow proxy my post requests to that web app.
What I don't want to do is change my '/api/items' into something like 'http://localhost:8084/api/items' mostly because I don't want to have to remember to replace these before deploying (I know I'll forget) and while doable, I don't want to on my server implement CORS just to have to remember to disable it when I deploy to production.
But really, I would accept just about any workflow if it is recommended. I just would like to eliminate any manual code transformations pre production deploy.
The suggested attempt is to use a simple proxy server which forwards to pub serve.
See for example https://code.google.com/p/dart/issues/detail?id=18039
This issue contains the source code for a simple custom proxy server example https://code.google.com/p/dart/issues/detail?id=15731
see also
Dart: How to use different settings in debug and production mode?
How to achieve precompiler directive like functionality
Is there a compiler preprocessor in Dart?

Trouble linking ChicagoBoss controllers to views

I'm making a website in Erlang, but I'm having troubles. I installed Chicagoboss and the server starts, but I have a problem. They say to go to this page localhost:8001/pages/index when i go to this page I get an error:
No routes matched the requested URL. (Don't worry, this message will not appear in production.)
I did not do anything, I coded the file in src/controllers/main.erl. What am I doing wrong?
I've never used ChicagoBoss, but this question is extremely basic and you should read carefully tutorial before asking. Take a look how the requested URL is dispatched:
host:port/yourcontroller/youraction
will invoke function like
youraction('GET', []) ->
{output, "Hello World!"}.
from file src/controller/PROJECT_yourcontroller_controller.erl. This sample works out of the box. In general case look at PROJECT/priv/PROJECT.routes to define rules to bind URL patterns to their controllers actions.

ArgumentNullException when initializing site

I am in the process of evaluating several service frameworks and one of them is OpenRasta.
Despite being taken a bit aback for the lack of organization (multiple source code repositories, lack of binary downloads, outdated build instructions and the end result of the build, OpenRasta.dll, has version 0.0.0.0 after building the openrasta-core repository), I managed my way to start building a site with a service that serves a bit of Xml (I did include OpenRasta.Hosting.AspNet and configured the handlers and modules as per IIS or Cassini).
But the very first time I hit the site (both IIS Express and VS Dev Server) I get a ArgumentNullException coming from the PipelineStage.cs. Apparently the pipeline.CallGraph property is null.
My configuration source is a mere:
ResourceSpace.Has
.ResourcesOfType<CatalogCollection>()
.AtUri("/catalogs")
.HandledBy<CatalogsHandler>()
.AsXmlDataContract();
As I mentioned I am using the code I cloned from the openrasta-core repository as of yesterday.
Thanks in advance
try wrapping resource registrations in
using (OpenRastaConfiguration.Manual)
{
//code
}
Also check this out;
https://github.com/openrasta/openrasta-stable/wiki/Building-Your-First-OpenRasta-Website
Hope this helps

Silverlight 3 with Weborb for Java

For some reason, i can not invoke java method deployed under Tomcat/Weborb application. When i run weborb console and invoke the method from there, there is no problem. However when i tried to call from Silverlight 3 client, it does not response at all. There is one possibility which is incorrect service gateway. But i have checked the server path to make sure it is correct. I also tried different approaches to invoke server call such as proxy and class interface mentioned inside weborb documentation. I'm stuck with this problem for two days already and can not progress any further. Is there any common mistake when it comes to this problem? Any help would appreciate.
Cheers,
Khoa Nguyen
I found the solution. This is because the gateway mapping is incorrect. For instance, When deploy under weborb, the client use localhost:8080/weborb.wo. However when you deploy underworb, the gateway mapping is now change to something like localhost:8080/weborb/console/weborb.wo something like that. You can see how your request mapped to by run the weborb console and look at the server status as you invoke your java methods.
Hope this help.
Cheers,
Khoa Nguyen
There is a new WebORB for Java 4.1 release available that fixes this mapping issue. In addition, the new code generator creates a complete client class library with complex types, enums, bindable model and proxy class for the remote Java service. The release is available here:http://www.themidnightcoders.com/products.html

Resources