Merge pull request #615 from flightphp/windows-fixes

Added some fixes to get this working in windows locally
pull/618/head
fadrian06 3 weeks ago committed by GitHub
commit 9d71303384
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

@ -42,13 +42,13 @@ use flight\net\Route;
* Routes a PATCH URL to a callback function. * Routes a PATCH URL to a callback function.
* @method Route delete(string $pattern, callable|string $callback, bool $pass_route = false, string $alias = '') * @method Route delete(string $pattern, callable|string $callback, bool $pass_route = false, string $alias = '')
* Routes a DELETE URL to a callback function. * 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. * Adds standardized RESTful routes for a controller.
* @method Router router() Gets router * @method Router router() Gets router
* @method string getUrl(string $alias) Gets a url from an alias * @method string getUrl(string $alias) Gets a url from an alias
* *
* # Views * # 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 * @method View view() Gets current view
* *
* # Request-Response * # Request-Response
@ -600,7 +600,8 @@ class Engine
*/ */
public function _error(Throwable $e): void public function _error(Throwable $e): void
{ {
$msg = sprintf(<<<HTML $msg = sprintf(
<<<'HTML'
<h1>500 Internal Server Error</h1> <h1>500 Internal Server Error</h1>
<h3>%s (%s)</h3> <h3>%s (%s)</h3>
<pre>%s</pre> <pre>%s</pre>

@ -23,7 +23,7 @@ require_once __DIR__ . '/autoload.php';
* @method static void stop(?int $code = null) Stops the framework and sends a response. * @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) * @method static void halt(int $code = 200, string $message = '', bool $actuallyExit = true)
* Stop the framework with an optional status code and message. * 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. * Registers a class to a framework method.
* @method static void unregister(string $methodName) * @method static void unregister(string $methodName)
* Unregisters a class to a framework method. * Unregisters a class to a framework method.
@ -42,7 +42,7 @@ require_once __DIR__ . '/autoload.php';
* Routes a PATCH URL to a callback function. * Routes a PATCH URL to a callback function.
* @method static Route delete(string $pattern, callable|string $callback, bool $pass_route = false, string $alias = '') * @method static Route delete(string $pattern, callable|string $callback, bool $pass_route = false, string $alias = '')
* Routes a DELETE URL to a callback function. * 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. * Adds standardized RESTful routes for a controller.
* @method static Router router() Returns Router instance. * @method static Router router() Returns Router instance.
* @method static string getUrl(string $alias, array<string, mixed> $params = []) Gets a url from an alias * @method static string getUrl(string $alias, array<string, mixed> $params = []) Gets a url from an alias

@ -198,7 +198,7 @@ class Route
public function hydrateUrl(array $params = []): string public function hydrateUrl(array $params = []): string
{ {
$url = preg_replace_callback("/(?:@([\w]+)(?:\:([^\/]+))?\)*)/i", function ($match) use ($params) { $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]]; return $params[$match[1]];
} }
}, $this->pattern); }, $this->pattern);

@ -378,7 +378,7 @@ class FlightTest extends TestCase
public function testKeepThePreviousStateOfOneViewComponentByDefault(): void public function testKeepThePreviousStateOfOneViewComponentByDefault(): void
{ {
$this->expectOutputString(<<<html $this->expectOutputString(<<<'html'
<div>Hi</div> <div>Hi</div>
<div>Hi</div> <div>Hi</div>

@ -175,7 +175,7 @@ class ViewTest extends TestCase
public function testKeepThePreviousStateOfOneViewComponentByDefault(): void public function testKeepThePreviousStateOfOneViewComponentByDefault(): void
{ {
$this->expectOutputString(<<<html $this->expectOutputString(<<<'html'
<div>Hi</div> <div>Hi</div>
<div>Hi</div> <div>Hi</div>
@ -197,7 +197,7 @@ class ViewTest extends TestCase
$this->view->set('prop', 'bar'); $this->view->set('prop', 'bar');
$this->expectOutputString(<<<html $this->expectOutputString(<<<'html'
<div>qux</div> <div>qux</div>
<div>bar</div> <div>bar</div>
@ -211,7 +211,7 @@ class ViewTest extends TestCase
{ {
return [ return [
[ [
<<<html <<<'html'
<div>Hi</div> <div>Hi</div>
<div></div> <div></div>
@ -220,7 +220,7 @@ class ViewTest extends TestCase
'/^Undefined variable:? \$?prop$/' '/^Undefined variable:? \$?prop$/'
], ],
[ [
<<<html <<<'html'
<input type="number" /> <input type="number" />

@ -11,11 +11,14 @@ use PHPUnit\Framework\TestCase;
class ControllerCommandTest extends TestCase class ControllerCommandTest extends TestCase
{ {
protected static $in = __DIR__ . '/input.test'; protected static $in = '';
protected static $ou = __DIR__ . '/output.test'; protected static $ou = '';
public function setUp(): void 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::$in, '', LOCK_EX);
file_put_contents(static::$ou, '', LOCK_EX); file_put_contents(static::$ou, '', LOCK_EX);
} }
@ -37,6 +40,10 @@ class ControllerCommandTest extends TestCase
if (file_exists(__DIR__ . '/controllers/')) { if (file_exists(__DIR__ . '/controllers/')) {
rmdir(__DIR__ . '/controllers/'); rmdir(__DIR__ . '/controllers/');
} }
// Thanks Windows
clearstatcache();
gc_collect_cycles();
} }
protected function newApp(string $name, string $version = '') protected function newApp(string $name, string $version = '')

@ -13,13 +13,16 @@ use PHPUnit\Framework\TestCase;
class RouteCommandTest extends TestCase class RouteCommandTest extends TestCase
{ {
protected static $in = __DIR__ . '/input.test'; protected static $in = __DIR__ . DIRECTORY_SEPARATOR . 'input.test';
protected static $ou = __DIR__ . '/output.test'; protected static $ou = __DIR__ . DIRECTORY_SEPARATOR . 'output.test';
public function setUp(): void public function setUp(): void
{ {
file_put_contents(static::$in, '', LOCK_EX); // Need dynamic filenames to avoid unlink() issues with windows.
file_put_contents(static::$ou, '', LOCK_EX); 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 = []; $_SERVER = [];
$_REQUEST = []; $_REQUEST = [];
Flight::init(); Flight::init();
@ -43,6 +46,10 @@ class RouteCommandTest extends TestCase
unset($_REQUEST); unset($_REQUEST);
unset($_SERVER); unset($_SERVER);
Flight::clear(); Flight::clear();
// Thanks Windows
clearstatcache();
gc_collect_cycles();
} }
protected function newApp(string $name, string $version = '') protected function newApp(string $name, string $version = '')
@ -54,7 +61,7 @@ class RouteCommandTest extends TestCase
protected function createIndexFile() protected function createIndexFile()
{ {
$index = <<<PHP $index = <<<'PHP'
<?php <?php
require __DIR__ . '/../../vendor/autoload.php'; require __DIR__ . '/../../vendor/autoload.php';

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

Loading…
Cancel
Save