Skip to content

Commit

Permalink
Adds more test cases.
Browse files Browse the repository at this point in the history
  • Loading branch information
lukeraymonddowning authored and taylorotwell committed Jun 7, 2021
1 parent b8c1532 commit 0e542b4
Showing 1 changed file with 31 additions and 10 deletions.
41 changes: 31 additions & 10 deletions tests/View/Blade/BladeEchoHandlerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,10 @@ public function testWhitespaceIsPreservedCorrectly()
);
}

public function testHandlerLogicWorksCorrectly()
/**
* @dataProvider handlerLogicDataProvider
*/
public function testHandlerLogicWorksCorrectly($blade)
{
$this->expectExceptionMessage('The fluent object has been successfully handled!');

Expand All @@ -63,23 +66,41 @@ public function testHandlerLogicWorksCorrectly()

$exampleObject = new Fluent();

eval(Str::of($this->compiler->compileString('{{$exampleObject}}'))->remove(['<?php', '?>']));
eval(Str::of($this->compiler->compileString($blade))->remove(['<?php', '?>']));
}

public function testHandlerLogicWorksCorrectlyWithSemicolon()
public function handlerLogicDataProvider()
{
$this->expectExceptionMessage('The fluent object has been successfully handled!');

$this->compiler->stringable(Fluent::class, function ($object) {
throw new Exception('The fluent object has been successfully handled!');
});
return [
['{{$exampleObject}}'],
['{{$exampleObject;}}'],
];
}

/**
* @dataProvider nonStringableDataProvider
*/
public function testHandlerWorksWithNonStringables($blade, $expectedOutput)
{
app()->singleton('blade.compiler', function () {
return $this->compiler;
});

$exampleObject = new Fluent();
// We output to the buffer to avoid outputting in the test console.
ob_start();
eval(Str::of($this->compiler->compileString($blade))->remove(['<?php', '?>']));
$output = ob_get_contents();
ob_end_clean();

eval(Str::of($this->compiler->compileString('{{$exampleObject;}}'))->remove(['<?php', '?>']));
$this->assertSame($expectedOutput, $output);
}

public function nonStringableDataProvider()
{
return [
['{{"foo" . "bar"}}', 'foobar'],
['{{ 1 + 2 }}{{ "test"; }}', '3test'],
['@php($test = "hi"){{ $test }}', 'hi']
];
}
}

0 comments on commit 0e542b4

Please sign in to comment.