Skip to content

Commit 79227eb

Browse files
committed
Merge branch 'release/0.8.1'
2 parents 9348bae + 013a86d commit 79227eb

File tree

10 files changed

+880
-21
lines changed

10 files changed

+880
-21
lines changed

.github/workflows/ci.yml

Lines changed: 19 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -5,30 +5,29 @@ on: [push]
55
jobs:
66
build-test:
77
runs-on: ubuntu-latest
8-
container:
9-
image: php:8.4 # This forces the job to run in a Docker container
108

119
steps:
1210
- name: Checkout
1311
uses: actions/checkout@v3
1412

15-
- name: Install System Dependencies (Git, Zip, Unzip)
16-
run: |
17-
apt-get update
18-
apt-get install -y unzip git zip
19-
20-
- name: Install and Enable extensions
21-
run: |
22-
docker-php-ext-install sockets calendar
23-
docker-php-ext-enable sockets calendar
24-
25-
- name: Install Composer
26-
run: |
27-
curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin --filename=composer
28-
composer --version
13+
- name: Setup PHP
14+
uses: shivammathur/setup-php@v2
15+
with:
16+
php-version: 8.4
17+
extensions: sockets, calendar, pcov
18+
coverage: pcov
2919

3020
- name: Install Dependencies
31-
run: composer install --prefer-dist --no-progress
32-
33-
- name: Run PHPUnit
34-
run: vendor/bin/phpunit tests
21+
run: composer install --prefer-dist --no-progress --no-interaction --optimize-autoloader
22+
23+
- name: Run PHPUnit with Coverage
24+
run: vendor/bin/phpunit tests --coverage-clover coverage.xml --coverage-filter src
25+
26+
- name: Upload coverage to Codecov
27+
uses: codecov/codecov-action@v5
28+
with:
29+
token: ${{ secrets.CODECOV_TOKEN }}
30+
files: ./coverage.xml
31+
flags: core
32+
slug: Neuron-PHP/core
33+
fail_ci_if_error: true

.version.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,6 @@
22
"strategy": "semver",
33
"major": 0,
44
"minor": 8,
5-
"patch": 0,
5+
"patch": 1,
66
"build": 0
77
}

LICENSE

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2025 NeuronPHP
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

