Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added some fixes to get this working in windows locally #615

Merged
merged 1 commit into from
Jan 1, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions flight/Engine.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,13 +42,13 @@
* Routes a PATCH URL to a callback function.
* @method Route delete(string $pattern, callable|string $callback, bool $pass_route = false, string $alias = '')
* Routes a DELETE URL to a callback function.
* @method void resource(string $pattern, string $controllerClass, array $methods = [])
* @method void resource(string $pattern, string $controllerClass, array<string, string|array<string>> $methods = [])
* Adds standardized RESTful routes for a controller.
* @method Router router() Gets router
* @method string getUrl(string $alias) Gets a url from an alias
*
* # Views
* @method void render(string $file, ?array $data = null, ?string $key = null) Renders template
* @method void render(string $file, ?array<string,mixed> $data = null, ?string $key = null) Renders template
* @method View view() Gets current view
*
* # Request-Response
Expand Down Expand Up @@ -600,7 +600,8 @@ public function _start(): void
*/
public function _error(Throwable $e): void
{
$msg = sprintf(<<<HTML
$msg = sprintf(
<<<'HTML'
<h1>500 Internal Server Error</h1>
<h3>%s (%s)</h3>
<pre>%s</pre>
Expand Down
4 changes: 2 additions & 2 deletions flight/Flight.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
* @method static void stop(?int $code = null) Stops the framework and sends a response.
* @method static void halt(int $code = 200, string $message = '', bool $actuallyExit = true)
* Stop the framework with an optional status code and message.
* @method static void register(string $name, string $class, array $params = [], ?callable $callback = null)
* @method static void register(string $name, string $class, array<int, mixed> $params = [], ?callable $callback = null)
* Registers a class to a framework method.
* @method static void unregister(string $methodName)
* Unregisters a class to a framework method.
Expand All @@ -42,7 +42,7 @@
* Routes a PATCH URL to a callback function.
* @method static Route delete(string $pattern, callable|string $callback, bool $pass_route = false, string $alias = '')
* Routes a DELETE URL to a callback function.
* @method static void resource(string $pattern, string $controllerClass, array $methods = [])
* @method static void resource(string $pattern, string $controllerClass, array<string, string|array<string>> $methods = [])
* Adds standardized RESTful routes for a controller.
* @method static Router router() Returns Router instance.
* @method static string getUrl(string $alias, array<string, mixed> $params = []) Gets a url from an alias
Expand Down
2 changes: 1 addition & 1 deletion flight/net/Route.php
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ public function matchAlias(string $alias): bool
public function hydrateUrl(array $params = []): string
{
$url = preg_replace_callback("/(?:@([\w]+)(?:\:([^\/]+))?\)*)/i", function ($match) use ($params) {
if (isset($match[1]) && isset($params[$match[1]])) {
if (isset($params[$match[1]]) === true) {
return $params[$match[1]];
}
}, $this->pattern);
Expand Down
2 changes: 1 addition & 1 deletion tests/FlightTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -378,7 +378,7 @@ public function testDoesNotPreserveVarsWhenFlagIsDisabled(

public function testKeepThePreviousStateOfOneViewComponentByDefault(): void
{
$this->expectOutputString(<<<html
$this->expectOutputString(<<<'html'
<div>Hi</div>
<div>Hi</div>
Expand Down
8 changes: 4 additions & 4 deletions tests/ViewTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ public function testDoesNotPreserveVarsWhenFlagIsDisabled(

public function testKeepThePreviousStateOfOneViewComponentByDefault(): void
{
$this->expectOutputString(<<<html
$this->expectOutputString(<<<'html'
<div>Hi</div>
<div>Hi</div>
Expand All @@ -197,7 +197,7 @@ public function testKeepThePreviousStateOfDataSettedBySetMethod(): void

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

$this->expectOutputString(<<<html
$this->expectOutputString(<<<'html'
<div>qux</div>
<div>bar</div>

Expand All @@ -211,7 +211,7 @@ public static function renderDataProvider(): array
{
return [
[
<<<html
<<<'html'
<div>Hi</div>
<div></div>

Expand All @@ -220,7 +220,7 @@ public static function renderDataProvider(): array
'/^Undefined variable:? \$?prop$/'
],
[
<<<html
<<<'html'
<input type="number" />
Expand Down
11 changes: 9 additions & 2 deletions tests/commands/ControllerCommandTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,14 @@

class ControllerCommandTest extends TestCase
{
protected static $in = __DIR__ . '/input.test';
protected static $ou = __DIR__ . '/output.test';
protected static $in = '';
protected static $ou = '';

public function setUp(): void
{
// Need dynamic filenames to avoid unlink() issues with windows.
static::$in = __DIR__ . DIRECTORY_SEPARATOR . 'input.test' . uniqid('', true) . '.txt';
static::$ou = __DIR__ . DIRECTORY_SEPARATOR . 'output.test' . uniqid('', true) . '.txt';
file_put_contents(static::$in, '', LOCK_EX);
file_put_contents(static::$ou, '', LOCK_EX);
}
Expand All @@ -37,6 +40,10 @@ public function tearDown(): void
if (file_exists(__DIR__ . '/controllers/')) {
rmdir(__DIR__ . '/controllers/');
}

// Thanks Windows
clearstatcache();
gc_collect_cycles();
}

protected function newApp(string $name, string $version = '')
Expand Down
17 changes: 12 additions & 5 deletions tests/commands/RouteCommandTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,16 @@

class RouteCommandTest extends TestCase
{
protected static $in = __DIR__ . '/input.test';
protected static $ou = __DIR__ . '/output.test';
protected static $in = __DIR__ . DIRECTORY_SEPARATOR . 'input.test';
protected static $ou = __DIR__ . DIRECTORY_SEPARATOR . 'output.test';

public function setUp(): void
{
file_put_contents(static::$in, '', LOCK_EX);
file_put_contents(static::$ou, '', LOCK_EX);
// Need dynamic filenames to avoid unlink() issues with windows.
static::$in = __DIR__ . DIRECTORY_SEPARATOR . 'input.test' . uniqid('', true) . '.txt';
static::$ou = __DIR__ . DIRECTORY_SEPARATOR . 'output.test' . uniqid('', true) . '.txt';
file_put_contents(static::$in, '');
file_put_contents(static::$ou, '');
$_SERVER = [];
$_REQUEST = [];
Flight::init();
Expand All @@ -43,6 +46,10 @@ public function tearDown(): void
unset($_REQUEST);
unset($_SERVER);
Flight::clear();

// Thanks Windows
clearstatcache();
gc_collect_cycles();
}

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

protected function createIndexFile()
{
$index = <<<PHP
$index = <<<'PHP'
<?php
require __DIR__ . '/../../vendor/autoload.php';
Expand Down
2 changes: 1 addition & 1 deletion tests/server/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@

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