Skip to content

Commit

Permalink
[8.x] Allow the use of temporary views for Blade testing on Windows m…
Browse files Browse the repository at this point in the history
…achines (#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 <taylor@laravel.com>
  • Loading branch information
jnoordsij and taylorotwell committed Apr 19, 2021
1 parent aa1f47e commit 856cdba
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 3 deletions.
Expand Up @@ -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;
Expand Down Expand Up @@ -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));
}

/**
Expand Down
18 changes: 18 additions & 0 deletions tests/Foundation/Testing/Concerns/InteractsWithViewsTest.php
@@ -0,0 +1,18 @@
<?php

namespace Illuminate\Tests\Foundation\Testing\Concerns;

use Illuminate\Foundation\Testing\Concerns\InteractsWithViews;
use Orchestra\Testbench\TestCase;

class InteractsWithViewsTest extends TestCase
{
use InteractsWithViews;

public function testBladeCorrectlyRendersString()
{
$string = (string) $this->blade('@if(true)test @endif');

$this->assertEquals('test ', $string);
}
}

0 comments on commit 856cdba

Please sign in to comment.