koel/tests/Traits/InteractsWithIoc.php

25 lines
530 B
PHP
Raw Normal View History

2018-08-19 11:05:33 +02:00
<?php
namespace Tests\Traits;
use Mockery;
use Mockery\MockInterface;
trait InteractsWithIoc
{
/**
2018-08-19 11:06:59 +02:00
* Mock an IOC dependency, for example an injected service in controllers.
2018-08-19 11:05:33 +02:00
*
* @param string $abstract
2018-08-19 11:06:59 +02:00
* @param array $args
2018-08-19 11:05:33 +02:00
*
* @return MockInterface
*/
protected function mockIocDependency($abstract, ...$args)
{
2018-08-23 08:58:17 +02:00
return tap(Mockery::mock($abstract, ...$args), static function ($mocked) use ($abstract) {
2018-08-19 11:05:33 +02:00
app()->instance($abstract, $mocked);
});
}
}