koel/tests/Traits/InteractsWithIoc.php

25 lines
523 B
PHP
Raw Normal View History

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)
{
return tap(Mockery::mock($abstract, ...$args), function ($mocked) use ($abstract) {
app()->instance($abstract, $mocked);
});
}
}