Skip to content

Commit cce2477

Browse files
committed
feat: add MockCommon for shared test helpers and mocks
1 parent 1482cdd commit cce2477

File tree

2 files changed

+50
-0
lines changed

2 files changed

+50
-0
lines changed

system/Boot.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,9 @@ public static function bootTest(Paths $paths): void
149149
static::setExceptionHandler();
150150
static::initializeKint();
151151
static::autoloadHelpers();
152+
153+
// Global test helpers and mocks for all tests
154+
require_once ROOTPATH . 'tests/_support/MockCommon.php';
152155
}
153156

154157
/**

tests/_support/MockCommon.php

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
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 Tests\Support;
15+
16+
/**
17+
* MockCommon.php
18+
*
19+
* Shared mocks and helpers for all tests in CodeIgniter 4.
20+
* Loaded automatically during `Boot::bootTest()`.
21+
*
22+
* Purpose:
23+
* - Provide global mock functions like `is_cli()`
24+
* - Keep tests isolated and maintainable
25+
*
26+
* How to extend:
27+
* - Add new helper functions below
28+
* - Keep mocks idempotent to avoid side effects
29+
*/
30+
31+
// ---------------------------------------------------
32+
// Environment helpers
33+
// ---------------------------------------------------
34+
if (! function_exists('is_cli')) {
35+
/**
36+
* Force non-CLI environment for tests
37+
*/
38+
function is_cli(): bool
39+
{
40+
return false;
41+
}
42+
}
43+
44+
// ---------------------------------------------------
45+
// Placeholder for additional mocks/helpers
46+
// ---------------------------------------------------
47+
// Add any other test helpers here, e.g., logger mocks, cache mocks, etc.

0 commit comments

Comments
 (0)