diff --git a/src/flextype/core/Parsers/Shortcodes/PhpShortcode.php b/src/flextype/core/Parsers/Shortcodes/PhpShortcode.php index a51cf56b..d63e87ee 100644 --- a/src/flextype/core/Parsers/Shortcodes/PhpShortcode.php +++ b/src/flextype/core/Parsers/Shortcodes/PhpShortcode.php @@ -24,8 +24,12 @@ parsers()->shortcodes()->addHandler('php', static function (ShortcodeInterface $ if (! registry()->get('flextype.settings.parsers.shortcodes.shortcodes.php.enabled')) { return ''; } - - ob_start(); - eval($s->getContent()); - return ob_get_clean(); + + if ($s->getContent() != null) { + ob_start(); + eval($s->getContent()); + return ob_get_clean(); + } + + return '@php'; }); \ No newline at end of file diff --git a/tests/src/flextype/core/Parsers/Shortcodes/PhpShortcodeTest.php b/tests/src/flextype/core/Parsers/Shortcodes/PhpShortcodeTest.php index 0543e5d4..5c4556f2 100644 --- a/tests/src/flextype/core/Parsers/Shortcodes/PhpShortcodeTest.php +++ b/tests/src/flextype/core/Parsers/Shortcodes/PhpShortcodeTest.php @@ -2,7 +2,17 @@ declare(strict_types=1); -test('[php] shortcode', function () { - $this->assertEquals("Foo", - parsers()->shortcodes()->parse('(php)echo "Foo";(/php)')); +beforeEach(function() { + filesystem()->directory(PATH['project'] . '/entries')->ensureExists(0755, true); +}); + +afterEach(function () { + filesystem()->directory(PATH['project'] . '/entries')->delete(); +}); + +test('php shortcode', function () { + $this->assertEquals("Foo", parsers()->shortcodes()->parse('(php)echo "Foo";(/php)')); + + expect(entries()->create('bar', ['test' => '(php) echo "Bar";']))->toBeTrue(); + expect(entries()->fetch('bar')['test'])->toBe('Bar'); });