Skip to content

Commit

Permalink
Rename methods so tests are easier to understand.
Browse files Browse the repository at this point in the history
myTestRule and myTestRule2 were not easily grokkable.
  • Loading branch information
markstory committed Sep 26, 2015
1 parent 57b718a commit e49ff51
Showing 1 changed file with 17 additions and 17 deletions.
34 changes: 17 additions & 17 deletions tests/TestCase/Validation/ValidationRuleTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ class ValidationRuleTest extends TestCase
*
* @return bool
*/
public function myTestRule()
public function willFail()
{
return false;
}
Expand All @@ -39,7 +39,7 @@ public function myTestRule()
*
* @return bool
*/
public function myTestRule2()
public function willPass()
{
return true;
}
Expand All @@ -49,7 +49,7 @@ public function myTestRule2()
*
* @return string
*/
public function myTestRule3()
public function willFail3()
{
return 'string';
}
Expand All @@ -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));
}

Expand All @@ -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));
}
Expand Down Expand Up @@ -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]));
Expand All @@ -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);
Expand All @@ -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);
Expand All @@ -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'));
}
Expand Down

0 comments on commit e49ff51

Please sign in to comment.