koel/tests/Traits/InteractsWithIoc.php
2018-08-19 11:06:59 +02:00

24 lines
523 B
PHP

<?php
namespace Tests\Traits;
use Mockery;
use Mockery\MockInterface;
trait InteractsWithIoc
{
/**
* Mock an IOC dependency, for example an injected service in controllers.
*
* @param string $abstract
* @param array $args
*
* @return MockInterface
*/
protected function mockIocDependency($abstract, ...$args)
{
return tap(Mockery::mock($abstract, ...$args), function ($mocked) use ($abstract) {
app()->instance($abstract, $mocked);
});
}
}