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
|
|
|
*
|
|
|
|
* @param string $abstract
|
2018-08-19 09:06:59 +00:00
|
|
|
* @param array $args
|
2018-08-19 09:05:33 +00:00
|
|
|
*
|
|
|
|
* @return MockInterface
|
|
|
|
*/
|
|
|
|
protected function mockIocDependency($abstract, ...$args)
|
|
|
|
{
|
2018-08-23 06:58:17 +00:00
|
|
|
return tap(Mockery::mock($abstract, ...$args), static function ($mocked) use ($abstract) {
|
2018-08-19 09:05:33 +00:00
|
|
|
app()->instance($abstract, $mocked);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|