readme.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
[![CI](https://github.com/Neuron-PHP/core/actions/workflows/ci.yml/badge.svg)](https://github.com/Neuron-PHP/core/actions)
2+
[![codecov](https://codecov.io/gh/Neuron-PHP/core/branch/develop/graph/badge.svg)](https://codecov.io/gh/Neuron-PHP/core)
23
# Neuron-PHP Core
34

45
The foundational component of the Neuron PHP framework, providing essential utilities, string and array manipulation classes, and a comprehensive exception hierarchy for PHP 8.4+ applications.

src/Core/System/IFileSystem.php

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
<?php
2+
3+
namespace Neuron\Core\System;
4+
5+
/**
6+
* Interface for file system operations abstraction.
7+
*
8+
* Provides a testable abstraction over file system operations. Implementations
9+
* can be real file system access for production or in-memory systems for testing.
10+
*/
11+
interface IFileSystem
12+
{
13+
/**
14+
* Check if a file exists
15+
*
16+
* @param string $path File path
17+
* @return bool True if file exists, false otherwise
18+
*/
19+
public function fileExists( string $path ): bool;
20+
21+
/**
22+
* Read entire file contents
23+
*
24+
* @param string $path File path
25+
* @return string|false File contents or false on failure
26+
*/
27+
public function readFile( string $path ): string|false;
28+
29+
/**
30+
* Check if path is a directory
31+
*
32+
* @param string $path Directory path
33+
* @return bool True if directory exists, false otherwise
34+
*/
35+
public function isDir( string $path ): bool;
36+
37+
/**
38+
* Get absolute path (resolve symlinks, relative paths)
39+
*
40+
* @param string $path Path to resolve
41+
* @return string|false Resolved absolute path or false on failure
42+
*/
43+
public function realpath( string $path ): string|false;
44+
45+
/**
46+
* Get current working directory
47+
*
48+
* @return string|false Current directory or false on failure
49+
*/
50+
public function getcwd(): string|false;
51+
52+
/**
53+
* Write data to file
54+
*
55+
* @param string $path File path
56+
* @param string $data Data to write
57+
* @return int|false Number of bytes written or false on failure
58+
*/
59+
public function writeFile( string $path, string $data ): int|false;
60+
}
Lines changed: 171 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,171 @@
1+
<?php
2+
3+
namespace Neuron\Core\System;
4+
5+
/**
6+
* In-memory file system implementation for testing.
7+
*
8+
* Provides a virtual file system that exists entirely in memory. Files and
9+
* directories can be programmatically added for testing without touching the
10+
* real file system. Perfect for unit testing file-dependent operations.
11+
*/
12+
class MemoryFileSystem implements IFileSystem
13+
{
14+
/**
15+
* @var array<string, string> In-memory files (path => content)
16+
*/
17+
private array $files = [];
18+
19+
/**
20+
* @var array<string, bool> In-memory directories (path => true)
21+
*/
22+
private array $directories = [];
23+
24+
/**
25+
* @var string Current working directory
26+
*/
27+
private string $cwd = '/';
28+
29+
/**
30+
* Add a file to the virtual file system
31+
*
32+
* @param string $path File path
33+
* @param string $content File content
34+
* @return void
35+
*/
36+
public function addFile( string $path, string $content ): void
37+
{
38+
$this->files[$path] = $content;
39+
}
40+
41+
/**
42+
* Add a directory to the virtual file system
43+
*
44+
* @param string $path Directory path
45+
* @return void
46+
*/
47+
public function addDirectory( string $path ): void
48+
{
49+
$this->directories[$path] = true;
50+
}
51+
52+
/**
53+
* Set the current working directory
54+
*
55+
* @param string $path Directory path
56+
* @return void
57+
*/
58+
public function setCwd( string $path ): void
59+
{
60+
$this->cwd = $path;
61+
}
62+
63+
/**
64+
* Remove a file from the virtual file system
65+
*
66+
* @param string $path File path
67+
* @return void
68+
*/
69+
public function removeFile( string $path ): void
70+
{
71+
unset( $this->files[$path] );
72+
}
73+
74+
/**
75+
* Remove a directory from the virtual file system
76+
*
77+
* @param string $path Directory path
78+
* @return void
79+
*/
80+
public function removeDirectory( string $path ): void
81+
{
82+
unset( $this->directories[$path] );
83+
}
84+
85+
/**
86+
* Clear all files and directories
87+
*
88+
* @return void
89+
*/
90+
public function clear(): void
91+
{
92+
$this->files = [];
93+
$this->directories = [];
94+
$this->cwd = '/';
95+
}
96+
97+
/**
98+
* @inheritDoc
99+
*/
100+
public function fileExists( string $path ): bool
101+
{
102+
return isset( $this->files[$path] );
103+
}
104+
105+
/**
106+
* @inheritDoc
107+
*/
108+
public function readFile( string $path ): string|false
109+
{
110+
return $this->files[$path] ?? false;
111+
}
112+
113+
/**
114+
* @inheritDoc
115+
*/
116+
public function isDir( string $path ): bool
117+
{
118+
return isset( $this->directories[$path] );
119+
}
120+
121+
/**
122+
* @inheritDoc
123+
*/
124+
public function realpath( string $path ): string|false
125+
{
126+
// Simplistic realpath: just check if file or directory exists
127+
if( $this->fileExists( $path ) || $this->isDir( $path ) )
128+
{
129+
return $path;
130+
}
131+
132+
return false;
133+
}
134+
135+
/**
136+
* @inheritDoc
137+
*/
138+
public function getcwd(): string|false
139+
{
140+
return $this->cwd;
141+
}
142+
143+
/**
144+
* @inheritDoc
145+
*/
146+
public function writeFile( string $path, string $data ): int|false
147+
{
148+
$this->files[$path] = $data;
149+
return strlen( $data );
150+
}
151+
152+
/**
153+
* Get all files in the virtual file system
154+
*
155+
* @return array<string, string>
156+
*/
157+
public function getFiles(): array
158+
{
159+
return $this->files;
160+
}
161+
162+
/**
163+
* Get all directories in the virtual file system
164+
*
165+
* @return array<string, bool>
166+
*/
167+
public function getDirectories(): array
168+
{
169+
return $this->directories;
170+
}
171+
}

src/Core/System/RealFileSystem.php

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
<?php
2+
3+
namespace Neuron\Core\System;
4+
5+
/**
6+
* Real file system implementation.
7+
*
8+
* This is the production implementation that wraps PHP's native file system functions.
9+
* Provides actual file system access for normal operations.
10+
*/
11+
class RealFileSystem implements IFileSystem
12+
{
13+
/**
14+
* @inheritDoc
15+
*/
16+
public function fileExists( string $path ): bool
17+
{
18+
return file_exists( $path );
19+
}
20+
21+
/**
22+
* @inheritDoc
23+
*/
24+
public function readFile( string $path ): string|false
25+
{
26+
return file_get_contents( $path );
27+
}
28+
29+
/**
30+
* @inheritDoc
31+
*/
32+
public function isDir( string $path ): bool
33+
{
34+
return is_dir( $path );
35+
}
36+
37+
/**
38+
* @inheritDoc
39+
*/
40+
public function realpath( string $path ): string|false
41+
{
42+
return realpath( $path );
43+
}
44+
45+
/**
46+
* @inheritDoc
47+
*/
48+
public function getcwd(): string|false
49+
{
50+
return getcwd();
51+
}
52+
53+
/**
54+
* @inheritDoc
55+
*/
56+
public function writeFile( string $path, string $data ): int|false
57+
{
58+
return file_put_contents( $path, $data );
59+
}
60+
}

0 commit comments

Comments
 (0)