-
Notifications
You must be signed in to change notification settings - Fork 102
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
39fceee
commit 75d452f
Showing
6 changed files
with
160 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
<?php | ||
declare(strict_types=1); | ||
|
||
/** | ||
* CakePHP(tm) : Rapid Development Framework (https://cakephp.org) | ||
* Copyright (c) Cake Software Foundation, Inc. (https://cakefoundation.org) | ||
* | ||
* Licensed under The MIT License | ||
* For full copyright and license information, please see the LICENSE.txt | ||
* Redistributions of files must retain the above copyright notice. | ||
* | ||
* @copyright Copyright (c) Cake Software Foundation, Inc. (https://cakefoundation.org) | ||
* @link https://cakephp.org CakePHP(tm) Project | ||
* @since 3.1.0 | ||
* @license https://www.opensource.org/licenses/mit-license.php MIT License | ||
*/ | ||
namespace Bake\Command; | ||
|
||
/** | ||
* Enum code generator. | ||
*/ | ||
class EnumCommand extends SimpleBakeCommand | ||
{ | ||
/** | ||
* Task name used in path generation. | ||
* | ||
* @var string | ||
*/ | ||
public string $pathFragment = 'Model/Enum/'; | ||
|
||
/** | ||
* @inheritDoc | ||
*/ | ||
public function name(): string | ||
{ | ||
return 'enum'; | ||
} | ||
|
||
/** | ||
* @inheritDoc | ||
*/ | ||
public function fileName(string $name): string | ||
{ | ||
return $name . '.php'; | ||
} | ||
|
||
/** | ||
* @inheritDoc | ||
*/ | ||
public function template(): string | ||
{ | ||
return 'Bake.Model/enum'; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
{# | ||
/** | ||
* CakePHP(tm) : Rapid Development Framework (https://cakephp.org) | ||
* Copyright (c) Cake Software Foundation, Inc. (https://cakefoundation.org) | ||
* | ||
* Licensed under The MIT License | ||
* For full copyright and license information, please see the LICENSE.txt | ||
* Redistributions of files must retain the above copyright notice. | ||
* | ||
* @copyright Copyright (c) Cake Software Foundation, Inc. (https://cakefoundation.org) | ||
* @link https://cakephp.org CakePHP(tm) Project | ||
* @since 3.1.0 | ||
* @license https://www.opensource.org/licenses/mit-license.php MIT License | ||
*/ | ||
#} | ||
{{ element('Bake.file_header', { | ||
namespace: "#{namespace}\\Model\\Enum", | ||
}) }} | ||
|
||
{{ DocBlock.classDescription(name, 'Enum', [])|raw }} | ||
enum {{ name }}: int | ||
{ | ||
/** | ||
* @return string | ||
*/ | ||
public function label(): string | ||
{ | ||
return mb_strtolower($this->name); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
<?php | ||
declare(strict_types=1); | ||
|
||
/** | ||
* CakePHP(tm) : Rapid Development Framework (https://cakephp.org) | ||
* Copyright (c) Cake Software Foundation, Inc. (https://cakefoundation.org) | ||
* | ||
* Licensed under The MIT License | ||
* For full copyright and license information, please see the LICENSE.txt | ||
* Redistributions of files must retain the above copyright notice. | ||
* | ||
* @copyright Copyright (c) Cake Software Foundation, Inc. (https://cakefoundation.org) | ||
* @link https://cakephp.org CakePHP(tm) Project | ||
* @since 3.1.0 | ||
* @license https://www.opensource.org/licenses/mit-license.php MIT License | ||
*/ | ||
namespace Bake\Test\TestCase\Command; | ||
|
||
use Bake\Test\TestCase\TestCase; | ||
use Cake\Console\CommandInterface; | ||
use Cake\Core\Plugin; | ||
|
||
/** | ||
* EnumCommandTest class | ||
*/ | ||
class EnumCommandTest extends TestCase | ||
{ | ||
/** | ||
* setup method | ||
* | ||
* @return void | ||
*/ | ||
public function setUp(): void | ||
{ | ||
parent::setUp(); | ||
$this->_compareBasePath = Plugin::path('Bake') . 'tests' . DS . 'comparisons' . DS . 'Model' . DS; | ||
$this->setAppNamespace('Bake\Test\App'); | ||
} | ||
|
||
/** | ||
* test baking an enum | ||
* | ||
* @return void | ||
*/ | ||
public function testBakeEnum() | ||
{ | ||
$this->generatedFile = APP . 'Model/Enum/FooBar.php'; | ||
$this->exec('bake enum FooBar', ['y']); | ||
|
||
$this->assertExitCode(CommandInterface::CODE_SUCCESS); | ||
$this->assertFileExists($this->generatedFile); | ||
$result = file_get_contents($this->generatedFile); | ||
$this->assertSameAsFile(__FUNCTION__ . '.php', $result); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
<?php | ||
declare(strict_types=1); | ||
|
||
namespace Bake\Test\App\Model\Enum; | ||
|
||
/** | ||
* FooBar Enum | ||
*/ | ||
enum FooBar: int | ||
{ | ||
/** | ||
* @return string | ||
*/ | ||
public function label(): string | ||
{ | ||
return mb_strtolower($this->name); | ||
} | ||
} |