Skip to content
This repository was archived by the owner on Oct 20, 2025. It is now read-only.

Commit 1b7eb03

Browse files
committed
updated tests command
- fixes typo in cli configuration - updated tests namespace in psr-4
1 parent cc26fde commit 1b7eb03

File tree

5 files changed

+51
-65
lines changed

5 files changed

+51
-65
lines changed

.gitattributes

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
/tests export-ignore
22
/.github export-ignore
3+
/.phpunit.cache export-ignore
34
.gitattributes export-ignore
45
.gitignore export-ignore
56
.phpunit.result.cache export-ignore

composer.json

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
"homepage": "https://github.com/PhpSlides",
55
"type": "library",
66
"license": "MIT",
7-
"keywords": [ "framework", "phpslides" ],
7+
"keywords": ["framework", "phpslides"],
88
"support": {
99
"issues": "https://github.com/PhpSlides/framework/issues",
1010
"source": "https://github.com/PhpSlides/framework"
@@ -31,22 +31,23 @@
3131
},
3232
"autoload": {
3333
"psr-4": {
34-
"PhpSlides\\": [ "src/Exception/" ],
35-
"PhpSlides\\Src\\": [ "src/" ],
36-
"PhpSlides\\Router\\": [ "Router/" ]
34+
"PhpSlides\\": "src/Exception/",
35+
"PhpSlides\\Src\\": "src/",
36+
"PhpSlides\\Router\\": "Router/"
3737
},
38-
"files": [ "src/Bootstrap/App.php" ]
38+
"files": ["src/Bootstrap/App.php"]
3939
},
4040
"autoload-dev": {
4141
"psr-4": {
42-
"PhpSlides\\Tests\\": "tests/"
42+
"PhpSlides\\Tests\\": "tests/tests/"
4343
}
4444
},
4545
"config": {
4646
"preferred-install": "dist"
4747
},
4848
"scripts": {
49-
"test": "vendor/bin/phpunit"
49+
"test": "vendor/bin/phpunit",
50+
"phpunit": "php vendor/bin/phpunit"
5051
},
5152
"minimum-stability": "stable",
5253
"prefer-stable": true

src/Cli/Configure.php

Lines changed: 13 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,19 @@
11
<?php declare(strict_types=1);
22

3-
43
namespace PhpSlides\Src\Cli;
54

65
trait Configure
76
{
8-
public static function bootstrap ()
9-
{
10-
if (php_sapi_name() == 'cli')
11-
{
12-
// Mock necessary $_SERVER variables
13-
$_SERVER['REQUEST_URI'] ??= '/';
14-
$_SERVER['REQUEST_METHOD'] ??= 'GET';
15-
$_SERVER['HTTP_HOST'] ??= 'localhost';
16-
$_SERVER['SERVER_NAME'] ??= 'localhost';
17-
$_SERVER['SERVER_PORT'] ??= '80';
18-
$_SERVER['HTTPS'] ??= 'off';
19-
}
20-
}
21-
}
7+
protected static function bootstrap()
8+
{
9+
if (php_sapi_name() == 'cli') {
10+
// Mock necessary $_SERVER variables
11+
$_SERVER['REQUEST_URI'] ??= '/';
12+
$_SERVER['REQUEST_METHOD'] ??= 'GET';
13+
$_SERVER['HTTP_HOST'] ??= 'localhost';
14+
$_SERVER['SERVER_NAME'] ??= 'localhost';
15+
$_SERVER['SERVER_PORT'] ??= '80';
16+
$_SERVER['HTTPS'] ??= 'off';
17+
}
18+
}
19+
}

src/Foundation/Application.php

