Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
8 changes: 4 additions & 4 deletions src/Model/Behavior/EnumBehavior.php
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -267,7 +267,7 @@ public function buildRules(EventInterface $event, RulesChecker $rules): RulesChe
]);
}

return $rules;
$event->setResult($rules);
}

/**
Expand All @@ -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']};
Expand Down
16 changes: 8 additions & 8 deletions tests/TestCase/Model/Behavior/EnumBehaviorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down Expand Up @@ -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'],
Expand All @@ -329,7 +329,7 @@ public function testAssociationsCreated()

public function testEnumMultipleAlias()
{
$result = $this->Articles->enum();
$result = $this->Articles->getBehavior('Enum')->enum();
$expected = [
'priority' => [
'URGENT' => 'Urgent',
Expand Down Expand Up @@ -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',
Expand All @@ -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'],
Expand Down Expand Up @@ -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);
}
}
Loading