Skip to content

Commit

Permalink
Removing the count validation from the table object
Browse files Browse the repository at this point in the history
It's now in a rule.
  • Loading branch information
Florian Krämer committed Apr 27, 2016
1 parent 1d2312e commit ed33770
Show file tree
Hide file tree
Showing 2 changed files with 0 additions and 42 deletions.
24 changes: 0 additions & 24 deletions src/ORM/Table.php
Expand Up @@ -2305,28 +2305,4 @@ public function __debugInfo()
'connectionName' => $conn ? $conn->configName() : null
];
}

/**
* Validates that a belongsToMany or hasMany assoc has at least one entry.
*
* This can be used to validate any other array as well.
*
* @param mixed $value
* @return boolean
*/
public function validateCount($value, $expectedCount = 0, $operator = '>')
{
if (!is_array($value)) {
return false;
}
if (isset($value['_ids'])) {
if (!is_array($value['_ids'])) {
return false;
}
$count = count($value['_ids']);
} else {
$count = count($value);
}
return Validation::comparison($count, $operator, $expectedCount);
}
}
18 changes: 0 additions & 18 deletions tests/TestCase/ORM/TableTest.php
Expand Up @@ -5860,22 +5860,4 @@ public function skipIfSqlServer()
);
}

/**
* Test that an association has at least one entry present.
*
* @return void
*/
public function testValidateCount()
{
$table = TableRegistry::get('Authors');
$this->assertFalse($table->validateCount(''));
$this->assertFalse($table->validateCount([]));
$this->assertFalse($table->validateCount(['_ids' => '']));
$this->assertFalse($table->validateCount(['_ids' => []]));

$this->assertFalse($table->validateCount(['_ids' => [1, 2, 3]], 4, '='));
$this->assertTrue($table->validateCount(['_ids' => [1, 2, 3]], 4, '<='));

$this->assertTrue($table->validateCount(['_ids' => [1, 2, 3]]));
}
}

0 comments on commit ed33770

Please sign in to comment.