In a php project that I maintain I have a database structure without migrations, hence no way to reproduce it or make on the fly a test database.
And the queries used to be performed on them are rather complex ones. The pattern in code used with them is (I try to show a generelized preview of the problem):
public function someMethod(PDO $connection, string $param) {
$sql="^some complex sql query^";
$pdo->prepare($sql);
$pdo->bindParam('param',$param);
$stmt->execute();
return $stmt->fetchAll();
}
In order to test this function I created a duplicate database and from that I deleted all the production data keeping the least minimal. I use the following testing approach when I write phphunit test
- Populate the database with test data.
- Run the method.
- Do my Assertions.
- Delete the test data manually using Delete sql statements.
Did this approach creates a Unit test for my application or an Integration one. Keep in mind that the whole logic is implemented in an SQL query instead on the php layer.
For example a query like that:
Select
value,
CASE
WHEN "time"::time < '12:00' and "time"::time > '00:00' then true
ELSE
false end as observed_in_morning
from
observations
The example above the logic that indicates whether an observation happened in me morning or not is written on the sql statement, clearly a business logic.
So a test testing whether an observation happened in the morning is a unit test or an integration one?