Skip to content

Commit 3827e9a

Browse files
committed
updated tests.
1 parent cf9258d commit 3827e9a

File tree

10 files changed

+277
-79
lines changed

10 files changed

+277
-79
lines changed

.gitignore

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,5 +15,4 @@ test.log
1515
CLAUDE.md
1616
/cache/
1717
/.claude/
18-
19-
coverage.xml
18+
coverage*

composer.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,8 @@
4141
"autoload-dev": {
4242
"psr-4": {
4343
"Mvc\\": "tests/Mvc",
44-
"Tests\\": "tests/Tests"
44+
"Tests\\": "tests/Tests",
45+
"Neuron\\Core\\": "../core/src/Core/"
4546
}
4647
},
4748
"extra": {

src/Bootstrap.php

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
namespace Neuron\Mvc;
33

44
use Neuron\Core\Exceptions\NotFound;
5+
use Neuron\Core\System\IFileSystem;
6+
use Neuron\Core\System\RealFileSystem;
57
use Neuron\Data\Filters\Get;
68
use Neuron\Data\Filters\Server;
79
use Neuron\Data\Objects\Version;
@@ -101,11 +103,14 @@ function clearExpiredCache( Application $app ) : int
101103
* This function looks for a file named _{name}.php in the shared views directory.
102104
* @param string $name The name of the partial (without underscore prefix or .php extension)
103105
* @param array $data Optional data array to pass to the partial as variables
106+
* @param IFileSystem|null $fs File system implementation (null = use real file system)
104107
* @return void
105108
* @throws NotFound
106109
*/
107-
function partial( string $name, array $data = [] ) : void
110+
function partial( string $name, array $data = [], ?IFileSystem $fs = null ) : void
108111
{
112+
$fs = $fs ?? new RealFileSystem();
113+
109114
$path = Registry::getInstance()
110115
->get( "Views.Path" );
111116

@@ -117,7 +122,7 @@ function partial( string $name, array $data = [] ) : void
117122

118123
$view = "$path/shared/_$name.php";
119124

120-
if( !file_exists( $view ) )
125+
if( !$fs->fileExists( $view ) )
121126
{
122127
throw new NotFound( "Partial not found: $view" );
123128
}

src/Mvc/Application.php

Lines changed: 26 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88
use Neuron\Core\Exceptions\MissingMethod;
99
use Neuron\Core\Exceptions\NotFound;
1010
use Neuron\Core\Exceptions\Validation;
11+
use Neuron\Core\System\IFileSystem;
12+
use Neuron\Core\System\RealFileSystem;
1113
use Neuron\Data\Settings\Source\ISettingSource;
1214
use Neuron\Log\Log;
1315
use Neuron\Mvc\Controllers\Factory;
@@ -32,17 +34,20 @@ class Application extends Base
3234
private array $_requests = [];
3335
private bool $_captureOutput = false;
3436
private ?string $_output = '';
37+
private IFileSystem $fs;
3538

3639
/**
3740
* Application constructor.
3841
* @param string $version
3942
* @param ISettingSource|null $source
43+
* @param IFileSystem|null $fs File system implementation (null = use real file system)
4044
* @throws Exception
4145
*/
42-
public function __construct( string $version ="1.0.0", ?ISettingSource $source = null )
46+
public function __construct( string $version ="1.0.0", ?ISettingSource $source = null, ?IFileSystem $fs = null )
4347
{
4448
$this->setHandleFatal( true );
4549
$this->setHandleErrors( true );
50+
$this->fs = $fs ?? new RealFileSystem();
4651

4752
parent::__construct( $version, $source );
4853

@@ -118,7 +123,14 @@ protected function loadRequests(): void
118123
$requestPath = $this->getRegistryObject( 'Requests.Path' );
119124
}
120125

121-
foreach( glob($requestPath . '/*.yaml') as $filename )
126+
$files = $this->fs->glob($requestPath . '/*.yaml');
127+
128+
if( $files === false )
129+
{
130+
return;
131+
}
132+
133+
foreach( $files as $filename )
122134
{
123135
$name = pathinfo( $filename )['filename'];
124136

@@ -374,15 +386,25 @@ protected function loadRoutes(): void
374386
$file = $this->getRoutesPath();
375387
}
376388

377-
if( !file_exists( $file . '/routes.yaml' ) )
389+
$routesFile = $file . '/routes.yaml';
390+
391+
if( !$this->fs->fileExists( $routesFile ) )
378392
{
379393
Log::debug( "routes.yaml not found." );
380394
return;
381395
}
382396

397+
$content = $this->fs->readFile( $routesFile );
398+
399+
if( $content === false )
400+
{
401+
Log::error( "Failed to read routes.yaml" );
402+
return;
403+
}
404+
383405
try
384406
{
385-
$data = Yaml::parseFile( $file . '/routes.yaml' );
407+
$data = Yaml::parse( $content );
386408
}
387409
catch( ParseException $exception )
388410
{

0 commit comments

Comments
 (0)