attachMany relation during testing

I have a model which has some attachOne and attachMany file attachments.

Both of these work fine during normal use.
However I am having difficulty with setting up tests

I have the following code in my test class

$logo = file(__DIR__ . '/assests/images/logo.png');

        $file = new System\Models\File;
        $file->data = __DIR__ . '/assests/images/Sample-Photo.jpeg';
        $file->is_public = 1;

        $nhd->developer_logo = (new System\Models\File)->fromData($logo, 'logo.png');


        $developer_logo_path = $nhd->developer_logo->getPath();
        $photo_path = $nhd->development_photos[0]->getPath();

Both the ‘$developer_logo_path’ and ‘$photo_path’ variables successfully return a stored file path ( which actually points to a file which has been saved ) which is what i would except.

However if i then let the test run and execute the normal code. If I put a breakpoint in the component php file at the point after the model referred to in the test code as $nhd has been loaded there is a ‘developer_logo’ attached ( the AttachOne file ) but there are no ‘development_photos’ ( the attachMany file ).
As a result the template also does not output anything when {{component.development_photos}} is used

I also tried using the inline method to add the attachMany file ( $nhd->development_photos = (new System\Models\File)->fromData($photo, ‘logo.png’); ) and this also did not work.

Can anyone help me?

Take a look at these files for working examples (~v3.0):

  • modules/system/tests/database/AttachOneModelTest.php
  • modules/system/tests/database/AttachManyModelTest.php