Я пытаюсь выполнить модульное тестирование пользовательского блейда, если в laravel.
<?php
namespace Tests\Unit;
use Tests\TestCase;
use Illuminate\Filesystem\Filesystem;
use Illuminate\View\Compilers\BladeCompiler;
class BladeIfAdminStatementTest extends TestCase
{
public function testIfAdminStatementAreCompiled()
{
$compiler = new BladeCompiler(\Mockery::mock(Filesystem::class), __DIR__);
$string = '@admin test @endadmin';
$expected = '<?php if(auth->check() && auth()->user()->isAdmin()): ?> test <?php endif; ?>';
$this->assertEquals($expected, $compiler->compileString($string));
}
}
В AppServiceProvider.php
<?php
...
public function boot()
{
\Blade::if('admin', function () {
return auth()->check() && auth()->user()->isAdmin();
});
}
Когда я запускаю phpunit, я получаю:
Failed asserting that two strings are equal.
Expected :'<?php if(auth->check() && auth()->user()->isAdmin()): ?> test <?php endif; ?>'
Actual :'@admin test @endadmin'
Когда я пытаюсь изменить $string
с @admin test @endadmin
на @if(true) test @endif
и запустить phpunit:
Failed asserting that two strings are equal.
Expected :'<?php if(auth->check() && auth()->user()->isAdmin()): ?> test <?php endif; ?>'
Actual :'<?php if(true): ?> test <?php endif; ?>'
Обратите внимание, что это не удалось, но все равно оператор @if
скомпилированправильно, в то время как мой пользовательский оператор @admin
не является.