2

I have a very small test suite for testing CRUD operations on a REST API. My controller displays a form, table, etc, based on the information provided by the API. My test class create a new Buzz object and makes requests to the API server.

Unfortunately, this sucks, because if i update or delete something, it is deleted in the API. This is a very bad test practice. How can i unit test my application, when using an external data source like this?

2 Answers 2

1

Look into test doubles and stubs in the PHPUnit docs:

http://www.phpunit.de/manual/current/en/test-doubles.html

You can use them to replace API functionality.

Sign up to request clarification or add additional context in comments.

2 Comments

Thing is, i cannot mock the server response. I would have to mock the response, based on the request, making sure both are OK.
It's just a simple Buzz usage: submitting GETs and POSTs with data to be created, updated or deleted. The problem is: i don't want to interact with the service database/logic, i just want to make sure my client is communicating well.
0

Unfortunately, this sucks, because if i update or delete something, it is deleted in the API. This is a very bad test practice. How can i unit test my application, when using an external data source like this?

Create some fake, erasable data.. matter of fact you should be not even running PHPUnit tests on a production database/server.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.