Skip to content
Permalink
Browse files

Rename methods so tests are easier to understand.

myTestRule and myTestRule2 were not easily grokkable.
  • Loading branch information...
markstory committed Sep 26, 2015
1 parent 57b718a commit e49ff5193640e2b1d9c7cf45903088429a905a1e
Showing with 17 additions and 17 deletions.
  1. +17 −17 tests/TestCase/Validation/ValidationRuleTest.php
@@ -29,7 +29,7 @@ class ValidationRuleTest extends TestCase
*
* @return bool
*/
public function myTestRule()
public function willFail()
{
return false;
}
@@ -39,7 +39,7 @@ public function myTestRule()
*
* @return bool
*/
public function myTestRule2()
public function willPass()
{
return true;
}
@@ -49,7 +49,7 @@ public function myTestRule2()
*
* @return string
*/
public function myTestRule3()
public function willFail3()
{
return 'string';
}
@@ -65,16 +65,16 @@ public function testCustomMethods()
$providers = ['default' => $this];
$context = ['newRecord' => true];
$Rule = new ValidationRule(['rule' => 'myTestRule']);
$Rule = new ValidationRule(['rule' => 'willFail']);
$this->assertFalse($Rule->process($data, $providers, $context));
$Rule = new ValidationRule(['rule' => 'myTestRule2']);
$Rule = new ValidationRule(['rule' => 'willPass']);
$this->assertTrue($Rule->process($data, $providers, $context));
$Rule = new ValidationRule(['rule' => 'myTestRule3']);
$Rule = new ValidationRule(['rule' => 'willFail3']);
$this->assertEquals('string', $Rule->process($data, $providers, $context));
$Rule = new ValidationRule(['rule' => 'myTestRule', 'message' => 'foo']);
$Rule = new ValidationRule(['rule' => 'willFail', 'message' => 'foo']);
$this->assertEquals('foo', $Rule->process($data, $providers, $context));
}
@@ -90,7 +90,7 @@ public function testCustomMethodNoProvider()
$providers = ['default' => ''];
$rule = new ValidationRule([
'rule' => [$this, 'myTestRule']
'rule' => [$this, 'willFail']
]);
$this->assertFalse($rule->process($data, $providers, $context));
}
@@ -123,19 +123,19 @@ public function testSkip()
$providers = ['default' => $this];
$Rule = new ValidationRule([
'rule' => 'myTestRule',
'rule' => 'willFail',
'on' => 'create'
]);
$this->assertFalse($Rule->process($data, $providers, ['newRecord' => true]));
$Rule = new ValidationRule([
'rule' => 'myTestRule',
'rule' => 'willFail',
'on' => 'update'
]);
$this->assertTrue($Rule->process($data, $providers, ['newRecord' => true]));
$Rule = new ValidationRule([
'rule' => 'myTestRule',
'rule' => 'willFail',
'on' => 'update'
]);
$this->assertFalse($Rule->process($data, $providers, ['newRecord' => false]));
@@ -152,7 +152,7 @@ public function testCallableOn()
$providers = ['default' => $this];
$Rule = new ValidationRule([
'rule' => 'myTestRule',
'rule' => 'willFail',
'on' => function ($context) use ($providers) {
$expected = compact('providers') + ['newRecord' => true, 'data' => []];
$this->assertEquals($expected, $context);
@@ -162,7 +162,7 @@ public function testCallableOn()
$this->assertFalse($Rule->process($data, $providers, ['newRecord' => true]));
$Rule = new ValidationRule([
'rule' => 'myTestRule',
'rule' => 'willFail',
'on' => function ($context) use ($providers) {
$expected = compact('providers') + ['newRecord' => true, 'data' => []];
$this->assertEquals($expected, $context);
@@ -179,17 +179,17 @@ public function testCallableOn()
*/
public function testGet()
{
$Rule = new ValidationRule(['rule' => 'myTestRule', 'message' => 'foo']);
$Rule = new ValidationRule(['rule' => 'willFail', 'message' => 'foo']);
$this->assertEquals('myTestRule', $Rule->get('rule'));
$this->assertEquals('willFail', $Rule->get('rule'));
$this->assertEquals('foo', $Rule->get('message'));
$this->assertEquals('default', $Rule->get('provider'));
$this->assertEquals([], $Rule->get('pass'));
$this->assertNull($Rule->get('non-existent'));
$Rule = new ValidationRule(['rule' => ['myTestRule2', 'param'], 'message' => 'bar']);
$Rule = new ValidationRule(['rule' => ['willPass', 'param'], 'message' => 'bar']);
$this->assertEquals('myTestRule2', $Rule->get('rule'));
$this->assertEquals('willPass', $Rule->get('rule'));
$this->assertEquals('bar', $Rule->get('message'));
$this->assertEquals(['param'], $Rule->get('pass'));
}

0 comments on commit e49ff51

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