A
A
an232014-10-17 18:32:58
PHP
an23, 2014-10-17 18:32:58

How to test interaction with PHPUnit database?

Good afternoon. I use PHPUnit to test PHP code.
At the moment I am writing the application architecture, while using the Data Mapper template. Accordingly, most tests should be limited to checking the interaction of the code with the database. CRUD operations on an entity, etc. I think here you need to check the work with the database directly, and not replace it with stub objects. Is DB interaction testing modular at all? And how to conduct this test. Whether to use DBUnit. Again, how? I'm not asking about what can be read in the documentation, but specifically about the best solutions that came with experience. Thank you!

Answer the question

In order to leave comments, you need to log in

1 answer(s)
T
TomaZ Vazovsky, 2014-10-19
@Keksinautin

Probably no longer modular. I would call it "integration" because we are testing how your code works together with the base.
The bottom line is that we (in the case of writing to the database) give data to the input of the method, and then check what we received in the database, and without using our code. In the case of reading, on the contrary, we first create records using third-party tools, and then check how they are read.
In such tests, I always acted as follows:
1. Create a "data provider" - which in a declarative form describes the parameters: "what is at the input of the method" and "what is in the database" or "what is in the database" and "what is at the output of the method" .
2. We have direct access to the database, with the help of it in each test we either create a record in the database or check whether
But I think you should not get carried away with such tests, because they essentially just check that you have correctly compiled the request.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question