Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/develop' into 4.6
Browse files Browse the repository at this point in the history
  • Loading branch information
kenjis committed May 10, 2024
2 parents 1c5f488 + 069e13d commit f0e610d
Show file tree
Hide file tree
Showing 12 changed files with 80 additions and 14 deletions.
2 changes: 1 addition & 1 deletion system/DataCaster/DataCaster.php
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ public function castAs(mixed $value, string $field, string $method = 'get'): mix
$params = array_map('trim', explode(',', $matches[2]));
}

if ($isNullable) {
if ($isNullable && ! $this->strict) {
$params[] = 'nullable';
}

Expand Down
2 changes: 1 addition & 1 deletion system/Files/FileCollection.php
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ final protected static function matchFiles(array $files, string $pattern): array
['\#', '\.', '.*', '.'],
$pattern
);
$pattern = "#{$pattern}#";
$pattern = "#\\A{$pattern}\\z#";
}

return array_filter($files, static fn ($value) => (bool) preg_match($pattern, basename($value)));
Expand Down
4 changes: 2 additions & 2 deletions system/Model.php
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ protected function doFind(bool $singleton, $id = null)
$row = $builder->get()->getResult($this->tempReturnType);
}

if ($useCast) {
if ($useCast && $row !== null) {
$row = $this->convertToReturnType($row, $returnType);

$this->tempReturnType = $returnType;
Expand Down Expand Up @@ -318,7 +318,7 @@ protected function doFirst()

$row = $builder->limit(1, 0)->get()->getFirstRow($this->tempReturnType);

if ($useCast) {
if ($useCast && $row !== null) {
$row = $this->convertToReturnType($row, $returnType);

$this->tempReturnType = $returnType;
Expand Down
Empty file.
4 changes: 2 additions & 2 deletions tests/_support/Models/UserCastsTimestampModel.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ class UserCastsTimestampModel extends Model
'id' => 'int',
'name' => 'base64',
'email' => 'json-array',
'created_at' => 'datetime',
'updated_at' => 'datetime',
'created_at' => '?datetime',
'updated_at' => '?datetime',
];
protected array $castHandlers = [
'base64' => CastBase64::class,
Expand Down
13 changes: 11 additions & 2 deletions tests/system/Files/FileCollectionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,7 @@ public function testAddStringDirectoryRecursive(): void
$this->directory . 'fig_3.php',
$this->directory . 'prune_ripe.php',
SUPPORTPATH . 'Files/baker/banana.php',
SUPPORTPATH . 'Files/baker/fig_3.php.txt',
];

$files->add(SUPPORTPATH . 'Files');
Expand Down Expand Up @@ -227,6 +228,7 @@ public function testAddArrayRecursive(): void
$this->directory . 'fig_3.php',
$this->directory . 'prune_ripe.php',
SUPPORTPATH . 'Files/baker/banana.php',
SUPPORTPATH . 'Files/baker/fig_3.php.txt',
SUPPORTPATH . 'Log/Handlers/TestHandler.php',
];

Expand Down Expand Up @@ -392,6 +394,7 @@ public function testAddDirectoryRecursive(): void
$this->directory . 'fig_3.php',
$this->directory . 'prune_ripe.php',
SUPPORTPATH . 'Files/baker/banana.php',
SUPPORTPATH . 'Files/baker/fig_3.php.txt',
];

$collection->addDirectory(SUPPORTPATH . 'Files', true);
Expand All @@ -407,6 +410,7 @@ public function testAddDirectories(): void
$this->directory . 'fig_3.php',
$this->directory . 'prune_ripe.php',
SUPPORTPATH . 'Files/baker/banana.php',
SUPPORTPATH . 'Files/baker/fig_3.php.txt',
];

