Skip to content

Commit 9d71303

Browse files
authored
Merge pull request #615 from flightphp/windows-fixes
Added some fixes to get this working in windows locally
2 parents 35b1a42 + 882a956 commit 9d71303

File tree

8 files changed

+34
-19
lines changed

8 files changed

+34
-19
lines changed

flight/Engine.php

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,13 +42,13 @@
4242
* Routes a PATCH URL to a callback function.
4343
* @method Route delete(string $pattern, callable|string $callback, bool $pass_route = false, string $alias = '')
4444
* Routes a DELETE URL to a callback function.
45-
* @method void resource(string $pattern, string $controllerClass, array $methods = [])
45+
* @method void resource(string $pattern, string $controllerClass, array<string, string|array<string>> $methods = [])
4646
* Adds standardized RESTful routes for a controller.
4747
* @method Router router() Gets router
4848
* @method string getUrl(string $alias) Gets a url from an alias
4949
*
5050
* # Views
51-
* @method void render(string $file, ?array $data = null, ?string $key = null) Renders template
51+
* @method void render(string $file, ?array<string,mixed> $data = null, ?string $key = null) Renders template
5252
* @method View view() Gets current view
5353
*
5454
* # Request-Response
@@ -600,7 +600,8 @@ public function _start(): void
600600
*/
601601
public function _error(Throwable $e): void
602602
{
603-
$msg = sprintf(<<<HTML
603+
$msg = sprintf(
604+
<<<'HTML'
604605
<h1>500 Internal Server Error</h1>
605606
<h3>%s (%s)</h3>
606607
<pre>%s</pre>

flight/Flight.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
* @method static void stop(?int $code = null) Stops the framework and sends a response.
2424
* @method static void halt(int $code = 200, string $message = '', bool $actuallyExit = true)
2525
* Stop the framework with an optional status code and message.
26-
* @method static void register(string $name, string $class, array $params = [], ?callable $callback = null)
26+
* @method static void register(string $name, string $class, array<int, mixed> $params = [], ?callable $callback = null)
2727
* Registers a class to a framework method.
2828
* @method static void unregister(string $methodName)
2929
* Unregisters a class to a framework method.
@@ -42,7 +42,7 @@
4242
* Routes a PATCH URL to a callback function.
4343
* @method static Route delete(string $pattern, callable|string $callback, bool $pass_route = false, string $alias = '')
4444
* Routes a DELETE URL to a callback function.
45-
* @method static void resource(string $pattern, string $controllerClass, array $methods = [])
45+
* @method static void resource(string $pattern, string $controllerClass, array<string, string|array<string>> $methods = [])
4646
* Adds standardized RESTful routes for a controller.
4747
* @method static Router router() Returns Router instance.
4848
* @method static string getUrl(string $alias, array<string, mixed> $params = []) Gets a url from an alias

flight/net/Route.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,7 @@ public function matchAlias(string $alias): bool
198198
public function hydrateUrl(array $params = []): string
199199
{
200200
$url = preg_replace_callback("/(?:@([\w]+)(?:\:([^\/]+))?\)*)/i", function ($match) use ($params) {
201-
if (isset($match[1]) && isset($params[$match[1]])) {
201+
if (isset($params[$match[1]]) === true) {
202202
return $params[$match[1]];
203203
}
204204
}, $this->pattern);

tests/FlightTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -378,7 +378,7 @@ public function testDoesNotPreserveVarsWhenFlagIsDisabled(
378378

379379
public function testKeepThePreviousStateOfOneViewComponentByDefault(): void
380380
{
381-
$this->expectOutputString(<<<html
381+
$this->expectOutputString(<<<'html'
382382
<div>Hi</div>
383383
<div>Hi</div>
384384

tests/ViewTest.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,7 @@ public function testDoesNotPreserveVarsWhenFlagIsDisabled(
175175

176176
public function testKeepThePreviousStateOfOneViewComponentByDefault(): void
177177
{
178-
$this->expectOutputString(<<<html
178+
$this->expectOutputString(<<<'html'
179179
<div>Hi</div>
180180
<div>Hi</div>
181181
@@ -197,7 +197,7 @@ public function testKeepThePreviousStateOfDataSettedBySetMethod(): void
197197

198198
$this->view->set('prop', 'bar');
199199

200-
$this->expectOutputString(<<<html
200+
$this->expectOutputString(<<<'html'
201201
<div>qux</div>
202202
<div>bar</div>
203203

@@ -211,7 +211,7 @@ public static function renderDataProvider(): array
211211
{
212212
return [
213213
[
214-
<<<html
214+
<<<'html'
215215
<div>Hi</div>
216216
<div></div>
217217

@@ -220,7 +220,7 @@ public static function renderDataProvider(): array
220220
'/^Undefined variable:? \$?prop$/'
221221
],
222222
[
223-
<<<html
223+
<<<'html'
224224
225225
<input type="number" />
226226

tests/commands/ControllerCommandTest.php

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,14 @@
1111

1212
class ControllerCommandTest extends TestCase
1313
{
14-
protected static $in = __DIR__ . '/input.test';
15-
protected static $ou = __DIR__ . '/output.test';
14+
protected static $in = '';
15+
protected static $ou = '';
1616

1717
public function setUp(): void
1818
{
19+
// Need dynamic filenames to avoid unlink() issues with windows.
20+
static::$in = __DIR__ . DIRECTORY_SEPARATOR . 'input.test' . uniqid('', true) . '.txt';
21+
static::$ou = __DIR__ . DIRECTORY_SEPARATOR . 'output.test' . uniqid('', true) . '.txt';
1922
file_put_contents(static::$in, '', LOCK_EX);
2023
file_put_contents(static::$ou, '', LOCK_EX);
2124
}
@@ -37,6 +40,10 @@ public function tearDown(): void
3740
if (file_exists(__DIR__ . '/controllers/')) {
3841
rmdir(__DIR__ . '/controllers/');
3942
}
43+
44+
// Thanks Windows
45+
clearstatcache();
46+
gc_collect_cycles();
4047
}
4148

4249
protected function newApp(string $name, string $version = '')

tests/commands/RouteCommandTest.php

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,16 @@
1313

1414
class RouteCommandTest extends TestCase
1515
{
16-
protected static $in = __DIR__ . '/input.test';
17-
protected static $ou = __DIR__ . '/output.test';
16+
protected static $in = __DIR__ . DIRECTORY_SEPARATOR . 'input.test';
17+
protected static $ou = __DIR__ . DIRECTORY_SEPARATOR . 'output.test';
1818

1919
public function setUp(): void
2020
{
21-
file_put_contents(static::$in, '', LOCK_EX);
22-
file_put_contents(static::$ou, '', LOCK_EX);
21+
// Need dynamic filenames to avoid unlink() issues with windows.
22+
static::$in = __DIR__ . DIRECTORY_SEPARATOR . 'input.test' . uniqid('', true) . '.txt';
23+
static::$ou = __DIR__ . DIRECTORY_SEPARATOR . 'output.test' . uniqid('', true) . '.txt';
24+
file_put_contents(static::$in, '');
25+
file_put_contents(static::$ou, '');
2326
$_SERVER = [];
2427
$_REQUEST = [];
2528
Flight::init();
@@ -43,6 +46,10 @@ public function tearDown(): void
4346
unset($_REQUEST);
4447
unset($_SERVER);
4548
Flight::clear();
49+
50+
// Thanks Windows
51+
clearstatcache();
52+
gc_collect_cycles();
4653
}
4754

4855
protected function newApp(string $name, string $version = '')
@@ -54,7 +61,7 @@ protected function newApp(string $name, string $version = '')
5461

5562
protected function createIndexFile()
5663
{
57-
$index = <<<PHP
64+
$index = <<<'PHP'
5865
<?php
5966
6067
require __DIR__ . '/../../vendor/autoload.php';

tests/server/index.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,7 @@
182182

183183
Flight::map('error', function (Throwable $e) {
184184
echo sprintf(
185-
<<<HTML
185+
<<<'HTML'
186186
<h1>500 Internal Server Error</h1>
187187
<h3>%s (%s)</h3>
188188
<pre style="border: 2px solid red; padding: 21px; background: lightgray; font-weight: bold;">%s</pre>

0 commit comments

Comments
 (0)