Skip to content

Commit

Permalink
[#11] Add error object (#21)
Browse files Browse the repository at this point in the history
* [#11] Add error object

* [#11] Remove composer lock again
  • Loading branch information
1blankz7 authored Oct 26, 2019
1 parent e96891e commit 528c054
Show file tree
Hide file tree
Showing 40 changed files with 292 additions and 390 deletions.
8 changes: 4 additions & 4 deletions spec/Check/CountCheckSpec.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,20 +27,20 @@ function it_implements_type_interface(TypeInterface $child)
function it_returns_a_result_on_invalid_child_check(TypeInterface $child, ResultInterface $result)
{
$result->isValid()->willReturn(false);
$child->check(Argument::any())->willReturn($result);
$child->check('', Argument::any())->willReturn($result);

$this->beConstructedWith($child, 1);

$this->check([])->shouldHaveType(ResultInterface::class);
$this->check('', [])->shouldHaveType(ResultInterface::class);
}

function it_returns_a_result_on_check(TypeInterface $child, ResultInterface $result)
{
$result->isValid()->willReturn(true);
$child->check(Argument::any())->willReturn($result);
$child->check('', Argument::any())->willReturn($result);

$this->beConstructedWith($child, 1);

$this->check([3])->shouldHaveType(ResultInterface::class);
$this->check('', [3])->shouldHaveType(ResultInterface::class);
}
}
8 changes: 4 additions & 4 deletions spec/Check/NumericRangeCheckSpec.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,20 +28,20 @@ function it_implements_type_interface(TypeInterface $child)
function it_returns_a_result_on_invalid_child_check(TypeInterface $child, ResultInterface $result)
{
$result->isValid()->willReturn(false);
$child->check(Argument::any())->willReturn($result);
$child->check('', Argument::any())->willReturn($result);

$this->beConstructedWith($child, 0, 1);

$this->check(Argument::any())->shouldHaveType(ResultInterface::class);
$this->check('', Argument::any())->shouldHaveType(ResultInterface::class);
}

function it_returns_a_result_on_check(TypeInterface $child, ResultInterface $result)
{
$result->isValid()->willReturn(true);
$child->check(Argument::any())->willReturn($result);
$child->check('', Argument::any())->willReturn($result);

$this->beConstructedWith($child, 0, 1);

$this->check(0)->shouldHaveType(ResultInterface::class);
$this->check('', 0)->shouldHaveType(ResultInterface::class);
}
}
5 changes: 3 additions & 2 deletions spec/CheckerSpec.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,15 @@ function it_is_initializable()
$this->shouldHaveType(Checker::class);
}

function it_accepts_a_type_and_an_array_as_parameter_for_fulfills(TypeInterface $type)
function it_accepts_a_type_and_an_array_as_parameter_for_fulfills(TypeInterface $type, ResultInterface $result)
{
$type->check('', [])->willReturn($result);
$this->fulfills([], $type);
}

function it_returns_the_result_of_the_type_in_fulfills(TypeInterface $type, ResultInterface $result)
{
$type->check([])->willReturn($result);
$type->check('', [])->willReturn($result);
$this->fulfills([], $type)->shouldBe($result);
}
}
2 changes: 1 addition & 1 deletion spec/ResultSpec.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ function it_will_return_is_invalid_if_it_was_set_in_constructor()

function it_will_return_an_empty_array_if_no_error_list_is_given()
{
$this->beConstructedWith(true);
$this->beConstructedWith(true, []);
$this->getErrors()->shouldHaveCount(0);
}
}
16 changes: 8 additions & 8 deletions spec/Type/AnyTypeSpec.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,25 +15,25 @@ function it_is_initializable()

function it_should_return_valid_for_null()
{
$this->check(null)->isValid()->shouldBe(true);
$this->check('', null)->isValid()->shouldBe(true);
}

function it_should_return_empty_errors_for_null()
{
$this->check(null)->getErrors()->shouldHaveCount(0);
$this->check('', null)->getErrors()->shouldHaveCount(0);
}

function it_should_return_valid_for_all_values()
{
$this->check(true)->isValid()->shouldBe(true);
$this->check("foo")->isValid()->shouldBe(true);
$this->check(13)->isValid()->shouldBe(true);
$this->check('', true)->isValid()->shouldBe(true);
$this->check('', "foo")->isValid()->shouldBe(true);
$this->check('', 13)->isValid()->shouldBe(true);
}

