Skip to content

Commit

Permalink
Add tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
robertpustulka committed Dec 1, 2017
1 parent 924338a commit 3978470
Showing 1 changed file with 109 additions and 0 deletions.
109 changes: 109 additions & 0 deletions tests/TestCase/Validation/ValidationSetTest.php
Expand Up @@ -19,6 +19,7 @@
use Cake\TestSuite\TestCase;
use Cake\Validation\ValidationRule;
use Cake\Validation\ValidationSet;
use PHPUnit\Framework\Error\Deprecated;

/**
* ValidationSetTest
Expand Down Expand Up @@ -208,4 +209,112 @@ public function testRemoveRule()
$set->remove('other');
$this->assertFalse(isset($set['other']));
}

/**
* Test requirePresence and isPresenceRequired methods
*
* @return void
*/
public function testRequirePresence()
{
$set = new ValidationSet();

$this->assertFalse($set->isPresenceRequired());

$set->requirePresence(true);
$this->assertTrue($set->isPresenceRequired());

$set->requirePresence(false);
$this->assertFalse($set->isPresenceRequired());
}

/**
* Test isPresenceRequired deprecated setter
*
* @group deprecated
* @return void
*/
public function testRequirePresenceDeprecated()
{
$this->deprecated(function () {
$set = new ValidationSet();

$this->assertFalse($set->isPresenceRequired());

$set->isPresenceRequired(true);
$this->assertTrue($set->isPresenceRequired());

$set->isPresenceRequired(false);
$this->assertFalse($set->isPresenceRequired());
});
}

/**
* Test isPresenceRequired method deprecation
*
* @group deprecated
* @return void
*/
public function testIsPresenceRequiredDeprecation()
{
$this->expectException(Deprecated::class);
$this->expectExceptionMessage('ValidationSet::isPresenceRequired() is deprecated as a setter. Use ValidationSet::requirePresence() instead.');

$set = new ValidationSet();
$set->isPresenceRequired(true);
}

/**
* Test allowEmpty and isEmptyAllowed methods
*
* @return void
*/
public function testAllowEmpty()
{
$set = new ValidationSet();

$this->assertFalse($set->isEmptyAllowed());

$set->allowEmpty(true);
$this->assertTrue($set->isEmptyAllowed());

$set->allowEmpty(false);
$this->assertFalse($set->isEmptyAllowed());
}

/**
* Test isEmptyAllowed deprecated setter
*
* @group deprecated
* @return void
*/
public function testAllowEmptyDeprecated()
{
$this->deprecated(function () {
$set = new ValidationSet();

$this->assertFalse($set->isEmptyAllowed());

$set->isEmptyAllowed(true);
$this->assertTrue($set->isEmptyAllowed());

$set->isEmptyAllowed(false);
$this->assertFalse($set->isEmptyAllowed());
});
}

/**
* Test isEmptyAllowed method deprecation
*
* @group deprecated
* @return void
*/
public function testIsEmptyAllowedDeprecation()
{
$this->expectException(Deprecated::class);
$this->expectExceptionMessage('ValidationSet::isEmptyAllowed() is deprecated as a setter. Use ValidationSet::allowEmpty() instead.');

$set = new ValidationSet();
$set->isEmptyAllowed(true);
}
}

0 comments on commit 3978470

Please sign in to comment.