The method TestRepositort::read_records takes a parameter array $query. These are the conditions that the data returned must match to. If multiple conditions are passed two problems can happens:
If mutiple conditions are correct, multiple of the same records are added to $matchingrecords.
If not all conditions are met, records are still added to $matchingrecords since only one has to pass to be added.
For ease here is the method:
/**
* Reads an array of objects from the store with the given type and query.
*
* @param string $type The name of the table to retrieve from.
* @param array $query Any additional conditions to add to the query.
* @return array
*/
public function read_records(string $type, array $query) {
$records = $this->testdata->$type;
$matchingrecords = [];
foreach ($records as $record) {
foreach ($query as $key => $value) {
if ($record->$key === $value) {
$matchingrecords[] = (object) $record;
}
}
}
return $matchingrecords;
}
The method TestRepositort::read_records takes a parameter
array $query
. These are the conditions that the data returned must match to. If multiple conditions are passed two problems can happens:$matchingrecords
.$matchingrecords
since only one has to pass to be added.For ease here is the method: