0

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:

  1. Response code is 200.

  2. Response is JSON.

  3. 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!

repara2
  • 114
  • 8

2 Answers2

0

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.

Community
  • 1
  • 1
Wilt
  • 41,477
  • 12
  • 152
  • 203
0

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

  • Sorry for the terribly late answer, zf-campus/rest is installed. I still get 404 and even more, calling the same project in localhost, I get different responses from the any other software and from php-unit. It looks like php-unit will only get 404 or 200 and it is unable to get any other codes. Any ideas? – repara2 May 30 '16 at 15:00