2018-09-25 16:46:37 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace Engelsystem\Test\Unit;
|
|
|
|
|
2019-10-08 13:57:50 +02:00
|
|
|
use Engelsystem\Application;
|
2021-06-29 00:27:57 +02:00
|
|
|
use Faker\Factory as FakerFactory;
|
|
|
|
use Faker\Generator;
|
2019-04-24 10:45:00 +02:00
|
|
|
use PHPUnit\Framework\MockObject\MockObject;
|
2019-10-06 21:03:20 +02:00
|
|
|
use PHPUnit\Framework\MockObject\Rule\InvocationOrder;
|
2018-09-25 16:46:37 +02:00
|
|
|
use PHPUnit\Framework\TestCase as PHPUnitTestCase;
|
|
|
|
|
|
|
|
abstract class TestCase extends PHPUnitTestCase
|
|
|
|
{
|
2019-10-08 13:57:50 +02:00
|
|
|
/** @var Application */
|
|
|
|
protected $app;
|
|
|
|
|
2018-09-25 16:46:37 +02:00
|
|
|
/**
|
|
|
|
* @param MockObject $object
|
|
|
|
* @param string $method
|
|
|
|
* @param array $arguments
|
|
|
|
* @param mixed $return
|
2019-10-06 21:03:20 +02:00
|
|
|
* @param InvocationOrder $times
|
2018-09-25 16:46:37 +02:00
|
|
|
*/
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
}
|
2019-10-08 13:57:50 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Called before each test run
|
|
|
|
*/
|
|
|
|
protected function setUp(): void
|
|
|
|
{
|
|
|
|
$this->app = new Application(__DIR__ . '/../../');
|
2021-06-29 00:27:57 +02:00
|
|
|
|
|
|
|
$faker = FakerFactory::create();
|
|
|
|
$faker->addProvider(new FakerProvider($faker));
|
|
|
|
$this->app->instance(Generator::class, $faker);
|
2019-10-08 13:57:50 +02:00
|
|
|
}
|
2018-09-25 16:46:37 +02:00
|
|
|
}
|