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

Fixed tests and lint problems in windows #515

Merged
merged 7 commits into from
Jan 19, 2024
Merged
Show file tree
Hide file tree
Changes from 4 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
6 changes: 2 additions & 4 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -49,11 +49,9 @@
"lint": "phpstan --no-progress -cphpstan.neon"
},
"suggest": {
"latte/latte": "Latte template engine"
},
"suggest-dev": {
"latte/latte": "Latte template engine",
"tracy/tracy": "Tracy debugger"
},
},
"replace": {
"mikecao/flight": "2.0.2"
}
Expand Down
5 changes: 2 additions & 3 deletions flight/Engine.php
Original file line number Diff line number Diff line change
Expand Up @@ -707,9 +707,8 @@ public function _lastModified(int $time): void
/**
* Gets a url from an alias that's supplied.
*
* @param string $alias the route alias
* @param array<string,mixed> the params for the route if applicable
* @return string
* @param string $alias the route alias.
* @param array<string, mixed> $params The params for the route if applicable.
*/
public function _getUrl(string $alias, array $params = []): string
{
Expand Down
6 changes: 6 additions & 0 deletions flight/template/View.php
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,7 @@ public function render($file, $data = null)
$this->template = $this->getTemplate($file);

if (!file_exists($this->template)) {
$this->template = self::normalizePath($this->template);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So this will fix the path....but then it throws an exception so nothing is really fixed.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you mean about empty strings?

throw new \Exception("Template file not found: {$this->template}.");
}

Expand Down Expand Up @@ -208,4 +209,9 @@ public function e($str)
echo $value;
return $value;
}

protected static function normalizePath(string $path, string $separator = DIRECTORY_SEPARATOR): string
{
return str_replace(['\\', '/'], $separator, $path);
}
}
28 changes: 27 additions & 1 deletion tests/ViewTest.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
<?php

use flight\template\View;

/**
* Flight: An extensible micro-framework.
*
Expand Down Expand Up @@ -65,7 +68,7 @@ public function testRender()

public function testRenderBadFilePath() {
$this->expectException(Exception::class);
$this->expectExceptionMessage('Template file not found: '.__DIR__ . '/views/badfile.php');
$this->expectExceptionMessage('Template file not found: ' . __DIR__ . DIRECTORY_SEPARATOR . 'views'. DIRECTORY_SEPARATOR . 'badfile.php');

$this->view->render('badfile');
}
Expand Down Expand Up @@ -117,4 +120,27 @@ public function testENoNeedToEscape() {
$result = $this->view->e('script');
$this->assertEquals('script', $result);
}

public function testNormalizePath(): void
{
$viewMock = new class extends View {
public static function normalizePath(string $path, string $separator = DIRECTORY_SEPARATOR): string
{
return parent::normalizePath($path, $separator);
}
};

self::assertSame(
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not a huge deal but the rest of the file uses $this-> instead of self:: One thing I've learned that is really important is to keep the codebase as consistent as possible so it doesn't look like "Oh that's definitely a spot fadrian06 coded in". When I code in this framework, even though it drives me nuts, I keep all the class vars lowercase. I would much rather do $Router = Flight::router(); but in order to keep it consistent, I do $router = Flight::router(); simply because it's keeping it consistent.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oh sorry, I hadn't noticed

'C:/xampp/htdocs/libs/Flight/core/index.php',
$viewMock::normalizePath('C:\xampp\htdocs\libs\Flight/core/index.php', '/')
);
self::assertSame(
'C:\xampp\htdocs\libs\Flight\core\index.php',
$viewMock::normalizePath('C:/xampp/htdocs/libs/Flight\core\index.php', '\\')
);
self::assertSame(
'C:°xampp°htdocs°libs°Flight°core°index.php',
$viewMock::normalizePath('C:/xampp/htdocs/libs/Flight\core\index.php', '°')
);
}
}