function it_should_return_empty_errors_for_all_values()
{
$this->check(true)->getErrors()->shouldHaveCount(0);
$this->check("foo")->getErrors()->shouldHaveCount(0);
$this->check(13)->getErrors()->shouldHaveCount(0);
$this->check('', true)->getErrors()->shouldHaveCount(0);
$this->check('', "foo")->getErrors()->shouldHaveCount(0);
$this->check('', 13)->getErrors()->shouldHaveCount(0);
}
}
14 changes: 7 additions & 7 deletions spec/Type/BoolTypeSpec.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,16 @@ function it_is_initializable()

function it_should_return_valid_for_bool()
{
$this->check(true)->isValid()->shouldBe(true);
$this->check(false)->isValid()->shouldBe(true);
$this->check('', true)->isValid()->shouldBe(true);
$this->check('', false)->isValid()->shouldBe(true);
}

function it_should_return_invalid_for_others()
{
$this->check(null)->isValid()->shouldBe(false);
$this->check("foo")->isValid()->shouldBe(false);
$this->check([])->isValid()->shouldBe(false);
$this->check(1)->isValid()->shouldBe(false);
$this->check(1.0)->isValid()->shouldBe(false);
$this->check('', null)->isValid()->shouldBe(false);
$this->check('', "foo")->isValid()->shouldBe(false);
$this->check('', [])->isValid()->shouldBe(false);
$this->check('', 1)->isValid()->shouldBe(false);
$this->check('', 1.0)->isValid()->shouldBe(false);
}
}
14 changes: 7 additions & 7 deletions spec/Type/DatetimeTypeSpec.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,18 +18,18 @@ function it_should_return_valid_for_correct_values()
{
$this->beConstructedWith('d-m-Y h:m:s', 'Europe/Berlin');

$this->check('12-12-2012 12:12:10')->isValid()->shouldBe(true);
$this->check('', '12-12-2012 12:12:10')->isValid()->shouldBe(true);
}

function it_should_return_invalid_for_others()
{
$this->beConstructedWith('d-m-Y h:m:s', 'Europe/Berlin');

$this->check(null)->isValid()->shouldBe(false);
$this->check('foo')->isValid()->shouldBe(false);
$this->check([])->isValid()->shouldBe(false);
$this->check(1.234)->isValid()->shouldBe(false);
$this->check(true)->isValid()->shouldBe(false);
$this->check(false)->isValid()->shouldBe(false);
$this->check('', null)->isValid()->shouldBe(false);
$this->check('', 'foo')->isValid()->shouldBe(false);
$this->check('', [])->isValid()->shouldBe(false);
$this->check('', 1.234)->isValid()->shouldBe(false);
$this->check('', true)->isValid()->shouldBe(false);
$this->check('', false)->isValid()->shouldBe(false);
}
}
16 changes: 8 additions & 8 deletions spec/Type/EnumTypeSpec.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,18 +18,18 @@ function it_is_valid_for_all_allowed_values()
{
$this->beConstructedWith(['test', 1, null]);

$this->check('test')->isValid()->shouldBe(true);
$this->check(1)->isValid()->shouldBe(true);
$this->check(null)->isValid()->shouldBe(true);
$this->check('', 'test')->isValid()->shouldBe(true);
$this->check('', 1)->isValid()->shouldBe(true);
$this->check('', null)->isValid()->shouldBe(true);
}

function it_is_invalid_for_not_allowed_values()
{
$this->beConstructedWith(['test', 1, null]);
$this->check('array')->isValid()->shouldBe(false);
$this->check(100)->isValid()->shouldBe(false);
$this->check(1.5)->isValid()->shouldBe(false);
$this->check(['test'])->isValid()->shouldBe(false);

$this->check('', 'array')->isValid()->shouldBe(false);
$this->check('', 100)->isValid()->shouldBe(false);
$this->check('', 1.5)->isValid()->shouldBe(false);
$this->check('', ['test'])->isValid()->shouldBe(false);
}
}
2 changes: 1 addition & 1 deletion spec/Type/ExactValueTypeSpec.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,6 @@ function it_is_initializable()
function it_is_valid_for_null_if_null_is_the_value()
{
$this->beConstructedWith(null);
$this->check(null)->isValid()->shouldBe(true);
$this->check('', null)->isValid()->shouldBe(true);
}
}
20 changes: 10 additions & 10 deletions spec/Type/FloatTypeSpec.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,19 +14,19 @@ function it_is_initializable()

function it_should_return_valid_for_floats()
{
$this->check(0.0)->isValid()->shouldBe(true);
$this->check(1.1)->isValid()->shouldBe(true);
$this->check(2.0)->isValid()->shouldBe(true);
$this->check(-144.2)->isValid()->shouldBe(true);
$this->check('', 0.0)->isValid()->shouldBe(true);
$this->check('', 1.1)->isValid()->shouldBe(true);
$this->check('', 2.0)->isValid()->shouldBe(true);
$this->check('', -144.2)->isValid()->shouldBe(true);
}

function it_should_return_invalid_for_others()
{
$this->check(null)->isValid()->shouldBe(false);
$this->check("foo")->isValid()->shouldBe(false);
$this->check([])->isValid()->shouldBe(false);
$this->check(1)->isValid()->shouldBe(false);
$this->check(true)->isValid()->shouldBe(false);
$this->check(false)->isValid()->shouldBe(false);
$this->check('', null)->isValid()->shouldBe(false);
$this->check('', "foo")->isValid()->shouldBe(false);
$this->check('', [])->isValid()->shouldBe(false);
$this->check('', 1)->isValid()->shouldBe(false);
$this->check('', true)->isValid()->shouldBe(false);
$this->check('', false)->isValid()->shouldBe(false);
}
}
20 changes: 10 additions & 10 deletions spec/Type/IntTypeSpec.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,19 +15,19 @@ function it_is_initializable()

function it_should_return_valid_for_integers()
{
$this->check(0)->isValid()->shouldBe(true);
$this->check(1)->isValid()->shouldBe(true);
$this->check(20)->isValid()->shouldBe(true);
$this->check(-144)->isValid()->shouldBe(true);
$this->check('', 0)->isValid()->shouldBe(true);
$this->check('', 1)->isValid()->shouldBe(true);
$this->check('', 20)->isValid()->shouldBe(true);
$this->check('', -144)->isValid()->shouldBe(true);
}

function it_should_return_invalid_for_others()
{
$this->check(null)->isValid()->shouldBe(false);
$this->check("foo")->isValid()->shouldBe(false);
$this->check([])->isValid()->shouldBe(false);
$this->check(1.234)->isValid()->shouldBe(false);
$this->check(true)->isValid()->shouldBe(false);
$this->check(false)->isValid()->shouldBe(false);
$this->check('', null)->isValid()->shouldBe(false);
$this->check('', "foo")->isValid()->shouldBe(false);
$this->check('', [])->isValid()->shouldBe(false);
$this->check('', 1.234)->isValid()->shouldBe(false);
$this->check('', true)->isValid()->shouldBe(false);
$this->check('', false)->isValid()->shouldBe(false);
}
}
6 changes: 3 additions & 3 deletions spec/Type/NullableTypeSpec.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,12 @@ function it_is_initializable(TypeInterface $childType)

function it_should_return_valid_for_null(TypeInterface $childType) {
$this->beConstructedWith($childType);
$this->check(null)->isValid()->shouldBe(true);
$this->check('', null)->isValid()->shouldBe(true);
}

function it_should_return_the_value_from_the_child(TypeInterface $childType) {
$this->beConstructedWith($childType);
$childType->check(false)->willReturn(new Result(false, []));
$this->check(false)->isValid()->shouldBe(false);
$childType->check('', false)->willReturn(new Result(false, []));
$this->check('', false)->isValid()->shouldBe(false);
}
}
26 changes: 13 additions & 13 deletions spec/Type/NumericTypeSpec.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,26 +15,26 @@ function it_is_initializable()

function it_should_return_valid_for_integers()
{
$this->check(0)->isValid()->shouldBe(true);
$this->check(1)->isValid()->shouldBe(true);
$this->check(20)->isValid()->shouldBe(true);
$this->check(-144)->isValid()->shouldBe(true);
$this->check('', 0)->isValid()->shouldBe(true);
$this->check('', 1)->isValid()->shouldBe(true);
$this->check('', 20)->isValid()->shouldBe(true);
$this->check('', -144)->isValid()->shouldBe(true);
}

