Make second argument of "AbstractEnvelope" optional

The argument "parameters" which is meant to give the wrapped rule's
exception some extra information does not always need to be defined, for
example when the exception does not need any parameter.

The current version of "AbstractEnvelope" required that argument and the
rules that are extending this class are passing an empty array.

This commit will make the "parameters" argument optional. As an extra,
it will make sure the tests from the children of "AbstractEnvelope" are
also covering their parent.

Signed-off-by: Henrique Moody <henriquemoody@gmail.com>
This commit is contained in:
Henrique Moody 2018-11-25 15:26:03 +01:00
parent 9595b3fd6c
commit 93e177a4c0
No known key found for this signature in database
GPG key ID: 221E9281655813A6
8 changed files with 7 additions and 3 deletions

View file

@ -42,7 +42,7 @@ abstract class AbstractEnvelope extends AbstractRule
* @param Validatable $validatable
* @param array $parameters
*/
public function __construct(Validatable $validatable, array $parameters)
public function __construct(Validatable $validatable, array $parameters = [])
{
$this->validatable = $validatable;
$this->parameters = $parameters;

View file

@ -53,6 +53,6 @@ final class FilterVar extends AbstractEnvelope
throw new ComponentException('Cannot accept the given filter');
}
parent::__construct(new Callback('filter_var', $filter, $options), []);
parent::__construct(new Callback('filter_var', $filter, $options));
}
}

View file

@ -30,6 +30,6 @@ final class Url extends AbstractEnvelope
*/
public function __construct()
{
parent::__construct(new FilterVar(FILTER_VALIDATE_URL), []);
parent::__construct(new FilterVar(FILTER_VALIDATE_URL));
}
}

0
tests/fixtures/non-writable vendored Normal file → Executable file
View file

View file

@ -20,6 +20,7 @@ use Respect\Validation\Test\Stubs\CountableStub;
/**
* @group rule
*
* @covers \Respect\Validation\Rules\AbstractEnvelope
* @covers \Respect\Validation\Rules\Between
*/
final class BetweenTest extends RuleTestCase

View file

@ -24,6 +24,7 @@ use const FILTER_VALIDATE_URL;
/**
* @group rule
*
* @covers \Respect\Validation\Rules\AbstractEnvelope
* @covers \Respect\Validation\Rules\FilterVar
*
* @author Gabriel Caruso <carusogabriel34@gmail.com>

View file

@ -19,6 +19,7 @@ use Respect\Validation\Test\RuleTestCase;
/**
* @group rule
*
* @covers \Respect\Validation\Rules\AbstractEnvelope
* @covers \Respect\Validation\Rules\LanguageCode
*
* @author Danilo Benevides <danilobenevides01@gmail.com>

View file

@ -18,6 +18,7 @@ use Respect\Validation\Test\RuleTestCase;
/**
* @group rule
*
* @covers \Respect\Validation\Rules\AbstractEnvelope
* @covers \Respect\Validation\Rules\Url
*
* @author Gabriel Caruso <carusogabriel34@gmail.com>