From 679b4b7501eaf0d4c084131771a3e2e4e412da3d Mon Sep 17 00:00:00 2001 From: Thoriq Firdaus <2067467+tfirdaus@users.noreply.github.com> Date: Fri, 11 Oct 2024 00:56:31 +0700 Subject: [PATCH] Test if block.json is not there (#15) --- app/Foundation/Blocks.php | 5 +++++ tests/app/Foundation/BlocksTest.php | 1 + tests/phpunit/fixtures/inc/blocks/block-d/index.php | 0 3 files changed, 6 insertions(+) create mode 100644 tests/phpunit/fixtures/inc/blocks/block-d/index.php diff --git a/app/Foundation/Blocks.php b/app/Foundation/Blocks.php index c2ad6d5..c6a2dc5 100644 --- a/app/Foundation/Blocks.php +++ b/app/Foundation/Blocks.php @@ -8,6 +8,7 @@ use RecursiveDirectoryIterator; use SplFileInfo; +use function file_exists; use function is_dir; class Blocks @@ -36,6 +37,10 @@ public function register(): void continue; } + if (! file_exists($block->getRealPath() . '/block.json')) { + continue; + } + register_block_type($block->getRealPath()); } } diff --git a/tests/app/Foundation/BlocksTest.php b/tests/app/Foundation/BlocksTest.php index 00969da..50e6765 100644 --- a/tests/app/Foundation/BlocksTest.php +++ b/tests/app/Foundation/BlocksTest.php @@ -29,5 +29,6 @@ public function testRegister(): void self::assertTrue(isset($blocks['codex/block-a'])); self::assertTrue(isset($blocks['codex/block-b'])); self::assertFalse(isset($blocks['codex/block-c'])); + self::assertFalse(isset($blocks['codex/block-c'])); } } diff --git a/tests/phpunit/fixtures/inc/blocks/block-d/index.php b/tests/phpunit/fixtures/inc/blocks/block-d/index.php new file mode 100644 index 0000000..e69de29