Skip to content

Instantly share code, notes, and snippets.

@osbre
Created April 17, 2025 21:38
Show Gist options
  • Save osbre/7f7074e499b3c429e98246d8dfa688fd to your computer and use it in GitHub Desktop.
Save osbre/7f7074e499b3c429e98246d8dfa688fd to your computer and use it in GitHub Desktop.
<?php
namespace Illuminate\Tests\View\Blade;
class BladeUseTest extends AbstractBladeTestCase
{
public function testUseStatementsAreCompiled()
{
$expected = "Foo <?php use \SomeNamespace\SomeClass as Foo; ?> bar";
$string = "Foo @use('SomeNamespace\SomeClass', 'Foo') bar";
$this->assertEquals($expected, $this->compiler->compileString($string));
$string = "Foo @use(SomeNamespace\SomeClass, Foo) bar";
$this->assertEquals($expected, $this->compiler->compileString($string));
}
public function testUseStatementsWithoutAsAreCompiled()
{
$expected = "Foo <?php use \SomeNamespace\SomeClass; ?> bar";
$string = "Foo @use('SomeNamespace\SomeClass') bar";
$this->assertEquals($expected, $this->compiler->compileString($string));
$string = "Foo @use(SomeNamespace\SomeClass) bar";
$this->assertEquals($expected, $this->compiler->compileString($string));
}
public function testUseStatementsWithBackslashAtBeginningAreCompiled()
{
$expected = "Foo <?php use \SomeNamespace\SomeClass; ?> bar";
$string = "Foo @use('\SomeNamespace\SomeClass') bar";
$this->assertEquals($expected, $this->compiler->compileString($string));
$string = "Foo @use(\SomeNamespace\SomeClass) bar";
$this->assertEquals($expected, $this->compiler->compileString($string));
}
public function testUseStatementsWithBackslashAtBeginningAndAliasedAreCompiled()
{
$expected = "Foo <?php use \SomeNamespace\SomeClass as Foo; ?> bar";
$string = "Foo @use('\SomeNamespace\SomeClass', 'Foo') bar";
$this->assertEquals($expected, $this->compiler->compileString($string));
$string = "Foo @use(\SomeNamespace\SomeClass, Foo) bar";
$this->assertEquals($expected, $this->compiler->compileString($string));
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment