Skip to content
This repository was archived by the owner on Oct 20, 2025. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
Refactor + run stub tests on Windows
  • Loading branch information
pascalbaljet committed Aug 2, 2022
commit 7f740f18ff47cd4c92be110919c8e04bc76e7c1d
3 changes: 2 additions & 1 deletion .github/workflows/run-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -127,11 +127,12 @@ jobs:
path: app/storage/logs

stub-tests:
runs-on: ubuntu-latest
runs-on: ${{ matrix.os }}

strategy:
fail-fast: true
matrix:
os: [ubuntu-latest, windows-2019]
php: [8.1, 8.0]
laravel: [9.*]
dependency-version: [prefer-lowest, prefer-stable]
Expand Down
26 changes: 18 additions & 8 deletions src/Commands/SpladeInstallCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -72,11 +72,21 @@ public function handle(): int
return self::SUCCESS;
}

/**
* End of line symbol.
*
* @return string
*/
private static function eol(): string
{
return windows_os() ? "\n" : PHP_EOL;
}

protected function installExceptionHandler()
{
$exceptionHandler = str_replace("\r\n", "\n", file_get_contents(app_path('Exceptions/Handler.php')));
$exceptionHandler = file_get_contents(app_path('Exceptions/Handler.php'));

$search = str_replace("\r\n", "\n", 'public function register()' . PHP_EOL . ' {');
$search = 'public function register()' . static::eol() . ' {';

$registerMethodAfter = Str::after($exceptionHandler, $search);

Expand All @@ -90,7 +100,7 @@ protected function installExceptionHandler()
app_path('Exceptions/Handler.php'),
str_replace(
$registerMethodAfter,
PHP_EOL . ' ' . $renderable . PHP_EOL . $registerMethodAfter,
static::eol() . ' ' . $renderable . static::eol() . $registerMethodAfter,
$exceptionHandler
)
);
Expand All @@ -103,13 +113,13 @@ protected function installExceptionHandler()
*/
protected function installRouteMiddleware()
{
$httpKernel = str_replace("\r\n", "\n", file_get_contents(app_path('Http/Kernel.php')));
$httpKernel = file_get_contents(app_path('Http/Kernel.php'));

$search = str_replace("\r\n", "\n", 'protected $routeMiddleware = [' . PHP_EOL);
$search = 'protected $routeMiddleware = [' . static::eol();

$routeMiddlewareAfter = Str::after($httpKernel, $search);

$routeMiddleware = "'splade' => \ProtoneMedia\Splade\Http\SpladeMiddleware::class";
$routeMiddleware = "'splade' => \ProtoneMedia\Splade\Http\SpladeMiddleware::class";

if (Str::contains($httpKernel, $routeMiddleware)) {
return;
Expand All @@ -119,7 +129,7 @@ protected function installRouteMiddleware()
app_path('Http/Kernel.php'),
str_replace(
$routeMiddlewareAfter,
' ' . $routeMiddleware . ',' . PHP_EOL . $routeMiddlewareAfter,
' ' . $routeMiddleware . ',' . static::eol() . $routeMiddlewareAfter,
$httpKernel
)
);
Expand Down Expand Up @@ -165,7 +175,7 @@ protected static function updateNodePackages(callable $callback, $dev = true)

file_put_contents(
base_path('package.json'),
json_encode($packages, JSON_UNESCAPED_SLASHES | JSON_PRETTY_PRINT) . PHP_EOL
json_encode($packages, JSON_UNESCAPED_SLASHES | JSON_PRETTY_PRINT) . static::eol()
);
}
}