From f20e02a5cf291a748f172d8258924ec3fd3c2c22 Mon Sep 17 00:00:00 2001 From: Mark Story Date: Sat, 1 Jun 2024 00:11:42 -0400 Subject: [PATCH] Expand coverage --- .../TestCase/Command/TemplateCommandTest.php | 46 ++++++++++++++++++- .../Template/testBakeIndexWithEnumNoLabel.php | 0 .../testBakeIndexWithEnumWithLabel.php | 0 .../Template/testBakeViewEnumNoLabel.php | 0 4 files changed, 45 insertions(+), 1 deletion(-) create mode 100644 tests/comparisons/Template/testBakeIndexWithEnumNoLabel.php create mode 100644 tests/comparisons/Template/testBakeIndexWithEnumWithLabel.php create mode 100644 tests/comparisons/Template/testBakeViewEnumNoLabel.php diff --git a/tests/TestCase/Command/TemplateCommandTest.php b/tests/TestCase/Command/TemplateCommandTest.php index 6ac9b0ec9..715b80fe6 100644 --- a/tests/TestCase/Command/TemplateCommandTest.php +++ b/tests/TestCase/Command/TemplateCommandTest.php @@ -17,6 +17,7 @@ namespace Bake\Test\TestCase\Command; use Bake\Command\TemplateCommand; +use Bake\Test\App\Model\Enum\ArticleStatus; use Bake\Test\App\Model\Enum\BakeUserStatus; use Bake\Test\App\Model\Table\BakeArticlesTable; use Bake\Test\TestCase\TestCase; @@ -459,6 +460,9 @@ public function testBakeView() */ public function testBakeViewEnum() { + $table = $this->fetchTable('BakeUsers'); + $table->getSchema()->setColumnType('status', EnumType::from(BakeUserStatus::class)); + $this->generatedFile = ROOT . 'templates/BakeUsers/view.php'; $this->exec('bake template bake_users view'); @@ -469,6 +473,26 @@ public function testBakeViewEnum() $this->assertSameAsFile(__FUNCTION__ . '.php', $result); } + /** + * test baking view with enum class + * + * @return void + */ + public function testBakeViewEnumNoLabel() + { + $table = $this->fetchTable('Articles'); + $table->getSchema()->setColumnType('status', EnumType::from(ArticleStatus::class)); + + $this->generatedFile = ROOT . 'templates/Articles/view.php'; + $this->exec('bake template articles view'); + + $this->assertExitCode(CommandInterface::CODE_SUCCESS); + $this->assertFileExists($this->generatedFile); + + $result = file_get_contents($this->generatedFile); + $this->assertSameAsFile(__FUNCTION__ . '.php', $result); + } + /** * Test generating view template with hidden fields * @@ -576,7 +600,7 @@ public function testBakeIndexWithIndexLimit() * * @return void */ - public function testBakeIndexWithEnum() + public function testBakeIndexWithEnumWithLabel() { $table = $this->fetchTable('BakeUsers'); $table->getSchema()->setColumnType('status', EnumType::from(BakeUserStatus::class)); @@ -591,6 +615,26 @@ public function testBakeIndexWithEnum() $this->assertSameAsFile(__FUNCTION__ . '.php', $result); } + /** + * test bake template with index enum types + * + * @return void + */ + public function testBakeIndexWithEnumNoLabel() + { + $table = $this->fetchTable('Articles'); + $table->getSchema()->setColumnType('status', EnumType::from(ArticleStatus::class)); + + $this->generatedFile = ROOT . 'templates/Articles/index.php'; + $this->exec('bake template articles index'); + + $this->assertExitCode(CommandInterface::CODE_SUCCESS); + $this->assertFileExists($this->generatedFile); + + $result = file_get_contents($this->generatedFile); + $this->assertSameAsFile(__FUNCTION__ . '.php', $result); + } + /** * test Bake with plugins * diff --git a/tests/comparisons/Template/testBakeIndexWithEnumNoLabel.php b/tests/comparisons/Template/testBakeIndexWithEnumNoLabel.php new file mode 100644 index 000000000..e69de29bb diff --git a/tests/comparisons/Template/testBakeIndexWithEnumWithLabel.php b/tests/comparisons/Template/testBakeIndexWithEnumWithLabel.php new file mode 100644 index 000000000..e69de29bb diff --git a/tests/comparisons/Template/testBakeViewEnumNoLabel.php b/tests/comparisons/Template/testBakeViewEnumNoLabel.php new file mode 100644 index 000000000..e69de29bb