$collection->addDirectories([
Expand All @@ -425,6 +429,7 @@ public function testAddDirectoriesRecursive(): void
$this->directory . 'fig_3.php',
$this->directory . 'prune_ripe.php',
SUPPORTPATH . 'Files/baker/banana.php',
SUPPORTPATH . 'Files/baker/fig_3.php.txt',
SUPPORTPATH . 'Log/Handlers/TestHandler.php',
];

Expand Down Expand Up @@ -471,6 +476,7 @@ public function testRemovePatternPseudo(): void
$expected = [
$this->directory . 'apple.php',
SUPPORTPATH . 'Files/baker/banana.php',
SUPPORTPATH . 'Files/baker/fig_3.php.txt',
];

$collection->removePattern('*_*.php');
Expand All @@ -485,6 +491,7 @@ public function testRemovePatternScope(): void

$expected = [
SUPPORTPATH . 'Files/baker/banana.php',
SUPPORTPATH . 'Files/baker/fig_3.php.txt',
];

$collection->removePattern('*.php', $this->directory);
Expand Down Expand Up @@ -512,6 +519,7 @@ public function testRetainPatternRegex(): void
$expected = [
$this->directory . 'fig_3.php',
$this->directory . 'prune_ripe.php',
SUPPORTPATH . 'Files/baker/fig_3.php.txt',
];

$collection->retainPattern('#[a-z]+_.*#');
Expand Down Expand Up @@ -541,6 +549,7 @@ public function testRetainPatternScope(): void
$expected = [
$this->directory . 'fig_3.php',
SUPPORTPATH . 'Files/baker/banana.php',
SUPPORTPATH . 'Files/baker/fig_3.php.txt',
];

$collection->retainPattern('*_?.php', $this->directory);
Expand All @@ -553,7 +562,7 @@ public function testCount(): void
$collection = new FileCollection();
$collection->addDirectory(SUPPORTPATH . 'Files', true);

$this->assertCount(4, $collection);
$this->assertCount(5, $collection);
}

public function testIterable(): void
Expand All @@ -568,6 +577,6 @@ public function testIterable(): void
$count++;
}

$this->assertSame($count, 4);
$this->assertSame($count, 5);
}
}
24 changes: 18 additions & 6 deletions tests/system/Helpers/FilesystemHelperTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -429,20 +429,32 @@ public function testGetFilenamesWithSymlinks(): void

public function testGetDirFileInfo(): void
{
$file = SUPPORTPATH . 'Files/baker/banana.php';
$info = get_file_info($file);
$file1 = SUPPORTPATH . 'Files/baker/banana.php';
$info1 = get_file_info($file1);
$file2 = SUPPORTPATH . 'Files/baker/fig_3.php.txt';
$info2 = get_file_info($file2);

$expected = [
'banana.php' => [
'name' => 'banana.php',
'server_path' => $file,
'size' => $info['size'],
'date' => $info['date'],
'server_path' => $file1,
'size' => $info1['size'],
'date' => $info1['date'],
'relative_path' => realpath(__DIR__ . '/../../_support/Files/baker'),
],
'fig_3.php.txt' => [
'name' => 'fig_3.php.txt',
'server_path' => $file2,
'size' => $info2['size'],
'date' => $info2['date'],
'relative_path' => realpath(__DIR__ . '/../../_support/Files/baker'),
],
];

$this->assertSame($expected, get_dir_file_info(SUPPORTPATH . 'Files/baker'));
$result = get_dir_file_info(SUPPORTPATH . 'Files/baker');
ksort($result);

$this->assertSame($expected, $result);
}

public function testGetDirFileInfoNested(): void
Expand Down
30 changes: 30 additions & 0 deletions tests/system/Models/DataConverterModelTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,16 @@ public function testFindAsArray(): void
$this->seeInDatabase('user', ['name' => 'Sm9obiBTbWl0aA==']);
}

public function testFindAsArrayReturnsNull(): void
{
$this->createModel(UserCastsTimestampModel::class);
$this->db->table('user')->truncate();

$user = $this->model->find(1);

$this->assertNull($user);
}

/**
* @return int|string Insert ID
*/
Expand Down Expand Up @@ -102,6 +112,16 @@ public function testFindAllAsArray(): void
$this->assertInstanceOf(Time::class, $users[1]['created_at']);
}

