koel/tests/Traits/InteractsWithIoc.php
2018-08-23 08:58:23 +02:00

24 lines
530 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), static function ($mocked) use ($abstract) {
app()->instance($abstract, $mocked);
});
}
}