2017-10-31 13:40:13 +01:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace Engelsystem\Test\Unit;
|
|
|
|
|
|
|
|
use Engelsystem\Application;
|
2017-12-25 23:52:31 +01:00
|
|
|
use PHPUnit\Framework\MockObject\Matcher\InvokedRecorder;
|
2017-10-31 13:40:13 +01:00
|
|
|
use PHPUnit\Framework\TestCase;
|
2017-10-31 14:15:19 +01:00
|
|
|
use PHPUnit_Framework_MockObject_MockObject as MockObject;
|
2017-10-31 13:40:13 +01:00
|
|
|
|
|
|
|
abstract class ServiceProviderTest extends TestCase
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
* @param array $methods
|
2017-10-31 14:15:19 +01:00
|
|
|
* @return Application|MockObject
|
2017-10-31 13:40:13 +01:00
|
|
|
*/
|
|
|
|
protected function getApp($methods = ['make', 'instance'])
|
|
|
|
{
|
2017-10-31 14:15:19 +01:00
|
|
|
/** @var MockObject|Application $app */
|
2017-10-31 13:40:13 +01:00
|
|
|
return $this->getMockBuilder(Application::class)
|
|
|
|
->setMethods($methods)
|
|
|
|
->getMock();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2017-10-31 14:15:19 +01:00
|
|
|
* @param MockObject $object
|
|
|
|
* @param string $method
|
|
|
|
* @param array $arguments
|
|
|
|
* @param mixed $return
|
|
|
|
* @param InvokedRecorder $times
|
2017-10-31 13:40:13 +01:00
|
|
|
*/
|
2017-10-31 14:15:19 +01:00
|
|
|
protected function setExpects($object, $method, $arguments = null, $return = null, $times = null)
|
2017-10-31 13:40:13 +01:00
|
|
|
{
|
2017-10-31 14:15:19 +01:00
|
|
|
if (is_null($times)) {
|
|
|
|
$times = $this->once();
|
|
|
|
}
|
|
|
|
|
|
|
|
$invocation = $object->expects($times)
|
2017-10-31 13:40:13 +01:00
|
|
|
->method($method);
|
2017-10-31 14:15:19 +01:00
|
|
|
|
|
|
|
if (is_null($arguments)) {
|
|
|
|
$invocation->withAnyParameters();
|
|
|
|
} else {
|
|
|
|
call_user_func_array([$invocation, 'with'], $arguments);
|
|
|
|
}
|
2017-10-31 13:40:13 +01:00
|
|
|
|
|
|
|
if (!is_null($return)) {
|
|
|
|
$invocation->willReturn($return);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|