Lines changed: 28 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
use Closure;
77
use PhpSlides\Router\Route;
88
use PhpSlides\Src\Http\Request;
9-
use PhpSlides\Src\Cli\Configure;
109
use PhpSlides\Src\Forgery\Forge;
1110
use PhpSlides\Src\Logger\Logger;
1211
use PhpSlides\Src\Logger\DBLogger;
@@ -30,12 +29,12 @@
3029
*/
3130
class Application extends Controller implements ApplicationInterface
3231
{
32+
use \PhpSlides\Src\Cli\Configure;
3333
use Configuration;
3434
use Logger;
35-
use DBLogger
36-
{
37-
Logger::log insteadof DBLogger;
38-
DBLogger::log as db_log;
35+
use DBLogger {
36+
Logger::log insteadof DBLogger;
37+
DBLogger::log as db_log;
3938
}
4039

4140
/**
@@ -97,37 +96,32 @@ class Application extends Controller implements ApplicationInterface
9796
*
9897
* @return self Returns an instance of the Application class.
9998
*/
100-
private static function configure (): void
99+
private static function configure(): void
101100
{
102-
if (php_sapi_name() == 'cli')
103-
{
104-
Configure::bootstrap();
101+
if (php_sapi_name() == 'cli') {
102+
static::bootstrap();
105103

106104
self::$request_uri = '/';
107105
self::$basePath = './tests/';
108-
}
109-
else if (php_sapi_name() == 'cli-server')
110-
{
106+
} elseif (php_sapi_name() == 'cli-server') {
111107
self::$request_uri = urldecode(
112-
parse_url($_SERVER['REQUEST_URI'], PHP_URL_PATH),
108+
parse_url($_SERVER['REQUEST_URI'], PHP_URL_PATH),
113109
);
114110
self::$basePath = '';
115-
}
116-
else
117-
{
111+
} else {
118112
self::$request_uri = urldecode(
119-
parse_url(
120-
$_REQUEST['uri'] ?? $_SERVER['REQUEST_URI'],
121-
PHP_URL_PATH,
122-
),
113+
parse_url(
114+
$_REQUEST['uri'] ?? $_SERVER['REQUEST_URI'],
115+
PHP_URL_PATH,
116+
),
123117
);
124118

125119
$find = '/src/routes/render.php';
126120
$self = $_SERVER['PHP_SELF'];
127121

128122
self::$basePath = strrpos($self, $find)
129-
? substr_replace($self, '/', strrpos($self, $find), strlen($find))
130-
: '../../';
123+
? substr_replace($self, '/', strrpos($self, $find), strlen($find))
124+
: '../../';
131125
}
132126

133127
$req = new Request();
@@ -141,7 +135,7 @@ private static function configure (): void
141135
*
142136
* @return void
143137
*/
144-
private static function paths (): void
138+
private static function paths(): void
145139
{
146140
self::$configsDir = self::$basePath . 'src/configs/';
147141
self::$viewsDir = self::$basePath . 'src/resources/views/';
@@ -154,15 +148,15 @@ private static function paths (): void
154148
*
155149
* @return void
156150
*/
157-
public function create (): void
151+
public function create(): void
158152
{
159153
self::configure();
160154
self::paths();
161155

162156
$loader = new FileLoader();
163157
$loader
164-
->load(__DIR__ . '/../Config/env.config.php')
165-
->load(__DIR__ . '/../Config/config.php');
158+
->load(__DIR__ . '/../Config/env.config.php')
159+
->load(__DIR__ . '/../Config/config.php');
166160

167161
session_start();
168162

@@ -171,11 +165,9 @@ public function create (): void
171165

172166
$sid = session_id();
173167

174-
if (getenv('HOT_RELOAD') == 'true')
175-
{
176-
Route::post("/hot-reload-a$sid", fn () => (new HotReload())->reload());
177-
Route::get("/hot-reload-a$sid/worker", function () use ($sid): string
178-
{
168+
if (getenv('HOT_RELOAD') == 'true') {
169+
Route::post("/hot-reload-a$sid", fn() => (new HotReload())->reload());
170+
Route::get("/hot-reload-a$sid/worker", function () use ($sid): string {
179171
$addr = self::$REMOTE_ADDR . "/hot-reload-a$sid";
180172
header('Content-Type: application/javascript');
181173

@@ -184,22 +176,18 @@ public function create (): void
184176
Render::WebRoute();
185177
}
186178

187-
try
188-
{
179+
try {
189180
Connection::init();
190181
DB::query('SELECT SCHEMA_NAME FROM INFORMATION_SCHEMA.SCHEMATA');
191-
}
192-
catch ( \Exception $e )
193-
{
182+
} catch (\Exception $e) {
194183
Database::$_connect_error = $e->getMessage();
195184
goto EXECUTION;
196185
}
197186
new Forge();
198187
new Autoloader();
199188

200189
EXECUTION:
201-
try
202-
{
190+
try {
203191
$loader->load(__DIR__ . '/../Globals/Functions.php');
204192

205193
$config_file = self::config_file();
@@ -209,14 +197,11 @@ public function create (): void
209197
header("Content-Type: text/html; charset=$charset");
210198

211199
self::config();
212-
}
213-
catch ( \Exception $e )
214-
{
200+
} catch (\Exception $e) {
215201
http_response_code(500);
216202
static::log();
217203

218-
if (function_exists('ExceptionHandler'))
219-
{
204+
if (function_exists('ExceptionHandler')) {
220205
call_user_func('ExceptionHandler', $e);
221206
}
222207
}

tests/.env

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
APP_NAME = 'PhpSlides'

0 commit comments

Comments
 (0)