Improve RuleTestCase class

- Add documentation to the class and its methods;
- Move RuleTestCase to Test namespace;
- Use PHP 7 type hinting;
- Rename getRuleMock() to createValidatableMock().
This commit is contained in:
Henrique Moody 2018-01-07 14:12:55 +01:00
parent 2d7e2ea48f
commit fe3654b270
No known key found for this signature in database
GPG key ID: 221E9281655813A6
30 changed files with 186 additions and 111 deletions

View file

@ -41,7 +41,7 @@
},
"autoload-dev": {
"psr-4": {
"Respect\\Validation\\": "tests/library/"
"Respect\\Validation\\Test\\": "tests/library/"
}
},
"extra": {

View file

@ -11,35 +11,59 @@
declare(strict_types=1);
namespace Respect\Validation\Rules;
namespace Respect\Validation\Test;
use PHPUnit\Framework\TestCase;
use Respect\Validation\Exceptions\ValidationException;
use Respect\Validation\Validatable;
/**
* Abstract class to create TestCases for Rules.
*
* @author Antonio Spinelli <tonicospinelli85@gmail.com>
* @author Henrique Moody <henriquemoody@gmail.com>
*
* @since 1.0.0
*/
abstract class RuleTestCase extends TestCase
{
/**
* It is to provide constructor arguments and.
* Data providers for valid results.
*
* @return array
* It returns an array of arrays. Each array contains an instance of Validatable
* as the first element and an input in which the validation SHOULD pass.
*
* @api
*
* @return array[]
*/
abstract public function providerForValidInput();
abstract public function providerForValidInput(): array;
/**
* @return array
* Data providers for invalid results.
*
* It returns an array of arrays. Each array contains an instance of Validatable
* as the first element and an input in which the validation SHOULD NOT pass.
*
* @api
*
* @return array[]
*/
abstract public function providerForInvalidInput();
abstract public function providerForInvalidInput(): array;
/**
* Create a mock of a Validatable.
*
* @api
*
* @param bool $expectedResult
* @param string[optional] $mockClassName
*
* @return Validatable
*/
public function getRuleMock($expectedResult, $mockClassName = '')
public function createValidatableMock(bool $expectedResult, string $mockClassName = ''): Validatable
{
$ruleMocked = $this->getMockBuilder(Validatable::class)
$validatableMocked = $this->getMockBuilder(Validatable::class)
->disableOriginalConstructor()
->setMethods(
[
@ -49,52 +73,56 @@ abstract class RuleTestCase extends TestCase
->setMockClassName($mockClassName)
->getMock();
$ruleMocked
$validatableMocked
->expects($this->any())
->method('validate')
->willReturn($expectedResult);
if ($expectedResult) {
$ruleMocked
$validatableMocked
->expects($this->any())
->method('check')
->willReturn($expectedResult);
$ruleMocked
$validatableMocked
->expects($this->any())
->method('assert')
->willReturn($expectedResult);
} else {
$ruleMocked
$validatableMocked
->expects($this->any())
->method('check')
->willThrowException(new ValidationException('Exception for '.$mockClassName.':check() method'));
$ruleMocked
$validatableMocked
->expects($this->any())
->method('assert')
->willThrowException(new ValidationException('Exception for '.$mockClassName.':assert() method'));
}
return $ruleMocked;
return $validatableMocked;
}
/**
* @test
*
* @dataProvider providerForValidInput
*
* @param Validatable $validator
* @param mixed $input
*/
public function testShouldValidateValidInput(Validatable $validator, $input): void
public function shouldValidateValidInput(Validatable $validator, $input): void
{
self::assertTrue($validator->validate($input));
}
/**
* @test
*
* @dataProvider providerForInvalidInput
*
* @param Validatable $validator
* @param mixed $input
*/
public function testShouldValidateInvalidInput(Validatable $validator, $input): void
public function shouldValidateInvalidInput(Validatable $validator, $input): void
{
self::assertFalse($validator->validate($input));
}

View file

@ -13,13 +13,16 @@ declare(strict_types=1);
namespace Respect\Validation\Rules;
use Respect\Validation\Test\RuleTestCase;
/**
* @group rule
* @covers \Respect\Validation\Rules\ArrayType
*/
class ArrayTypeTest extends RuleTestCase
{
public function providerForValidInput()
public function providerForValidInput(): array
{
$rule = new ArrayType();
@ -29,7 +32,7 @@ class ArrayTypeTest extends RuleTestCase
];
}
public function providerForInvalidInput()
public function providerForInvalidInput(): array
{
$rule = new ArrayType();

View file

@ -14,6 +14,7 @@ declare(strict_types=1);
namespace Respect\Validation\Rules;
use ArrayObject;
use Respect\Validation\Test\RuleTestCase;
use SimpleXMLElement;
use stdClass;
@ -23,7 +24,7 @@ use stdClass;
*/
class ArrayValTest extends RuleTestCase
{
public function providerForValidInput()
public function providerForValidInput(): array
{
$rule = new ArrayVal();
@ -35,7 +36,7 @@ class ArrayValTest extends RuleTestCase
];
}
public function providerForInvalidInput()
public function providerForInvalidInput(): array
{
$rule = new ArrayVal();

View file

@ -13,13 +13,15 @@ declare(strict_types=1);
namespace Respect\Validation\Rules;
use Respect\Validation\Test\RuleTestCase;
/**
* @group rule
* @covers \Respect\Validation\Rules\Base64
*/
class Base64Test extends RuleTestCase
{
public function providerForValidInput()
public function providerForValidInput(): array
{
$rule = new Base64();
@ -48,7 +50,7 @@ class Base64Test extends RuleTestCase
];
}
public function providerForInvalidInput()
public function providerForInvalidInput(): array
{
$rule = new Base64();

View file

@ -13,13 +13,15 @@ declare(strict_types=1);
namespace Respect\Validation\Rules;
use Respect\Validation\Test\RuleTestCase;
/**
* @group rule
* @covers \Respect\Validation\Rules\BoolVal
*/
class BoolValTest extends RuleTestCase
{
public function providerForValidInput()
public function providerForValidInput(): array
{
$rule = new BoolVal();
@ -36,7 +38,7 @@ class BoolValTest extends RuleTestCase
];
}
public function providerForInvalidInput()
public function providerForInvalidInput(): array
{
$rule = new BoolVal();

View file

@ -13,13 +13,15 @@ declare(strict_types=1);
namespace Respect\Validation\Rules;
use Respect\Validation\Test\RuleTestCase;
/**
* @group rule
* @covers \Respect\Validation\Rules\Countable
*/
class CountableTest extends RuleTestCase
{
public function providerForValidInput()
public function providerForValidInput(): array
{
$rule = new Countable();
@ -30,7 +32,7 @@ class CountableTest extends RuleTestCase
];
}
public function providerForInvalidInput()
public function providerForInvalidInput(): array
{
$rule = new Countable();

View file

@ -14,6 +14,7 @@ declare(strict_types=1);
namespace Respect\Validation\Rules;
use Respect\Validation\Exceptions\ComponentException;
use Respect\Validation\Test\RuleTestCase;
/**
* @group rule
@ -45,7 +46,7 @@ class CreditCardTest extends RuleTestCase
new CreditCard('RespectCard');
}
public function providerForValidInput()
public function providerForValidInput(): array
{
$general = new CreditCard();
$amex = new CreditCard(CreditCard::AMERICAN_EXPRESS);
@ -75,7 +76,7 @@ class CreditCardTest extends RuleTestCase
];
}
public function providerForInvalidInput()
public function providerForInvalidInput(): array
{
$general = new CreditCard();
$amex = new CreditCard(CreditCard::AMERICAN_EXPRESS);

View file

@ -13,13 +13,15 @@ declare(strict_types=1);
namespace Respect\Validation\Rules;
use Respect\Validation\Test\RuleTestCase;
/**
* @group rule
* @covers \Respect\Validation\Rules\CurrencyCode
*/
class CurrencyCodeTest extends RuleTestCase
{
public function providerForValidInput()
public function providerForValidInput(): array
{
$rule = new CurrencyCode();
@ -32,7 +34,7 @@ class CurrencyCodeTest extends RuleTestCase
];
}
public function providerForInvalidInput()
public function providerForInvalidInput(): array
{
$rule = new CurrencyCode();

View file

@ -13,6 +13,8 @@ declare(strict_types=1);
namespace Respect\Validation\Rules;
use Respect\Validation\Test\RuleTestCase;
/**
* @group rule
* @covers \Respect\Validation\Rules\Each
@ -20,11 +22,11 @@ namespace Respect\Validation\Rules;
*/
class EachTest extends RuleTestCase
{
public function providerForValidInput()
public function providerForValidInput(): array
{
$ruleNotEmpty = new Each($this->getRuleMock(true));
$ruleAlphaItemIntKey = new Each($this->getRuleMock(true), $this->getRuleMock(true));
$ruleOnlyKeyValidation = new Each(null, $this->getRuleMock(true));
$ruleNotEmpty = new Each($this->createValidatableMock(true));
$ruleAlphaItemIntKey = new Each($this->createValidatableMock(true), $this->createValidatableMock(true));
$ruleOnlyKeyValidation = new Each(null, $this->createValidatableMock(true));
$intStack = new \SplStack();
$intStack->push(1);
@ -46,10 +48,10 @@ class EachTest extends RuleTestCase
];
}
public function providerForInvalidInput()
public function providerForInvalidInput(): array
{
$rule = new Each($this->getRuleMock(false));
$ruleOnlyKeyValidation = new Each(null, $this->getRuleMock(false));
$rule = new Each($this->createValidatableMock(false));
$ruleOnlyKeyValidation = new Each(null, $this->createValidatableMock(false));
return [
[$rule, 123],
@ -63,7 +65,7 @@ class EachTest extends RuleTestCase
public function testValidatorShouldPassIfEveryArrayItemPass(): void
{
$v = new Each($this->getRuleMock(true));
$v = new Each($this->createValidatableMock(true));
$result = $v->check([1, 2, 3, 4, 5]);
self::assertTrue($result);
$result = $v->assert([1, 2, 3, 4, 5]);
@ -72,7 +74,7 @@ class EachTest extends RuleTestCase
public function testValidatorShouldPassIfEveryArrayItemAndKeyPass(): void
{
$v = new Each($this->getRuleMock(true), $this->getRuleMock(true));
$v = new Each($this->createValidatableMock(true), $this->createValidatableMock(true));
$result = $v->check(['a', 'b', 'c', 'd', 'e']);
self::assertTrue($result);
$result = $v->assert(['a', 'b', 'c', 'd', 'e']);
@ -81,7 +83,7 @@ class EachTest extends RuleTestCase
public function testValidatorShouldPassWithOnlyKeyValidation(): void
{
$v = new Each(null, $this->getRuleMock(true));
$v = new Each(null, $this->createValidatableMock(true));
$result = $v->check(['a', 'b', 'c', 'd', 'e']);
self::assertTrue($result);
$result = $v->assert(['a', 'b', 'c', 'd', 'e']);
@ -93,7 +95,7 @@ class EachTest extends RuleTestCase
*/
public function testValidatorShouldNotPassWithOnlyKeyValidation(): void
{
$v = new Each(null, $this->getRuleMock(false));
$v = new Each(null, $this->createValidatableMock(false));
$v->assert(['a', 'b', 'c', 'd', 'e']);
}
@ -102,7 +104,7 @@ class EachTest extends RuleTestCase
*/
public function testAssertShouldFailOnInvalidItem(): void
{
$v = new Each($this->getRuleMock(false));
$v = new Each($this->createValidatableMock(false));
$v->assert(['a', 2, 3, 4, 5]);
}
@ -111,7 +113,7 @@ class EachTest extends RuleTestCase
*/
public function testAssertShouldFailWithNonIterableInput(): void
{
$v = new Each($this->getRuleMock(false));
$v = new Each($this->createValidatableMock(false));
$v->assert('a');
}
@ -120,7 +122,7 @@ class EachTest extends RuleTestCase
*/
public function testCheckShouldFailWithNonIterableInput(): void
{
$v = new Each($this->getRuleMock(false));
$v = new Each($this->createValidatableMock(false));
$v->check(null);
}
}

View file

@ -13,13 +13,15 @@ declare(strict_types=1);
namespace Respect\Validation\Rules;
use Respect\Validation\Test\RuleTestCase;
/**
* @group rule
* @covers \Respect\Validation\Rules\Fibonacci
*/
class FibonacciTest extends RuleTestCase
{
public function providerForValidInput()
public function providerForValidInput(): array
{
$rule = new Fibonacci();
@ -40,7 +42,7 @@ class FibonacciTest extends RuleTestCase
];
}
public function providerForInvalidInput()
public function providerForInvalidInput(): array
{
$rule = new Fibonacci();

View file

@ -13,13 +13,15 @@ declare(strict_types=1);
namespace Respect\Validation\Rules;
use Respect\Validation\Test\RuleTestCase;
/**
* @group rule
* @covers \Respect\Validation\Rules\FloatType
*/
class FloatTypeTest extends RuleTestCase
{
public function providerForValidInput()
public function providerForValidInput(): array
{
$rule = new FloatType();
@ -34,7 +36,7 @@ class FloatTypeTest extends RuleTestCase
];
}
public function providerForInvalidInput()
public function providerForInvalidInput(): array
{
$rule = new FloatType();

View file

@ -14,6 +14,7 @@ declare(strict_types=1);
namespace Respect\Validation\Rules;
use finfo;
use Respect\Validation\Test\RuleTestCase;
use SplFileInfo;
use SplFileObject;
@ -38,7 +39,7 @@ class ImageTest extends RuleTestCase
self::assertInstanceOf('finfo', $rule->fileInfo);
}
public function providerForValidInput()
public function providerForValidInput(): array
{
$rule = new Image();
$fixturesDirectory = realpath(__DIR__.'/../../fixtures/');
@ -53,7 +54,7 @@ class ImageTest extends RuleTestCase
];
}
public function providerForInvalidInput()
public function providerForInvalidInput(): array
{
$rule = new Image();
$fixturesDirectory = realpath(__DIR__.'/../../fixtures/');

View file

@ -13,13 +13,15 @@ declare(strict_types=1);
namespace Respect\Validation\Rules;
use Respect\Validation\Test\RuleTestCase;
/**
* @group rule
* @covers \Respect\Validation\Rules\Imei
*/
class ImeiTest extends RuleTestCase
{
public function providerForValidInput()
public function providerForValidInput(): array
{
$rule = new Imei();
@ -35,7 +37,7 @@ class ImeiTest extends RuleTestCase
];
}
public function providerForInvalidInput()
public function providerForInvalidInput(): array
{
$rule = new Imei();

View file

@ -13,13 +13,15 @@ declare(strict_types=1);
namespace Respect\Validation\Rules;
use Respect\Validation\Test\RuleTestCase;
/**
* @group rule
* @covers \Respect\Validation\Rules\IterableType
*/
class IterableTypeTest extends RuleTestCase
{
public function providerForValidInput()
public function providerForValidInput(): array
{
$rule = new IterableType();
@ -30,7 +32,7 @@ class IterableTypeTest extends RuleTestCase
];
}
public function providerForInvalidInput()
public function providerForInvalidInput(): array
{
$rule = new IterableType();

View file

@ -13,6 +13,8 @@ declare(strict_types=1);
namespace Respect\Validation\Rules;
use Respect\Validation\Test\RuleTestCase;
/**
* @group rule
* @covers \Respect\Validation\Rules\Json
@ -20,7 +22,7 @@ namespace Respect\Validation\Rules;
*/
class JsonTest extends RuleTestCase
{
public function providerForValidInput()
public function providerForValidInput(): array
{
$json = new Json();
@ -37,7 +39,7 @@ class JsonTest extends RuleTestCase
];
}
public function providerForInvalidInput()
public function providerForInvalidInput(): array
{
$json = new Json();

View file

@ -13,13 +13,15 @@ declare(strict_types=1);
namespace Respect\Validation\Rules;
use Respect\Validation\Test\RuleTestCase;
/**
* @group rule
* @covers \Respect\Validation\Rules\LanguageCode
*/
class LanguageCodeTest extends RuleTestCase
{
public function providerForValidInput()
public function providerForValidInput(): array
{
$ruleAlpha2 = new LanguageCode();
$ruleAlpha3 = new LanguageCode('alpha-3');
@ -36,7 +38,7 @@ class LanguageCodeTest extends RuleTestCase
];
}
public function providerForInvalidInput()
public function providerForInvalidInput(): array
{
$ruleAlpha2 = new LanguageCode();
$ruleAlpha3 = new LanguageCode('alpha-3');

View file

@ -13,7 +13,7 @@ declare(strict_types=1);
namespace Respect\Validation\Rules\Locale;
use Respect\Validation\Rules\RuleTestCase;
use Respect\Validation\Test\RuleTestCase;
/**
* @group rule
@ -21,7 +21,7 @@ use Respect\Validation\Rules\RuleTestCase;
*/
class PlIdentityCardTest extends RuleTestCase
{
public function providerForValidInput()
public function providerForValidInput(): array
{
$rule = new PlIdentityCard();
@ -32,7 +32,7 @@ class PlIdentityCardTest extends RuleTestCase
];
}
public function providerForInvalidInput()
public function providerForInvalidInput(): array
{
$rule = new PlIdentityCard();

View file

@ -13,7 +13,7 @@ declare(strict_types=1);
namespace Respect\Validation\Rules\Locale;
use Respect\Validation\Rules\RuleTestCase;
use Respect\Validation\Test\RuleTestCase;
use stdClass;
/**
@ -22,7 +22,7 @@ use stdClass;
*/
class PlVatinTest extends RuleTestCase
{
public function providerForValidInput()
public function providerForValidInput(): array
{
$rule = new PlVatin();
@ -33,7 +33,7 @@ class PlVatinTest extends RuleTestCase
];
}
public function providerForInvalidInput()
public function providerForInvalidInput(): array
{
$rule = new PlVatin();

View file

@ -13,13 +13,15 @@ declare(strict_types=1);
namespace Respect\Validation\Rules;
use Respect\Validation\Test\RuleTestCase;
/**
* @group rule
* @covers \Respect\Validation\Rules\Luhn
*/
class LuhnTest extends RuleTestCase
{
public function providerForValidInput()
public function providerForValidInput(): array
{
$rule = new Luhn();
@ -31,7 +33,7 @@ class LuhnTest extends RuleTestCase
];
}
public function providerForInvalidInput()
public function providerForInvalidInput(): array
{
$rule = new Luhn();

View file

@ -13,6 +13,8 @@ declare(strict_types=1);
namespace Respect\Validation\Rules;
use Respect\Validation\Test\RuleTestCase;
/**
* @group rule
* @covers \Respect\Validation\Rules\Nif
@ -24,7 +26,7 @@ final class NifTest extends RuleTestCase
/**
* {@inheritdoc}
*/
public function providerForValidInput()
public function providerForValidInput(): array
{
$rule = new Nif();
@ -56,7 +58,7 @@ final class NifTest extends RuleTestCase
/**
* {@inheritdoc}
*/
public function providerForInvalidInput()
public function providerForInvalidInput(): array
{
$rule = new Nif();

View file

@ -13,6 +13,7 @@ declare(strict_types=1);
namespace Respect\Validation\Rules;
use Respect\Validation\Test\RuleTestCase;
use stdClass;
/**
@ -21,7 +22,7 @@ use stdClass;
*/
class NumberTest extends RuleTestCase
{
public function providerForValidInput()
public function providerForValidInput(): array
{
$rule = new Number();
@ -37,7 +38,7 @@ class NumberTest extends RuleTestCase
];
}
public function providerForInvalidInput()
public function providerForInvalidInput(): array
{
$rule = new Number();

View file

@ -13,13 +13,15 @@ declare(strict_types=1);
namespace Respect\Validation\Rules;
use Respect\Validation\Test\RuleTestCase;
/**
* @group rule
* @covers \Respect\Validation\Rules\Pesel
*/
class PeselTest extends RuleTestCase
{
public function providerForValidInput()
public function providerForValidInput(): array
{
$rule = new Pesel();
@ -35,7 +37,7 @@ class PeselTest extends RuleTestCase
];
}
public function providerForInvalidInput()
public function providerForInvalidInput(): array
{
$rule = new Pesel();

View file

@ -13,6 +13,8 @@ declare(strict_types=1);
namespace Respect\Validation\Rules;
use Respect\Validation\Test\RuleTestCase;
/**
* @group rule
* @covers \Respect\Validation\Rules\PhpLabel
@ -20,7 +22,7 @@ namespace Respect\Validation\Rules;
*/
class PhpLabelTest extends RuleTestCase
{
public function providerForValidInput()
public function providerForValidInput(): array
{
$rule = new PhpLabel();
@ -35,7 +37,7 @@ class PhpLabelTest extends RuleTestCase
];
}
public function providerForInvalidInput()
public function providerForInvalidInput(): array
{
$rule = new PhpLabel();

View file

@ -13,6 +13,7 @@ declare(strict_types=1);
namespace Respect\Validation\Rules;
use Respect\Validation\Test\RuleTestCase;
use stdClass;
/**
@ -28,7 +29,7 @@ class PisTest extends RuleTestCase
/**
* {@inheritdoc}
*/
public function providerForValidInput()
public function providerForValidInput(): array
{
$rule = new Pis();
@ -50,7 +51,7 @@ class PisTest extends RuleTestCase
/**
* {@inheritdoc}
*/
public function providerForInvalidInput()
public function providerForInvalidInput(): array
{
$rule = new Pis();

View file

@ -13,6 +13,8 @@ declare(strict_types=1);
namespace Respect\Validation\Rules;
use Respect\Validation\Test\RuleTestCase;
/**
* @group rule
* @covers \Respect\Validation\Rules\Regex
@ -22,7 +24,7 @@ final class RegexTest extends RuleTestCase
/**
* {@inheritdoc}
*/
public function providerForValidInput()
public function providerForValidInput(): array
{
return [
[new Regex('/^[a-z]+$/'), 'wpoiur'],
@ -34,7 +36,7 @@ final class RegexTest extends RuleTestCase
/**
* {@inheritdoc}
*/
public function providerForInvalidInput()
public function providerForInvalidInput(): array
{
return [
[new Regex('/^w+$/'), 'w poiur'],

View file

@ -13,6 +13,7 @@ declare(strict_types=1);
namespace Respect\Validation\Rules;
use Respect\Validation\Test\RuleTestCase;
use stdClass;
/**
@ -21,7 +22,7 @@ use stdClass;
*/
class StringValTest extends RuleTestCase
{
public function providerForValidInput()
public function providerForValidInput(): array
{
$rule = new StringVal();
@ -36,7 +37,7 @@ class StringValTest extends RuleTestCase
];
}
public function providerForInvalidInput()
public function providerForInvalidInput(): array
{
$rule = new StringVal();

View file

@ -13,13 +13,15 @@ declare(strict_types=1);
namespace Respect\Validation\Rules;
use Respect\Validation\Test\RuleTestCase;
/**
* @group rule
* @covers \Respect\Validation\Rules\Unique
*/
class UniqueTest extends RuleTestCase
{
public function providerForValidInput()
public function providerForValidInput(): array
{
$rule = new Unique();
@ -34,7 +36,7 @@ class UniqueTest extends RuleTestCase
];
}
public function providerForInvalidInput()
public function providerForInvalidInput(): array
{
$rule = new Unique();

View file

@ -13,13 +13,15 @@ declare(strict_types=1);
namespace Respect\Validation\Rules;
use Respect\Validation\Test\RuleTestCase;
/**
* @group rule
* @covers \Respect\Validation\Rules\Uuid
*/
class UuidTest extends RuleTestCase
{
public function providerForValidInput()
public function providerForValidInput(): array
{
$rule = new Uuid();
@ -35,7 +37,7 @@ class UuidTest extends RuleTestCase
];
}
public function providerForInvalidInput()
public function providerForInvalidInput(): array
{
$rule = new Uuid();

View file

@ -13,6 +13,8 @@ declare(strict_types=1);
namespace Respect\Validation\Rules;
use Respect\Validation\Test\RuleTestCase;
/**
* @group rule
* @covers \Respect\Validation\Rules\When
@ -21,14 +23,14 @@ class WhenTest extends RuleTestCase
{
public function testShouldConstructAnObjectWithoutElseRule(): void
{
$rule = new When($this->getRuleMock(true), $this->getRuleMock(true));
$rule = new When($this->createValidatableMock(true), $this->createValidatableMock(true));
self::assertInstanceOf(AlwaysInvalid::class, $rule->else);
}
public function testShouldConstructAnObjectWithElseRule(): void
{
$rule = new When($this->getRuleMock(true), $this->getRuleMock(true), $this->getRuleMock(true));
$rule = new When($this->createValidatableMock(true), $this->createValidatableMock(true), $this->createValidatableMock(true));
self::assertNotNull($rule->else);
}
@ -39,9 +41,9 @@ class WhenTest extends RuleTestCase
*/
public function testShouldThrowExceptionForTheThenRuleWhenTheIfRuleIsValidAndTheThenRuleIsNotOnAssertMethod(): void
{
$if = $this->getRuleMock(true);
$then = $this->getRuleMock(false, 'ThenNotValid');
$else = $this->getRuleMock(true);
$if = $this->createValidatableMock(true);
$then = $this->createValidatableMock(false, 'ThenNotValid');
$else = $this->createValidatableMock(true);
$rule = new When($if, $then, $else);
$rule->assert('');
@ -53,9 +55,9 @@ class WhenTest extends RuleTestCase
*/
public function testShouldThrowExceptionForTheThenRuleWhenTheIfRuleIsValidAndTheThenRuleIsNotOnCheckMethod(): void
{
$if = $this->getRuleMock(true);
$then = $this->getRuleMock(false, 'ThenNotValid');
$else = $this->getRuleMock(true);
$if = $this->createValidatableMock(true);
$then = $this->createValidatableMock(false, 'ThenNotValid');
$else = $this->createValidatableMock(true);
$rule = new When($if, $then, $else);
$rule->check('');
@ -67,9 +69,9 @@ class WhenTest extends RuleTestCase
*/
public function testShouldThrowExceptionForTheElseRuleWhenTheIfRuleIsNotValidAndTheElseRuleIsNotOnAssertMethod(): void
{
$if = $this->getRuleMock(false);
$then = $this->getRuleMock(false);
$else = $this->getRuleMock(false, 'ElseNotValid');
$if = $this->createValidatableMock(false);
$then = $this->createValidatableMock(false);
$else = $this->createValidatableMock(false, 'ElseNotValid');
$rule = new When($if, $then, $else);
$rule->assert('');
@ -81,9 +83,9 @@ class WhenTest extends RuleTestCase
*/
public function testShouldThrowExceptionForTheElseRuleWhenTheIfRuleIsNotValidAndTheElseRuleIsNotOnCheckMethod(): void
{
$if = $this->getRuleMock(false);
$then = $this->getRuleMock(false);
$else = $this->getRuleMock(false, 'ElseNotValid');
$if = $this->createValidatableMock(false);
$then = $this->createValidatableMock(false);
$else = $this->createValidatableMock(false, 'ElseNotValid');
$rule = new When($if, $then, $else);
$rule->check('');
@ -94,35 +96,35 @@ class WhenTest extends RuleTestCase
*
* @return array
*/
public function providerForValidInput()
public function providerForValidInput(): array
{
return [
'int (all true)' => [
new When($this->getRuleMock(true), $this->getRuleMock(true), $this->getRuleMock(true)),
new When($this->createValidatableMock(true), $this->createValidatableMock(true), $this->createValidatableMock(true)),
42,
],
'bool (all true)' => [
new When($this->getRuleMock(true), $this->getRuleMock(true), $this->getRuleMock(true)),
new When($this->createValidatableMock(true), $this->createValidatableMock(true), $this->createValidatableMock(true)),
true,
],
'empty (all true)' => [
new When($this->getRuleMock(true), $this->getRuleMock(true), $this->getRuleMock(true)),
new When($this->createValidatableMock(true), $this->createValidatableMock(true), $this->createValidatableMock(true)),
'',
],
'object (all true)' => [
new When($this->getRuleMock(true), $this->getRuleMock(true), $this->getRuleMock(true)),
new When($this->createValidatableMock(true), $this->createValidatableMock(true), $this->createValidatableMock(true)),
new \stdClass(),
],
'empty array (all true)' => [
new When($this->getRuleMock(true), $this->getRuleMock(true), $this->getRuleMock(true)),
new When($this->createValidatableMock(true), $this->createValidatableMock(true), $this->createValidatableMock(true)),
[],
],
'not empty array (all true)' => [
new When($this->getRuleMock(true), $this->getRuleMock(true), $this->getRuleMock(true)),
new When($this->createValidatableMock(true), $this->createValidatableMock(true), $this->createValidatableMock(true)),
['test'],
],
'when = true, then = false, else = true' => [
new When($this->getRuleMock(true), $this->getRuleMock(true), $this->getRuleMock(false)),
new When($this->createValidatableMock(true), $this->createValidatableMock(true), $this->createValidatableMock(false)),
false,
],
];
@ -131,19 +133,19 @@ class WhenTest extends RuleTestCase
/**
* @return array
*/
public function providerForInvalidInput()
public function providerForInvalidInput(): array
{
return [
'when = true, then = false, else = false' => [
new When($this->getRuleMock(true), $this->getRuleMock(false), $this->getRuleMock(false)),
new When($this->createValidatableMock(true), $this->createValidatableMock(false), $this->createValidatableMock(false)),
false,
],
'when = true, then = false, else = true' => [
new When($this->getRuleMock(true), $this->getRuleMock(false), $this->getRuleMock(true)),
new When($this->createValidatableMock(true), $this->createValidatableMock(false), $this->createValidatableMock(true)),
false,
],
'when = false, then = false, else = false' => [
new When($this->getRuleMock(false), $this->getRuleMock(false), $this->getRuleMock(false)),
new When($this->createValidatableMock(false), $this->createValidatableMock(false), $this->createValidatableMock(false)),
false,
],
];