summaryrefslogtreecommitdiff
path: root/tests/app/Services
diff options
context:
space:
mode:
authorGreg Roach <greg@subaqua.co.uk>2025-01-06 11:17:28 +0000
committerGreg Roach <greg@subaqua.co.uk>2025-01-06 12:47:39 +0000
commitcba20eb871932d4301cf65b62972e9fad19015ac (patch)
treecd01401993662b123d9c58cfb865f03a6e1b001e /tests/app/Services
parent24cb7547cb882ddc3e5b99cdff164831ef80290c (diff)
downloadwebtrees-cba20eb871932d4301cf65b62972e9fad19015ac.tar.gz
webtrees-cba20eb871932d4301cf65b62972e9fad19015ac.tar.bz2
webtrees-cba20eb871932d4301cf65b62972e9fad19015ac.zip
Add PhpService so we can mock/test calles to ini_get(), etc.
Diffstat (limited to 'tests/app/Services')
-rw-r--r--tests/app/Services/TimeoutServiceTest.php65
1 files changed, 14 insertions, 51 deletions
diff --git a/tests/app/Services/TimeoutServiceTest.php b/tests/app/Services/TimeoutServiceTest.php
index 16c5a4034f..05bb014c9b 100644
--- a/tests/app/Services/TimeoutServiceTest.php
+++ b/tests/app/Services/TimeoutServiceTest.php
@@ -20,68 +20,33 @@ declare(strict_types=1);
namespace Fisharebest\Webtrees\Services;
use Fisharebest\Webtrees\Contracts\TimeFactoryInterface;
-use Fisharebest\Webtrees\MockGlobalFunctions;
use Fisharebest\Webtrees\Registry;
use Fisharebest\Webtrees\TestCase;
use PHPUnit\Framework\Attributes\CoversClass;
-/**
- * Mock function.
- *
- * @param mixed ...$args
- *
- * @return mixed
- */
-function ini_get(...$args)
-{
- if (TestCase::$mock_functions === null) {
- return \ini_get(...$args);
- }
-
- return TestCase::$mock_functions->iniGet(...$args);
-}
-
#[CoversClass(TimeoutService::class)]
class TimeoutServiceTest extends TestCase
{
- protected function setUp(): void
- {
- parent::setUp();
-
- self::$mock_functions = $this->createMock(MockGlobalFunctions::class);
- }
-
- protected function tearDown(): void
- {
- parent::setUp();
-
- self::$mock_functions = null;
- }
-
public function testNoTimeOut(): void
{
- $now = 1500000000.0;
+ $php_service = $this->createMock(PhpService::class);
+ $php_service->method('maxExecutionTime')->willReturn(0);
- $timeout_service = new TimeoutService($now);
+ $now = 1500000000.0;
- self::$mock_functions
- ->method('iniGet')
- ->with('max_execution_time')
- ->willReturn('0');
+ $timeout_service = new TimeoutService(php_service: $php_service, start_time: $now);
self::assertFalse($timeout_service->isTimeNearlyUp());
}
public function testTimeOutReached(): void
{
- $now = 1500000000.0;
+ $php_service = $this->createMock(PhpService::class);
+ $php_service->method('maxExecutionTime')->willReturn(30);
- $timeout_service = new TimeoutService($now);
+ $now = 1500000000.0;
- self::$mock_functions
- ->method('iniGet')
- ->with('max_execution_time')
- ->willReturn('30');
+ $timeout_service = new TimeoutService(php_service: $php_service, start_time: $now);
$time_factory = $this->createMock(TimeFactoryInterface::class);
$time_factory->method('now')->willReturn($now + 60.0);
@@ -92,14 +57,12 @@ class TimeoutServiceTest extends TestCase
public function testTimeOutNotReached(): void
{
- $now = Registry::timeFactory()->now();
+ $php_service = $this->createMock(PhpService::class);
+ $php_service->method('maxExecutionTime')->willReturn(30);
- $timeout_service = new TimeoutService($now);
+ $now = Registry::timeFactory()->now();
- self::$mock_functions
- ->method('iniGet')
- ->with('max_execution_time')
- ->willReturn('30');
+ $timeout_service = new TimeoutService(php_service: $php_service, start_time: $now);
$time_factory = $this->createMock(TimeFactoryInterface::class);
$time_factory->method('now')->willReturn($now + 10.0);
@@ -112,7 +75,7 @@ class TimeoutServiceTest extends TestCase
{
$now = Registry::timeFactory()->now();
- $timeout_service = new TimeoutService($now);
+ $timeout_service = new TimeoutService(php_service: new PhpService(), start_time: $now);
$time_factory = $this->createMock(TimeFactoryInterface::class);
$time_factory->method('now')->willReturn($now + 1.4);
@@ -125,7 +88,7 @@ class TimeoutServiceTest extends TestCase
{
$now = Registry::timeFactory()->now();
- $timeout_service = new TimeoutService($now);
+ $timeout_service = new TimeoutService(php_service: new PhpService(), start_time: $now);
$time_factory = $this->createMock(TimeFactoryInterface::class);
$time_factory->method('now')->willReturn($now + 1.6);