public function testFindAllAsArrayReturnsNull(): void
{
$this->createModel(UserCastsTimestampModel::class);
$this->db->table('user')->truncate();

$users = $this->model->findAll();

$this->assertSame([], $users);
}

private function prepareTwoRecords(): void
{
$this->prepareOneRecord();
Expand Down Expand Up @@ -170,6 +190,16 @@ public function testFirstAsArray(): void
$this->assertInstanceOf(Time::class, $user['created_at']);
}

public function testFirstAsArrayReturnsNull(): void
{
$this->createModel(UserCastsTimestampModel::class);
$this->db->table('user')->truncate();

$user = $this->model->first();

$this->assertNull($user);
}

public function testFirstAsObject(): void
{
$this->prepareTwoRecords();
Expand Down
2 changes: 2 additions & 0 deletions tests/system/Publisher/PublisherInputTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ public function testAddPathDirectoryRecursive(): void
$this->directory . 'fig_3.php',
$this->directory . 'prune_ripe.php',
SUPPORTPATH . 'Files/baker/banana.php',
SUPPORTPATH . 'Files/baker/fig_3.php.txt',
];

$publisher->addPath('Files');
Expand Down Expand Up @@ -121,6 +122,7 @@ public function testAddPathsRecursive(): void
$this->directory . 'fig_3.php',
$this->directory . 'prune_ripe.php',
SUPPORTPATH . 'Files/baker/banana.php',
SUPPORTPATH . 'Files/baker/fig_3.php.txt',
SUPPORTPATH . 'Log/Handlers/TestHandler.php',
];

Expand Down
3 changes: 3 additions & 0 deletions tests/system/Publisher/PublisherOutputTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,7 @@ public function testMerge(): void
$this->root->url() . '/able/fig_3.php',
$this->root->url() . '/able/prune_ripe.php',
$this->root->url() . '/baker/banana.php',
$this->root->url() . '/baker/fig_3.php.txt',
];

$this->assertFileDoesNotExist($this->root->url() . '/able/fig_3.php');
Expand All @@ -183,6 +184,7 @@ public function testMergeReplace(): void
$this->root->url() . '/able/fig_3.php',
$this->root->url() . '/able/prune_ripe.php',
$this->root->url() . '/baker/banana.php',
$this->root->url() . '/baker/fig_3.php.txt',
];

$result = $publisher->addPath('/')->merge(true);
Expand All @@ -200,6 +202,7 @@ public function testMergeCollides(): void
$this->root->url() . '/able/apple.php',
$this->root->url() . '/able/prune_ripe.php',
$this->root->url() . '/baker/banana.php',
$this->root->url() . '/baker/fig_3.php.txt',
];

mkdir($this->root->url() . '/able/fig_3.php');
Expand Down
7 changes: 7 additions & 0 deletions user_guide_src/source/concepts/factories.rst
Original file line number Diff line number Diff line change
Expand Up @@ -270,6 +270,10 @@ Config Caching

.. versionadded:: 4.4.0

.. important:: Do not use this feature unless you have carefully read this section
and understand how this feature works. Otherwise, your application will not
function properly.

To improve performance, Config Caching has been implemented.

Prerequisite
Expand All @@ -287,6 +291,9 @@ Prerequisite
How It Works
============

.. important:: Once cached, configuration values are never changed until the cache
is deleted, even if the configuration file or **.env** is changed.

- Save the all Config instances in Factories into a cache file before shutdown,
if the state of the Config instances in Factories changes.
- Restore cached Config instances before CodeIgniter initialization if a cache
Expand Down
3 changes: 3 additions & 0 deletions user_guide_src/source/installation/deployment.rst
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,9 @@ See :ref:`modules-specify-composer-packages`.
Config Caching
==============

.. important:: Once cached, configuration values are never changed until the cache
is deleted, even if the configuration file or **.env** is changed.

Caching the Config objects can improve performance. However, the cache must be
manually deleted when changing Config values.

Expand Down

0 comments on commit f0e610d

Please sign in to comment.