function it_should_return_valid_for_floats()
{
$this->check(0.0)->isValid()->shouldBe(true);
$this->check(1.1235)->isValid()->shouldBe(true);
$this->check(-0.00001)->isValid()->shouldBe(true);
$this->check(-144.12313131313)->isValid()->shouldBe(true);
$this->check('', 0.0)->isValid()->shouldBe(true);
$this->check('', 1.1235)->isValid()->shouldBe(true);
$this->check('', -0.00001)->isValid()->shouldBe(true);
$this->check('', -144.12313131313)->isValid()->shouldBe(true);
}

function it_should_return_invalid_for_others()
{
$this->check(null)->isValid()->shouldBe(false);
$this->check("foo")->isValid()->shouldBe(false);
$this->check([])->isValid()->shouldBe(false);
$this->check(true)->isValid()->shouldBe(false);
$this->check(false)->isValid()->shouldBe(false);
$this->check('', null)->isValid()->shouldBe(false);
$this->check('', "foo")->isValid()->shouldBe(false);
$this->check('', [])->isValid()->shouldBe(false);
$this->check('', true)->isValid()->shouldBe(false);
$this->check('', false)->isValid()->shouldBe(false);
}
}
4 changes: 2 additions & 2 deletions spec/Type/OptionalTypeSpec.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ function it_is_initializable(TypeInterface $childType)

function it_should_return_the_value_from_the_child(TypeInterface $childType) {
$this->beConstructedWith($childType);
$childType->check(false)->willReturn(new Result(false, []));
$this->check(false)->isValid()->shouldBe(false);
$childType->check('', false)->willReturn(new Result(false, []));
$this->check('', false)->isValid()->shouldBe(false);
}
}
14 changes: 7 additions & 7 deletions spec/Type/RegexTypeSpec.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,24 +19,24 @@ function it_should_return_valid_for_matching_strings()
{
$this->beConstructedWith('/^def/');

$this->check('definitive')->isValid()->shouldBe(true);
$this->check('', 'definitive')->isValid()->shouldBe(true);
}

function it_should_return_invalid_for_not_matching_strings()
{
$this->beConstructedWith('/^def/');

$this->check('developers')->isValid()->shouldBe(false);
$this->check('', 'developers')->isValid()->shouldBe(false);
}

function it_should_return_invalid_for_others()
{
$this->beConstructedWith('/^def/');

$this->check(null)->isValid()->shouldBe(false);
$this->check(12.3)->isValid()->shouldBe(false);
$this->check([])->isValid()->shouldBe(false);
$this->check(-1)->isValid()->shouldBe(false);
$this->check(true)->isValid()->shouldBe(false);
$this->check('', null)->isValid()->shouldBe(false);
$this->check('', 12.3)->isValid()->shouldBe(false);
$this->check('', [])->isValid()->shouldBe(false);
$this->check('', -1)->isValid()->shouldBe(false);
$this->check('', true)->isValid()->shouldBe(false);
}
}
16 changes: 8 additions & 8 deletions spec/Type/StringTypeSpec.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,17 +15,17 @@ function it_is_initializable()

function it_should_return_valid_for_strings()
{
$this->check("")->isValid()->shouldBe(true);
$this->check("fooo")->isValid()->shouldBe(true);
$this->check('adadsad asd a')->isValid()->shouldBe(true);
$this->check('', '')->isValid()->shouldBe(true);
$this->check('', 'fooo')->isValid()->shouldBe(true);
$this->check('', 'adadsad asd a')->isValid()->shouldBe(true);
}

function it_should_return_invalid_for_others()
{
$this->check(null)->isValid()->shouldBe(false);
$this->check(12.3)->isValid()->shouldBe(false);
$this->check([])->isValid()->shouldBe(false);
$this->check(-1)->isValid()->shouldBe(false);
$this->check(true)->isValid()->shouldBe(false);
$this->check('', null)->isValid()->shouldBe(false);
$this->check('', 12.3)->isValid()->shouldBe(false);
$this->check('', [])->isValid()->shouldBe(false);
$this->check('', -1)->isValid()->shouldBe(false);
$this->check('', true)->isValid()->shouldBe(false);
}
}
Loading

0 comments on commit 528c054

Please sign in to comment.