• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

codeigniter4 / CodeIgniter4 / 25686094134

11 May 2026 05:26PM UTC coverage: 88.195% (-0.03%) from 88.223%
25686094134

push

github

web-flow
test: make random component execution safer (#10169)

* test: make random component execution safer

* test: remove unnecessary normalization

Signed-off-by: memleakd <121398829+memleakd@users.noreply.github.com>

* fix: stabilize cached table names for random tests

Signed-off-by: memleakd <121398829+memleakd@users.noreply.github.com>

* test: address review feedbacks

Signed-off-by: memleakd <121398829+memleakd@users.noreply.github.com>

* fix: log factories cache write failures

Signed-off-by: memleakd <121398829+memleakd@users.noreply.github.com>

* fix: document best-effort log chmod

Signed-off-by: memleakd <121398829+memleakd@users.noreply.github.com>

---------

Signed-off-by: memleakd <121398829+memleakd@users.noreply.github.com>

8 of 14 new or added lines in 4 files covered. (57.14%)

2 existing lines in 1 file now uncovered.

22114 of 25074 relevant lines covered (88.19%)

209.98 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

53.85
/system/Cache/FactoriesCache/FileVarExportHandler.php
1
<?php
2

3
declare(strict_types=1);
4

5
/**
6
 * This file is part of CodeIgniter 4 framework.
7
 *
8
 * (c) CodeIgniter Foundation <admin@codeigniter.com>
9
 *
10
 * For the full copyright and license information, please view
11
 * the LICENSE file that was distributed with this source code.
12
 */
13

14
namespace CodeIgniter\Cache\FactoriesCache;
15

16
final class FileVarExportHandler
17
{
18
    private string $path = WRITEPATH . 'cache';
19

20
    public function save(string $key, mixed $val): void
21
    {
22
        $val = var_export($val, true);
32✔
23

24
        // Two processes may try to create the directory at the same time.
25
        // is_dir() confirms it exists, so suppressing the warning is safe.
26
        if (! is_dir($this->path) && ! @mkdir($this->path, 0777, true) && ! is_dir($this->path)) {
32✔
NEW
27
            log_message('error', 'FactoriesCache: cannot create cache directory: ' . $this->path);
×
28

NEW
29
            return;
×
30
        }
31

32
        // Write to temp file first to ensure atomicity
33
        $tmp = $this->path . "/{$key}." . uniqid('', true) . '.tmp';
32✔
34
        if (file_put_contents($tmp, '<?php return ' . $val . ';', LOCK_EX) === false) {
32✔
NEW
35
            log_message('warning', 'FactoriesCache: failed to write temp file for key: ' . $key);
×
36

NEW
37
            return;
×
38
        }
39

40
        // Another process may have wiped the directory. Clean up on failure.
41
        if (! @rename($tmp, $this->path . "/{$key}")) {
32✔
NEW
42
            log_message('warning', 'FactoriesCache: failed to commit cache file for key: ' . $key);
×
43

NEW
44
            @unlink($tmp);
×
45
        }
46
    }
47

48
    public function delete(string $key): void
49
    {
50
        @unlink($this->path . "/{$key}");
2✔
51
    }
52

53
    public function get(string $key): mixed
54
    {
55
        return @include $this->path . "/{$key}";
35✔
56
    }
57
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc