trying to unit test a repository method that returns an object, and the test fixtures are arrays, the return value is an object.
Would the data in the test fixtures need to be changed to become objects, or can i convert the retrieved data into an object at the start of the test. Test method is below
/**
* Test Getting Details by Importer and Year method
*
* @return void
*/
public function testGetDetailsByImporterAndYear(): void
{
$expectedImporterDetail = $this->getFixtureData('ImporterDetails', 0);
$importer = $this->getFixtureData('Importers', 0);
$year = 2021;
$result = $this->ImporterDetails->getDetailsByImporterAndYear($importer['id'], $year);
$this->assertEquals($expectedImporterDetail, $result, 'Should only be one result');
$expectedResult = null;
$importerId = PHP_INT_MAX;
$yearMax = 2038;
$result = $this->ImporterDetails->getDetailsByImporterAndYear($importerId, $yearMax);
$this->assertSame($expectedResult, $result, 'Should be no result returned');
}
and an example of the test data
$data = [
[
'id' => '1',
'client_id' => '1',
'importer_id' => '1',
'name' => 'Ethil Jones',
'email' => '[email protected]',
'address' => '136 Manor Way
Great Marton
FY3 7UT',
'year' => '2021',
'created' => '2021-12-07 22:32:59',
'modified' => '2021-12-07 22:32:59',
],
Ive looked into mock objects, though not sure that would be the right use case here. Any pointers would be great. Bottom half of the test works, as the method may return null. Just the part where the object is returned struggling to assert same