Support the ongoing development of Laravel.io →
IOC Testing
Last updated 1 year ago.
0

Seems the problem was elsewhere and injecting it like any other class seems to work fine. For those who are wondering:

My Image class constructor:

use Illuminate\Config\Repository as Config;

class Image {
    public function __construct(
        Config $config
    ) {
        $this->config = $config;
    }
}

My ImageSpec.php:

function let(\Illuminate\Config\Repository $config)
{
    $this->beConstructedWith($config);
}

function it_is_initializable()
{
    $this->shouldHaveType('Acme\Images\Image');
}
Last updated 1 year ago.

mehdidalvand liked this reply

1

Yes, it works if you leave it at that. However if you add another function to the image class like this:

function isAccepted(){
    return in_array($this->type, $this->config->get('accepted_types'));
}

I don't think it will work in this case. Or you will get weird results at best.

0

Sign in to participate in this thread!

Eventy

Your banner here too?

Moderators

We'd like to thank these amazing companies for supporting us

Your logo here?

Laravel.io

The Laravel portal for problem solving, knowledge sharing and community building.

© 2024 Laravel.io - All rights reserved.