Skip to content
Permalink
Browse files

Changed option name

  • Loading branch information...
james.byrne
james.byrne committed Apr 11, 2016
1 parent 0aced1a commit 7a59f209193aae8cda0149355466fc49ed11e082
Showing with 12 additions and 8 deletions.
  1. +6 −2 src/ORM/Rule/IsUnique.php
  2. +6 −6 tests/TestCase/ORM/RulesCheckerIntegrationTest.php
@@ -53,7 +53,11 @@ public function __invoke(EntityInterface $entity, array $options)
return true;
}
$checkNull = isset($options['checkNull']) ? true : false;
$permitMultipleNulls = true;
if(isset($options['permitMultipleNulls'])) {
$permitMultipleNulls = $options['permitMultipleNulls'] === true ? true : false;
}
$alias = $options['repository']->alias();
$conditions = $this->_alias($alias, $entity->extract($this->_fields));
if ($entity->isNew() === false) {
@@ -64,7 +68,7 @@ public function __invoke(EntityInterface $entity, array $options)
}
}
if ($checkNull) {
if ($permitMultipleNulls) {
foreach ($conditions as $key => $value) {
if ($value === null) {
$conditions[$key . ' IS'] = $value;
@@ -370,20 +370,20 @@ public function testIsUniqueMultipleFields()
}
/**
* Tests isUnique with checkNull
* Tests isUnique with permitMultipleNulls
*
* @group save
* @return void
*/
public function testIsUniqueCheckNull()
public function testIsUniquePermitMultipleNulls()
{
$entity = new Entity([
'log_id' => null
]);
$table = TableRegistry::get('Logs');
$rules = $table->rulesChecker();
$rules->add($rules->isUnique(['log_id']), ['checkNull' => true]);
$rules->add($rules->isUnique(['log_id']), ['permitMultipleNulls' => true]);
$this->assertFalse($table->save($entity));
$this->assertEquals(['_isUnique' => 'This value is already in use'], $entity->errors('log_id'));
@@ -397,12 +397,12 @@ public function testIsUniqueCheckNull()
}
/**
* Tests isUnique with multiple fields and checkNull
* Tests isUnique with multiple fields and permitMultipleNulls
*
* @group save
* @return void
*/
public function testIsUniqueMultipleFieldsCheckNull()
public function testIsUniqueMultipleFieldsPermitMultipleNulls()
{
$entity = new Entity([
'log_id' => 3,
@@ -411,7 +411,7 @@ public function testIsUniqueMultipleFieldsCheckNull()
$table = TableRegistry::get('Logs');
$rules = $table->rulesChecker();
$rules->add($rules->isUnique(['log_id', 'type'], 'Nope'), ['checkNull' => true]);
$rules->add($rules->isUnique(['log_id', 'type'], 'Nope'), ['permitMultipleNulls' => true]);
$this->assertFalse($table->save($entity));
$this->assertEquals(['log_id' => ['_isUnique' => 'Nope']], $entity->errors());

0 comments on commit 7a59f20

Please sign in to comment.
You can’t perform that action at this time.