Skip to content
Permalink
Browse files

rename allowPartialNulls to allowNullableNulls

  • Loading branch information...
Jonas
Jonas committed Jul 10, 2016
1 parent 230e06f commit e91858d0ff2f7e39b87a5213ef84167dee958123
Showing with 42 additions and 42 deletions.
  1. +3 −3 src/ORM/Rule/ExistsIn.php
  2. +2 −2 src/ORM/RulesChecker.php
  3. +37 −37 tests/TestCase/ORM/RulesCheckerIntegrationTest.php
@@ -49,7 +49,7 @@ class ExistsIn
/**
* Constructor.
*
* Available option for $options is 'allowPartialNulls' flag.
* Available option for $options is 'allowNullableNulls' flag.
* Set to true to accept composite foreign keys where one or more nullable columns are null.
*
* @param string|array $fields The field or fields to check existence as primary key.
@@ -59,7 +59,7 @@ class ExistsIn
*/
public function __construct($fields, $repository, array $options = [])
{
$options += ['allowPartialNulls' => false];
$options += ['allowNullableNulls' => false];
$this->_options = $options;
$this->_fields = (array)$fields;
@@ -114,7 +114,7 @@ public function __invoke(EntityInterface $entity, array $options)
return true;
}
if ($this->_options['allowPartialNulls']) {
if ($this->_options['allowNullableNulls']) {
$schema = $source->schema();
foreach ($this->_fields as $i => $field) {
if ($schema->column($field) && $schema->isNullable($field) && $entity->get($field) === null) {
@@ -71,9 +71,9 @@ public function isUnique(array $fields, $message = null)
* $rules->add($rules->existsIn('site_id', new SitesTable(), 'Invalid Site'));
* ```
*
* Available $options are error 'message' and 'allowPartialNulls' flag.
* Available $options are error 'message' and 'allowNullableNulls' flag.
* 'message' sets a custom error message.
* Set 'allowPartialNulls' to true to accept composite foreign keys where one or more nullable columns are null.
* Set 'allowNullableNulls' to true to accept composite foreign keys where one or more nullable columns are null.
*
* @param string|array $field The field or list of fields to check for existence by
* primary key lookup in the other table.
@@ -828,11 +828,11 @@ public function testExistsInErrorWithArrayField()
}
/**
* Tests new allowPartialNulls flag with author id set to null
* Tests new allowNullableNulls flag with author id set to null
*
* @return
*/
public function testExistsInAllowPartialNullsWithAuthorIdNullA()
public function testExistsInAllowNullableNullsWithAuthorIdNullA()
{
$entity = new Entity([
'id' => 10,
@@ -845,17 +845,17 @@ public function testExistsInAllowPartialNullsWithAuthorIdNullA()
$rules = $table->rulesChecker();
$rules->add($rules->existsIn(['author_id', 'site_id'], 'SiteAuthors', [
'allowPartialNulls' => true
'allowNullableNulls' => true
]));
$this->assertInstanceOf('Cake\ORM\Entity', $table->save($entity));
}
/**
* Tests new allowPartialNulls flag with author id set to null
* Tests new allowNullableNulls flag with author id set to null
*
* @return
*/
public function testExistsInAllowPartialNullsWithAuthorIdNullB()
public function testExistsInAllowNullableNullsWithAuthorIdNullB()
{
$entity = new Entity([
'id' => 10,
@@ -868,17 +868,17 @@ public function testExistsInAllowPartialNullsWithAuthorIdNullB()
$rules = $table->rulesChecker();
$rules->add($rules->existsIn(['author_id', 'site_id'], 'SiteAuthors', [
'allowPartialNulls' => false
'allowNullableNulls' => false
]));
$this->assertFalse($table->save($entity));
}
/**
* Tests new allowPartialNulls flag with author id set to null
* Tests new allowNullableNulls flag with author id set to null
*
* @return
*/
public function testExistsInAllowPartialNullsWithAuthorIdNullC()
public function testExistsInAllowNullableNullsWithAuthorIdNullC()
{
$entity = new Entity([
'id' => 10,
@@ -895,11 +895,11 @@ public function testExistsInAllowPartialNullsWithAuthorIdNullC()
}
/**
* Tests new allowPartialNulls flag with author id set to null
* Tests new allowNullableNulls flag with author id set to null
*
* @return
*/
public function testExistsInAllowPartialNullsWithAuthorIdNullD()
public function testExistsInAllowNullableNullsWithAuthorIdNullD()
{
$entity = new Entity([
'id' => 10,
@@ -912,19 +912,19 @@ public function testExistsInAllowPartialNullsWithAuthorIdNullD()
$rules = $table->rulesChecker();
$rules->add($rules->existsIn(['author_id', 'site_id'], 'SiteAuthors', [
'allowPartialNulls' => false,
'allowNullableNulls' => false,
'message' => 'Niente'
]));
$this->assertFalse($table->save($entity));
$this->assertEquals(['author_id' => ['_existsIn' => 'Niente']], $entity->errors());
}
/**
* Tests new allowPartialNulls flag with author id set to null
* Tests new allowNullableNulls flag with author id set to null
*
* @return
*/
public function testExistsInAllowPartialNullsWithAuthorIdNullE()
public function testExistsInAllowNullableNullsWithAuthorIdNullE()
{
$entity = new Entity([
'id' => 10,
@@ -937,18 +937,18 @@ public function testExistsInAllowPartialNullsWithAuthorIdNullE()
$rules = $table->rulesChecker();
$rules->add($rules->existsIn(['author_id', 'site_id'], 'SiteAuthors', [
'allowPartialNulls' => true,
'allowNullableNulls' => true,
'message' => 'Niente'
]));
$this->assertInstanceOf('Cake\ORM\Entity', $table->save($entity));
}
/**
* Tests new allowPartialNulls flag with author id set to 1
* Tests new allowNullableNulls flag with author id set to 1
*
* @return
*/
public function testExistsInAllowPartialNullsWithAuthorId1A()
public function testExistsInAllowNullableNullsWithAuthorId1A()
{
$entity = new Entity([
'id' => 10,
@@ -960,16 +960,16 @@ public function testExistsInAllowPartialNullsWithAuthorId1A()
$table->belongsTo('SiteAuthors');
$rules = $table->rulesChecker();
$rules->add($rules->existsIn(['author_id', 'site_id'], 'SiteAuthors', ['allowPartialNulls' => true]));
$rules->add($rules->existsIn(['author_id', 'site_id'], 'SiteAuthors', ['allowNullableNulls' => true]));
$this->assertInstanceOf('Cake\ORM\Entity', $table->save($entity));
}
/**
* Tests new allowPartialNulls flag with author id set to 1
* Tests new allowNullableNulls flag with author id set to 1
*
* @return
*/
public function testExistsInAllowPartialNullsWithAuthorIdB()
public function testExistsInAllowNullableNullsWithAuthorIdB()
{
$entity = new Entity([
'id' => 10,
@@ -981,16 +981,16 @@ public function testExistsInAllowPartialNullsWithAuthorIdB()
$table->belongsTo('SiteAuthors');
$rules = $table->rulesChecker();
$rules->add($rules->existsIn(['author_id', 'site_id'], 'SiteAuthors', ['allowPartialNulls' => false]));
$rules->add($rules->existsIn(['author_id', 'site_id'], 'SiteAuthors', ['allowNullableNulls' => false]));
$this->assertInstanceOf('Cake\ORM\Entity', $table->save($entity));
}
/**
* Tests new allowPartialNulls flag with author id set to 1
* Tests new allowNullableNulls flag with author id set to 1
*
* @return
*/
public function testExistsInAllowPartialNullsWithAuthorId1C()
public function testExistsInAllowNullableNullsWithAuthorId1C()
{
$entity = new Entity([
'id' => 10,
@@ -1007,11 +1007,11 @@ public function testExistsInAllowPartialNullsWithAuthorId1C()
}
/**
* Tests new allowPartialNulls flag with author id set to 1
* Tests new allowNullableNulls flag with author id set to 1
*
* @return
*/
public function testExistsInAllowPartialNullsWithAuthorId1E()
public function testExistsInAllowNullableNullsWithAuthorId1E()
{
$entity = new Entity([
'id' => 10,
@@ -1024,17 +1024,17 @@ public function testExistsInAllowPartialNullsWithAuthorId1E()
$rules = $table->rulesChecker();
$rules->add($rules->existsIn(['author_id', 'site_id'], 'SiteAuthors', [
'allowPartialNulls' => true,
'allowNullableNulls' => true,
'message' => 'will not error']));
$this->assertInstanceOf('Cake\ORM\Entity', $table->save($entity));
}
/**
* Tests new allowPartialNulls flag with author id set to 1
* Tests new allowNullableNulls flag with author id set to 1
*
* @return
*/
public function testExistsInAllowPartialNullsWithAuthorId1F()
public function testExistsInAllowNullableNullsWithAuthorId1F()
{
$entity = new Entity([
'id' => 10,
@@ -1047,17 +1047,17 @@ public function testExistsInAllowPartialNullsWithAuthorId1F()
$rules = $table->rulesChecker();
$rules->add($rules->existsIn(['author_id', 'site_id'], 'SiteAuthors', [
'allowPartialNulls' => false,
'allowNullableNulls' => false,
'message' => 'will not error']));
$this->assertInstanceOf('Cake\ORM\Entity', $table->save($entity));
}
/**
* Tests new allowPartialNulls flag with author id set to 99999999 (does not exist)
* Tests new allowNullableNulls flag with author id set to 99999999 (does not exist)
*
* @return
*/
public function testExistsInAllowPartialNullsWithAuthorId1G()
public function testExistsInAllowNullableNullsWithAuthorId1G()
{
$entity = new Entity([
'id' => 10,
@@ -1070,19 +1070,19 @@ public function testExistsInAllowPartialNullsWithAuthorId1G()
$rules = $table->rulesChecker();
$rules->add($rules->existsIn(['author_id', 'site_id'], 'SiteAuthors', [
'allowPartialNulls' => true,
'allowNullableNulls' => true,
'message' => 'will error']));
$this->assertFalse($table->save($entity));
$this->assertEquals(['author_id' => ['_existsIn' => 'will error']], $entity->errors());
}
/**
* Tests new allowPartialNulls flag with author id set to 99999999 (does not exist)
* Tests new allowNullableNulls flag with author id set to 99999999 (does not exist)
* and site_id set to 99999999 (does not exist)
*
* @return
*/
public function testExistsInAllowPartialNullsWithAuthorId1H()
public function testExistsInAllowNullableNullsWithAuthorId1H()
{
$entity = new Entity([
'id' => 10,
@@ -1095,19 +1095,19 @@ public function testExistsInAllowPartialNullsWithAuthorId1H()
$rules = $table->rulesChecker();
$rules->add($rules->existsIn(['author_id', 'site_id'], 'SiteAuthors', [
'allowPartialNulls' => true,
'allowNullableNulls' => true,
'message' => 'will error']));
$this->assertFalse($table->save($entity));
$this->assertEquals(['author_id' => ['_existsIn' => 'will error']], $entity->errors());
}
/**
* Tests new allowPartialNulls flag with author id set to 1 (does exist)
* Tests new allowNullableNulls flag with author id set to 1 (does exist)
* and site_id set to 99999999 (does not exist)
*
* @return
*/
public function testExistsInAllowPartialNullsWithAuthorId1I()
public function testExistsInAllowNullableNullsWithAuthorId1I()
{
$entity = new Entity([
'id' => 10,
@@ -1120,7 +1120,7 @@ public function testExistsInAllowPartialNullsWithAuthorId1I()
$rules = $table->rulesChecker();
$rules->add($rules->existsIn(['author_id', 'site_id'], 'SiteAuthors', [
'allowPartialNulls' => true,
'allowNullableNulls' => true,
'message' => 'will error']));
$this->assertFalse($table->save($entity));
$this->assertEquals(['author_id' => ['_existsIn' => 'will error']], $entity->errors());

0 comments on commit e91858d

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