Skip to content

Commit 1b93904

Browse files
committed
wip
1 parent e1443c8 commit 1b93904

5 files changed

Lines changed: 141 additions & 0 deletions

File tree

tests/system/Cache/Handlers/FileHandlerTest.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -388,6 +388,16 @@ public function testGetItemWithCorruptedData(): void
388388

389389
$this->assertNull($this->handler->get(self::$key1));
390390
}
391+
392+
public function testPing(): void
393+
{
394+
$this->assertTrue($this->handler->ping());
395+
}
396+
397+
public function testReconnect(): void
398+
{
399+
$this->assertTrue($this->handler->reconnect());
400+
}
391401
}
392402

393403
/**

tests/system/CodeIgniterTest.php

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1270,4 +1270,27 @@ public function testRouteAttributesDisabledInConfig(): void
12701270
// But the controller method should still execute
12711271
$this->assertStringContainsString('Filtered', (string) $output);
12721272
}
1273+
1274+
public function testResetForWorkerMode(): void
1275+
{
1276+
$config = new App();
1277+
$codeigniter = new MockCodeIgniter($config);
1278+
1279+
$this->setPrivateProperty($codeigniter, 'request', service('request'));
1280+
$this->setPrivateProperty($codeigniter, 'response', service('response'));
1281+
$this->setPrivateProperty($codeigniter, 'output', 'test output');
1282+
1283+
$this->assertNotNull($this->getPrivateProperty($codeigniter, 'request'));
1284+
$this->assertNotNull($this->getPrivateProperty($codeigniter, 'response'));
1285+
$this->assertNotNull($this->getPrivateProperty($codeigniter, 'output'));
1286+
1287+
$codeigniter->resetForWorkerMode();
1288+
1289+
$this->assertNull($this->getPrivateProperty($codeigniter, 'request'));
1290+
$this->assertNull($this->getPrivateProperty($codeigniter, 'response'));
1291+
$this->assertNull($this->getPrivateProperty($codeigniter, 'router'));
1292+
$this->assertNull($this->getPrivateProperty($codeigniter, 'controller'));
1293+
$this->assertNull($this->getPrivateProperty($codeigniter, 'method'));
1294+
$this->assertNull($this->getPrivateProperty($codeigniter, 'output'));
1295+
}
12731296
}

tests/system/Config/ServicesTest.php

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@
5151
use Config\Exceptions;
5252
use Config\Security as SecurityConfig;
5353
use Config\Session as ConfigSession;
54+
use Config\WorkerMode;
5455
use InvalidArgumentException;
5556
use PHPUnit\Framework\Attributes\DataProvider;
5657
use PHPUnit\Framework\Attributes\Group;
@@ -500,4 +501,64 @@ public function testServiceInstance(): void
500501
$this->assertInstanceOf(\Config\Services::class, new \Config\Services());
501502
rename(COMPOSER_PATH . '.backup', COMPOSER_PATH);
502503
}
504+
505+
public function testHas(): void
506+
{
507+
$this->assertFalse(Services::has('timer'));
508+
509+
Services::timer();
510+
511+
$this->assertTrue(Services::has('timer'));
512+
}
513+
514+
public function testHasReturnsFalseForNonExistentService(): void
515+
{
516+
$this->assertFalse(Services::has('nonexistent'));
517+
}
518+
519+
#[PreserveGlobalState(false)]
520+
#[RunInSeparateProcess]
521+
public function testResetForWorkerModeWithKeepAliveStrategy(): void
522+
{
523+
$config = new WorkerMode();
524+
$config->cacheStrategy = 'keep-alive';
525+
$config->persistentServices = ['timer'];
526+
527+
Services::cache();
528+
Services::timer();
529+
Services::typography();
530+
531+
$this->assertTrue(Services::has('cache'));
532+
$this->assertTrue(Services::has('timer'));
533+
$this->assertTrue(Services::has('typography'));
534+
535+
Services::resetForWorkerMode($config);
536+
537+
$this->assertTrue(Services::has('cache'));
538+
$this->assertTrue(Services::has('timer'));
539+
$this->assertFalse(Services::has('typography'));
540+
}
541+
542+
#[PreserveGlobalState(false)]
543+
#[RunInSeparateProcess]
544+
public function testResetForWorkerModeWithReconnectStrategy(): void
545+
{
546+
$config = new WorkerMode();
547+
$config->cacheStrategy = 'reconnect';
548+
$config->persistentServices = ['timer'];
549+
550+
Services::cache();
551+
Services::timer();
552+
Services::typography();
553+
554+
$this->assertTrue(Services::has('cache'));
555+
$this->assertTrue(Services::has('timer'));
556+
$this->assertTrue(Services::has('typography'));
557+
558+
Services::resetForWorkerMode($config);
559+
560+
$this->assertFalse(Services::has('cache'));
561+
$this->assertTrue(Services::has('timer'));
562+
$this->assertFalse(Services::has('typography'));
563+
}
503564
}

tests/system/Database/ConfigTest.php

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
use CodeIgniter\Database\Postgre\Connection as PostgreConnection;
1717
use CodeIgniter\Test\CIUnitTestCase;
1818
use CodeIgniter\Test\ReflectionHelper;
19+
use Config\WorkerMode;
1920
use PHPUnit\Framework\Attributes\DataProvider;
2021
use PHPUnit\Framework\Attributes\Group;
2122

@@ -239,4 +240,36 @@ public static function provideConvertDSN(): iterable
239240
],
240241
];
241242
}
243+
244+
#[Group('DatabaseLive')]
245+
public function testResetForWorkerModeWithDisconnectStrategy(): void
246+
{
247+
$config = new WorkerMode();
248+
$config->databaseStrategy = 'disconnect';
249+
250+
$conn = Config::connect();
251+
$this->assertInstanceOf(BaseConnection::class, $conn);
252+
253+
Config::resetForWorkerMode($config);
254+
255+
$this->assertFalse($this->getPrivateProperty($conn, 'connID'));
256+
}
257+
258+
#[Group('DatabaseLive')]
259+
public function testResetForWorkerModeWithKeepAliveStrategy(): void
260+
{
261+
$config = new WorkerMode();
262+
$config->databaseStrategy = 'keep-alive';
263+
264+
$conn = Config::connect();
265+
$this->assertInstanceOf(BaseConnection::class, $conn);
266+
267+
$conn->transStart();
268+
$this->assertGreaterThan(0, $conn->transDepth);
269+
270+
Config::resetForWorkerMode($config);
271+
272+
$this->assertSame(0, $conn->transDepth);
273+
$this->assertNotFalse($this->getPrivateProperty($conn, 'connID'));
274+
}
242275
}

tests/system/Events/EventsTest.php

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -332,4 +332,18 @@ private function getEditableObject(): stdClass
332332

333333
return clone $user;
334334
}
335+
336+
public function testResetForWorkerMode(): void
337+
{
338+
Events::on('test', static fn () => null);
339+
Events::trigger('test');
340+
341+
$performanceLog = Events::getPerformanceLogs();
342+
$this->assertNotEmpty($performanceLog);
343+
344+
Events::resetForWorkerMode();
345+
346+
$performanceLog = Events::getPerformanceLogs();
347+
$this->assertEmpty($performanceLog);
348+
}
335349
}

0 commit comments

Comments
 (0)