BladeTest::renderBasicBlade()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 8
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 4
nc 1
nop 1
dl 0
loc 8
rs 10
c 0
b 0
f 0
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
Security Best Practice introduced by
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 ignore-unhandled  annotation

68
        /** @scrutinizer ignore-unhandled */ @file_put_contents(

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...
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
Bug Best Practice introduced by
The expression return view()->make('vue')->render() also could return the type array which is incompatible with the documented return type string.
Loading history...
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
Security Best Practice introduced by
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 ignore-unhandled  annotation

84
        /** @scrutinizer ignore-unhandled */ @file_put_contents(

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
Bug Best Practice introduced by
The expression return view()->make('vue')->render() also could return the type array which is incompatible with the documented return type string.
Loading history...
90
    }
91
}
92