From 19f13b286dfd1a24e1ddd91a97ffd2c5f05dccad Mon Sep 17 00:00:00 2001 From: Yevgeny Tomenko Date: Wed, 1 Jul 2026 07:36:47 +0300 Subject: [PATCH 1/2] fix event callback --- src/Model/Behavior/EnumBehavior.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/Model/Behavior/EnumBehavior.php b/src/Model/Behavior/EnumBehavior.php index ecd3426..a288016 100644 --- a/src/Model/Behavior/EnumBehavior.php +++ b/src/Model/Behavior/EnumBehavior.php @@ -251,9 +251,9 @@ protected function translate(array $list): array /** * @param \Cake\Event\EventInterface $event Event. * @param \Cake\ORM\RulesChecker $rules Rules checker. - * @return \Cake\ORM\RulesChecker + * @return void */ - public function buildRules(EventInterface $event, RulesChecker $rules): RulesChecker + public function buildRules(EventInterface $event, RulesChecker $rules): void { foreach ($this->getConfig('lists') as $alias => $config) { if (Hash::get($config, 'applicationRules') === false) { @@ -267,7 +267,7 @@ public function buildRules(EventInterface $event, RulesChecker $rules): RulesChe ]); } - return $rules; + $event->setResult($rules); } /** From d769ddbf95e9bd917ee1eab5be7677e155b27039 Mon Sep 17 00:00:00 2001 From: Yevgeny Tomenko Date: Wed, 1 Jul 2026 07:54:03 +0300 Subject: [PATCH 2/2] =?UTF-8?q?cakephp=205.3=20=D0=B3pgrade?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- composer.json | 4 ++-- src/Model/Behavior/EnumBehavior.php | 2 +- .../TestCase/Model/Behavior/EnumBehaviorTest.php | 16 ++++++++-------- 3 files changed, 11 insertions(+), 11 deletions(-) diff --git a/composer.json b/composer.json index 756c7f6..d2e63f2 100644 --- a/composer.json +++ b/composer.json @@ -14,8 +14,8 @@ "source": "https://github.com/cakedc/enum" }, "require": { - "php": ">=8.1", - "cakephp/cakephp": "^5.0.6" + "php": ">=8.2", + "cakephp/cakephp": "^5.3" }, "require-dev": { "phpunit/phpunit": "^10.5.20", diff --git a/src/Model/Behavior/EnumBehavior.php b/src/Model/Behavior/EnumBehavior.php index a288016..3d73b7d 100644 --- a/src/Model/Behavior/EnumBehavior.php +++ b/src/Model/Behavior/EnumBehavior.php @@ -293,7 +293,7 @@ public function __call(string $method, array $args): bool throw new MissingEnumConfigurationException([$alias]); } - if ($entity->isEmpty($config['field']) && Hash::get($config, 'allowEmpty') === true) { + if (!$entity->hasValue($config['field']) && Hash::get($config, 'allowEmpty') === true) { return true; } $value = $entity->{$config['field']}; diff --git a/tests/TestCase/Model/Behavior/EnumBehaviorTest.php b/tests/TestCase/Model/Behavior/EnumBehaviorTest.php index 960f72b..b121f2c 100644 --- a/tests/TestCase/Model/Behavior/EnumBehaviorTest.php +++ b/tests/TestCase/Model/Behavior/EnumBehaviorTest.php @@ -249,7 +249,7 @@ public static function provideBasicLookups(): array */ public function testBasicLookups($group, $expected) { - $result = $this->Articles->enum($group); + $result = $this->Articles->getBehavior('Enum')->enum($group); $this->assertEquals($expected, $result); } @@ -305,7 +305,7 @@ public function testBuildRules($data, $expected) public function testEnumNested() { $this->Articles->behaviors()->Enum->setConfig('nested', true); - $result = $this->Articles->enum('priority'); + $result = $this->Articles->getBehavior('Enum')->enum('priority'); $expected = [ ['value' => 'URGENT', 'text' => 'Urgent'], ['value' => 'HIGH', 'text' => 'High'], @@ -329,7 +329,7 @@ public function testAssociationsCreated() public function testEnumMultipleAlias() { - $result = $this->Articles->enum(); + $result = $this->Articles->getBehavior('Enum')->enum(); $expected = [ 'priority' => [ 'URGENT' => 'Urgent', @@ -366,10 +366,10 @@ public function testEnumMultipleAlias() ]; $this->assertEquals($expected, $result); - $result = $this->Articles->enum([]); + $result = $this->Articles->getBehavior('Enum')->enum([]); $this->assertEquals($expected, $result); - $result = $this->Articles->enum(['priority', 'status']); + $result = $this->Articles->getBehavior('Enum')->enum(['priority', 'status']); $expected = [ 'priority' => [ 'URGENT' => 'Urgent', @@ -388,11 +388,11 @@ public function testEnumMultipleAlias() public function testTranslatedValues() { $this->Articles->behaviors()->Enum->setConfig('translate', true); - $result = $this->Articles->enum('node_group'); + $result = $this->Articles->getBehavior('Enum')->enum('node_group'); $this->assertEquals(['active' => 'Translated Active'], $result); - $result = $this->Articles->enum(['node_group', 'norules']); + $result = $this->Articles->getBehavior('Enum')->enum(['node_group', 'norules']); $expected = [ 'node_group' => ['active' => 'Translated Active'], @@ -427,7 +427,7 @@ public function testThirdPartyStrategy(array $config, array $expected) $this->getTableLocator()->clear(); $Articles = $this->getTableLocator()->get('CakeDC/Enum.Articles', ['table' => 'enum_articles']); $Articles->addBehavior('CakeDC/Enum.Enum', $config); - $result = $Articles->enum('article_category'); + $result = $Articles->getBehavior('Enum')->enum('article_category'); $this->assertEquals($expected, $result); } }