Skip to content

Commit

Permalink
rename allowPartialNulls to allowNullableNulls
Browse files Browse the repository at this point in the history
  • Loading branch information
Jonas committed Jul 10, 2016
1 parent 230e06f commit e91858d
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 42 deletions.
6 changes: 3 additions & 3 deletions src/ORM/Rule/ExistsIn.php
Expand Up @@ -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.
Expand All @@ -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;
Expand Down Expand Up @@ -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) {
Expand Down
4 changes: 2 additions & 2 deletions src/ORM/RulesChecker.php
Expand Up @@ -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.
Expand Down
74 changes: 37 additions & 37 deletions tests/TestCase/ORM/RulesCheckerIntegrationTest.php
Expand Up @@ -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,
Expand All @@ -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,
Expand All @@ -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,
Expand All @@ -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,
Expand All @@ -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,
Expand All @@ -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,
Expand All @@ -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,
Expand All @@ -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,
Expand All @@ -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,
Expand All @@ -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,
Expand All @@ -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,
Expand All @@ -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,
Expand All @@ -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,
Expand All @@ -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());
Expand Down

0 comments on commit e91858d

Please sign in to comment.