From 856cdbaf55b4304da0389b3ce33044f4b105e0fe Mon Sep 17 00:00:00 2001 From: Jesper Noordsij <45041769+jnoordsij@users.noreply.github.com> Date: Mon, 19 Apr 2021 15:26:42 +0200 Subject: [PATCH] [8.x] Allow the use of temporary views for Blade testing on Windows machines (#37044) * Allow the use of temporary views for Blade testing on Windows machines * Fix StyleCI issue * Add first test for InteractsWithViews trait * Fix StyleCI issues * Update InteractsWithViews.php Co-authored-by: Taylor Otwell --- .../Testing/Concerns/InteractsWithViews.php | 7 ++++--- .../Concerns/InteractsWithViewsTest.php | 18 ++++++++++++++++++ 2 files changed, 22 insertions(+), 3 deletions(-) create mode 100644 tests/Foundation/Testing/Concerns/InteractsWithViewsTest.php diff --git a/src/Illuminate/Foundation/Testing/Concerns/InteractsWithViews.php b/src/Illuminate/Foundation/Testing/Concerns/InteractsWithViews.php index 9dfbff5a38d2..574effe21260 100644 --- a/src/Illuminate/Foundation/Testing/Concerns/InteractsWithViews.php +++ b/src/Illuminate/Foundation/Testing/Concerns/InteractsWithViews.php @@ -4,7 +4,6 @@ use Illuminate\Support\Facades\View as ViewFacade; use Illuminate\Support\MessageBag; -use Illuminate\Support\Str; use Illuminate\Support\ViewErrorBag; use Illuminate\Testing\TestView; use Illuminate\View\View; @@ -38,11 +37,13 @@ protected function blade(string $template, array $data = []) ViewFacade::addLocation(sys_get_temp_dir()); } - $tempFile = tempnam($tempDirectory, 'laravel-blade').'.blade.php'; + $tempFileInfo = pathinfo(tempnam($tempDirectory, 'laravel-blade')); + + $tempFile = $tempFileInfo['dirname'].'/'.$tempFileInfo['filename'].'.blade.php'; file_put_contents($tempFile, $template); - return new TestView(view(Str::before(basename($tempFile), '.blade.php'), $data)); + return new TestView(view($tempFileInfo['filename'], $data)); } /** diff --git a/tests/Foundation/Testing/Concerns/InteractsWithViewsTest.php b/tests/Foundation/Testing/Concerns/InteractsWithViewsTest.php new file mode 100644 index 000000000000..42bc6c2ec28d --- /dev/null +++ b/tests/Foundation/Testing/Concerns/InteractsWithViewsTest.php @@ -0,0 +1,18 @@ +blade('@if(true)test @endif'); + + $this->assertEquals('test ', $string); + } +}