Skip to content

Commit d751725

Browse files
committed
test(integration): add BootstrapLoggerIntegrationTest for logger initialization
- Added `tests/Integration/BootstrapLoggerIntegrationTest.php` to verify integration between Bootstrap and maatify/psr-logger. - Ensures Bootstrap::init() initializes logger correctly and returns a valid PSR-3 compliant LoggerInterface instance. - Confirms idempotent behavior on multiple init() calls.
1 parent 5d850e2 commit d751725

2 files changed

Lines changed: 148 additions & 0 deletions

File tree

composer.json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,12 @@
4444
"require-dev": {
4545
"phpunit/phpunit": "^10.0"
4646
},
47+
48+
"autoload-dev": {
49+
"psr-4": {
50+
"Maatify\\Bootstrap\\Tests\\": "tests/"
51+
}
52+
},
4753
"scripts": {
4854
"test": "vendor/bin/phpunit --testdox"
4955
}
Lines changed: 142 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,142 @@
1+
<?php
2+
/**
3+
* @copyright ©2025 Maatify.dev
4+
* @Library maatify/bootstrap
5+
* @Project maatify:bootstrap
6+
* @author Mohamed Abdulalim (megyptm) <mohamed@maatify.dev>
7+
* @since 2025-11-10 21:48
8+
* @see https://www.maatify.dev Maatify.com
9+
* @link https://github.com/Maatify/bootstrap view project on GitHub
10+
* @note Distributed in the hope that it will be useful - WITHOUT WARRANTY.
11+
*/
12+
13+
declare(strict_types=1);
14+
15+
namespace Maatify\Bootstrap\Tests\Integration;
16+
17+
use Maatify\Bootstrap\Core\Bootstrap;
18+
use PHPUnit\Framework\TestCase;
19+
use Psr\Log\LoggerInterface;
20+
21+
/**
22+
* 🧩 **Class BootstrapLoggerIntegrationTest**
23+
*
24+
* 🎯 **Purpose:**
25+
* Validates the integration between {@see Bootstrap} (core system initializer)
26+
* and {@see maatify/psr-logger}, ensuring proper logger setup and behavior.
27+
*
28+
* 🧠 **Key Test Scenarios:**
29+
* - ✅ Confirms that `Bootstrap::init()` initializes successfully.
30+
* - ✅ Verifies that `Bootstrap::logger()` returns a PSR-3 compliant logger.
31+
* - ✅ Ensures multiple initialization calls remain idempotent.
32+
* - ✅ Confirms that logger operations (like `info()`) execute without errors.
33+
*
34+
* 🧪 **Test Context:**
35+
* These are integration-level tests that interact with filesystem paths
36+
* and logging subsystems, designed to ensure stable environment initialization
37+
* within the Maatify Bootstrap ecosystem.
38+
*/
39+
final class BootstrapLoggerIntegrationTest extends TestCase
40+
{
41+
/**
42+
* @var string Temporary directory for test operations.
43+
*/
44+
private string $basePath;
45+
46+
/**
47+
* ⚙️ **Setup Environment**
48+
*
49+
* Creates a temporary directory for log and bootstrap initialization.
50+
* Executed before each test method.
51+
*
52+
* @return void
53+
*/
54+
protected function setUp(): void
55+
{
56+
$this->basePath = sys_get_temp_dir() . '/maatify-bootstrap-tests';
57+
if (! is_dir($this->basePath)) {
58+
mkdir($this->basePath, 0777, true);
59+
}
60+
}
61+
62+
/**
63+
* 🧩 **Test Bootstrap Initialization**
64+
*
65+
* Ensures that calling `Bootstrap::init()` properly initializes
66+
* the system environment and sets up the logger.
67+
*
68+
* @return void
69+
*/
70+
public function testBootstrapInitializesLogger(): void
71+
{
72+
Bootstrap::init($this->basePath);
73+
74+
$this->assertTrue(
75+
Bootstrap::isInitialized(),
76+
'Bootstrap must be initialized after calling init().'
77+
);
78+
}
79+
80+
/**
81+
* 🔍 **Test PSR Logger Availability**
82+
*
83+
* Ensures that `Bootstrap::logger()` returns a valid instance
84+
* of {@see LoggerInterface}, and that logging operations
85+
* can be executed without exceptions.
86+
*
87+
* @return void
88+
*/
89+
public function testLoggerIsAvailableAndPsrCompliant(): void
90+
{
91+
Bootstrap::init($this->basePath);
92+
93+
$logger = Bootstrap::logger();
94+
95+
$this->assertInstanceOf(
96+
LoggerInterface::class,
97+
$logger,
98+
'Bootstrap::logger() should return a PSR-3 logger instance.'
99+
);
100+
101+
// 🧠 Try logging a message — should not throw any errors.
102+
$logger->info('Integration Test: Bootstrap logger initialized successfully.');
103+
$this->assertTrue(true, 'Logger should log without throwing exceptions.');
104+
}
105+
106+
/**
107+
* 🔁 **Test Idempotent Initialization**
108+
*
109+
* Confirms that multiple calls to `Bootstrap::init()` do not cause reinitialization
110+
* issues or exceptions, maintaining consistent state.
111+
*
112+
* @return void
113+
*/
114+
public function testMultipleInitCallsAreIdempotent(): void
115+
{
116+
Bootstrap::init($this->basePath);
117+
Bootstrap::init($this->basePath);
118+
119+
$this->assertTrue(
120+
Bootstrap::isInitialized(),
121+
'Bootstrap initialization should be idempotent.'
122+
);
123+
}
124+
125+
/**
126+
* 🧹 **Teardown Environment**
127+
*
128+
* Cleans up any temporary files or directories created during testing.
129+
* Ensures isolation between tests.
130+
*
131+
* @return void
132+
*/
133+
protected function tearDown(): void
134+
{
135+
if (is_dir($this->basePath)) {
136+
foreach (glob("{$this->basePath}/*") as $file) {
137+
@unlink($file);
138+
}
139+
@rmdir($this->basePath);
140+
}
141+
}
142+
}

0 commit comments

Comments
 (0)