2018-08-19 09:05:33 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace Tests\Traits;
|
|
|
|
|
|
|
|
use Mockery;
|
|
|
|
use Mockery\MockInterface;
|
|
|
|
|
|
|
|
trait InteractsWithIoc
|
|
|
|
{
|
|
|
|
/**
|
2018-08-19 09:06:59 +00:00
|
|
|
* Mock an IOC dependency, for example an injected service in controllers.
|
2018-08-19 09:05:33 +00:00
|
|
|
*/
|
2020-04-27 18:55:12 +00:00
|
|
|
protected static function mockIocDependency(string $abstract, ...$args): MockInterface
|
2018-08-19 09:05:33 +00:00
|
|
|
{
|
2020-04-27 18:55:12 +00:00
|
|
|
return tap(Mockery::mock($abstract, ...$args), static function (MockInterface $mocked) use ($abstract): void {
|
2018-08-19 09:05:33 +00:00
|
|
|
app()->instance($abstract, $mocked);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|