Tests: Moved ServiceProvider::setExpects to TestCase

This commit is contained in:
Igor Scheller 2018-09-25 16:46:37 +02:00 committed by msquare
parent fcee7d752f
commit c9afc27ab9
2 changed files with 37 additions and 29 deletions

View File

@ -3,8 +3,6 @@
namespace Engelsystem\Test\Unit; namespace Engelsystem\Test\Unit;
use Engelsystem\Application; use Engelsystem\Application;
use PHPUnit\Framework\MockObject\Matcher\InvokedRecorder;
use PHPUnit\Framework\TestCase;
use PHPUnit_Framework_MockObject_MockObject as MockObject; use PHPUnit_Framework_MockObject_MockObject as MockObject;
abstract class ServiceProviderTest extends TestCase abstract class ServiceProviderTest extends TestCase
@ -20,31 +18,4 @@ abstract class ServiceProviderTest extends TestCase
->setMethods($methods) ->setMethods($methods)
->getMock(); ->getMock();
} }
/**
* @param MockObject $object
* @param string $method
* @param array $arguments
* @param mixed $return
* @param InvokedRecorder $times
*/
protected function setExpects($object, $method, $arguments = null, $return = null, $times = null)
{
if (is_null($times)) {
$times = $this->once();
}
$invocation = $object->expects($times)
->method($method);
if (is_null($arguments)) {
$invocation->withAnyParameters();
} else {
call_user_func_array([$invocation, 'with'], $arguments);
}
if (!is_null($return)) {
$invocation->willReturn($return);
}
}
} }

37
tests/Unit/TestCase.php Normal file
View File

@ -0,0 +1,37 @@
<?php
namespace Engelsystem\Test\Unit;
use PHPUnit\Framework\MockObject\Matcher\InvokedRecorder;
use PHPUnit\Framework\TestCase as PHPUnitTestCase;
use PHPUnit_Framework_MockObject_MockObject as MockObject;
abstract class TestCase extends PHPUnitTestCase
{
/**
* @param MockObject $object
* @param string $method
* @param array $arguments
* @param mixed $return
* @param InvokedRecorder $times
*/
protected function setExpects($object, $method, $arguments = null, $return = null, $times = null)
{
if (is_null($times)) {
$times = $this->once();
}
$invocation = $object->expects($times)
->method($method);
if (is_null($arguments)) {
$invocation->withAnyParameters();
} else {
call_user_func_array([$invocation, 'with'], $arguments);
}
if (!is_null($return)) {
$invocation->willReturn($return);
}
}
}