| 1 | <?php |
||||
| 2 | |||||
| 3 | namespace Jhoff\BladeVue\Testing\Integration; |
||||
| 4 | |||||
| 5 | use Jhoff\BladeVue\Testing\TestCase; |
||||
| 6 | |||||
| 7 | class BladeTest extends TestCase |
||||
| 8 | { |
||||
| 9 | /** |
||||
| 10 | * @test |
||||
| 11 | */ |
||||
| 12 | public function bladeRendersBasicVueDirective() |
||||
| 13 | { |
||||
| 14 | $output = $this->renderBasicBlade('"my-component"'); |
||||
| 15 | |||||
| 16 | $this->assertStringContainsString('<component', $output); |
||||
| 17 | $this->assertStringContainsString('is="my-component"', $output); |
||||
| 18 | $this->assertStringContainsString('</component>', $output); |
||||
| 19 | } |
||||
| 20 | |||||
| 21 | /** |
||||
| 22 | * @test |
||||
| 23 | */ |
||||
| 24 | public function bladeRendersAdvancedVueDirective() |
||||
| 25 | { |
||||
| 26 | $output = $this->renderBasicBlade('"my-component", ["foo" => "bar"]'); |
||||
| 27 | |||||
| 28 | $this->assertStringContainsString('<component', $output); |
||||
| 29 | $this->assertStringContainsString('is="my-component"', $output); |
||||
| 30 | $this->assertStringContainsString('foo="bar"', $output); |
||||
| 31 | $this->assertStringContainsString('</component>', $output); |
||||
| 32 | } |
||||
| 33 | /** |
||||
| 34 | * @test |
||||
| 35 | */ |
||||
| 36 | public function bladeRendersInlineVueDirective() |
||||
| 37 | { |
||||
| 38 | $output = $this->renderInlineBlade('"my-component"'); |
||||
| 39 | |||||
| 40 | $this->assertStringContainsString('<component', $output); |
||||
| 41 | $this->assertStringContainsString('inline-template', $output); |
||||
| 42 | $this->assertStringContainsString('is="my-component"', $output); |
||||
| 43 | $this->assertStringContainsString('</component>', $output); |
||||
| 44 | } |
||||
| 45 | |||||
| 46 | /** |
||||
| 47 | * @test |
||||
| 48 | */ |
||||
| 49 | public function bladeRendersAdvancedInlineVueDirective() |
||||
| 50 | { |
||||
| 51 | $output = $this->renderInlineBlade('"my-component", ["foo" => "bar"]'); |
||||
| 52 | |||||
| 53 | $this->assertStringContainsString('<component', $output); |
||||
| 54 | $this->assertStringContainsString('inline-template', $output); |
||||
| 55 | $this->assertStringContainsString('is="my-component"', $output); |
||||
| 56 | $this->assertStringContainsString('foo="bar"', $output); |
||||
| 57 | $this->assertStringContainsString('</component>', $output); |
||||
| 58 | } |
||||
| 59 | |||||
| 60 | /** |
||||
| 61 | * Creates a vue file in the testbench views directory and renders it |
||||
| 62 | * |
||||
| 63 | * @param string $expression |
||||
| 64 | * @return string |
||||
| 65 | */ |
||||
| 66 | protected function renderBasicBlade(string $expression) |
||||
| 67 | { |
||||
| 68 | @file_put_contents( |
||||
|
0 ignored issues
–
show
|
|||||
| 69 | resource_path('views/vue.blade.php'), |
||||
| 70 | "@vue($expression)\n<div>Testing</div>\n@endvue" |
||||
| 71 | ); |
||||
| 72 | |||||
| 73 | return view()->make('vue')->render(); |
||||
|
0 ignored issues
–
show
|
|||||
| 74 | } |
||||
| 75 | |||||
| 76 | /** |
||||
| 77 | * Creates a vue file in the testbench views directory and renders it |
||||
| 78 | * |
||||
| 79 | * @param string $expression |
||||
| 80 | * @return string |
||||
| 81 | */ |
||||
| 82 | protected function renderInlineBlade(string $expression) |
||||
| 83 | { |
||||
| 84 | @file_put_contents( |
||||
|
0 ignored issues
–
show
It seems like you do not handle an error condition for
file_put_contents(). This can introduce security issues, and is generally not recommended.
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
If you suppress an error, we recommend checking for the error condition explicitly: // For example instead of
@mkdir($dir);
// Better use
if (@mkdir($dir) === false) {
throw new \RuntimeException('The directory '.$dir.' could not be created.');
}
Loading history...
|
|||||
| 85 | resource_path('views/vue.blade.php'), |
||||
| 86 | "@inlinevue($expression)\n<div>Testing</div>\n@endinlinevue" |
||||
| 87 | ); |
||||
| 88 | |||||
| 89 | return view()->make('vue')->render(); |
||||
|
0 ignored issues
–
show
|
|||||
| 90 | } |
||||
| 91 | } |
||||
| 92 |
If you suppress an error, we recommend checking for the error condition explicitly: