From 2df0d3a8a1fd1587ed21a1fa96a4e2faefeb2903 Mon Sep 17 00:00:00 2001 From: Alexandros Kalliontzis Date: Wed, 20 Nov 2019 00:41:02 +0200 Subject: [PATCH] Fixes and improvements in tests --- tests/src/IntegerValidatorTest.php | 41 +++++++++++++++--------------- tests/src/ObjectValidatorTest.php | 14 ++++++++-- 2 files changed, 32 insertions(+), 23 deletions(-) diff --git a/tests/src/IntegerValidatorTest.php b/tests/src/IntegerValidatorTest.php index a0f1c92..13bf3d0 100644 --- a/tests/src/IntegerValidatorTest.php +++ b/tests/src/IntegerValidatorTest.php @@ -4,9 +4,6 @@ use PHPUnit\Framework\TestCase; -/** - * Generated by PHPUnit_SkeletonGenerator on 2015 - 2016-10-05 at 20:04:03. - */ class IntegerValidatorTest extends TestCase { @@ -21,7 +18,7 @@ class IntegerValidatorTest extends TestCase */ protected function setUp(): void { - $this->object = new IntegerValidator(-1000, 1000, true); + $this->object = new IntegerValidator(-1000, 1000, true, true); } /** @@ -32,7 +29,7 @@ protected function tearDown(): void { } - public function validateSuccessProvider() + public function validateSuccessProvider(): array { //input, expected return [ @@ -44,20 +41,21 @@ public function validateSuccessProvider() ]; } - public function validateFailureProvider() + public function validateFailureProvider(): array { //input return [ - ['-0x'], - ['abc'], - ['+xyz'], - ['++30'], - [-1000], //should fail becaus of exclusiveMinimum - [-10000000], - [10000000], - ['-1000000000'], - [1.4], - [-13.5] + ['-0x', 'type'], + ['abc', 'type'], + ['+xyz', 'type'], + ['++30', 'type'], + [-1000, 'minimum'], //should fail because of exclusiveMinimum + [1000, 'maximum'], //should fail because of exclusiveMaximum + [-10000000, 'minimum'], + [10000000, 'maximum'], + ['-1000000000', 'minimum'], + [1.4, 'multipleOf'], + [-13.5, 'multipleOf'], ]; } @@ -67,6 +65,8 @@ public function testConstruct() 0, 1 ); + + $this->assertInstanceOf('\Phramework\Validate\NumberValidator', $validator); } /** @@ -165,15 +165,14 @@ public function testValidateSuccess($input, $expected) /** * @dataProvider validateFailureProvider */ - public function testValidateFailure($input) + public function testValidateFailure($input, $failure) { $return = $this->object->validate($input); - $this->assertFalse($return->status); + $parameters = $return->errorObject->getParameters(); - $this->markTestIncomplete( - 'Test Exclusive' - ); + $this->assertFalse($return->status); + $this->assertEquals($failure, $parameters[0]['failure']); } public function testValidateFailureMultipleOf() diff --git a/tests/src/ObjectValidatorTest.php b/tests/src/ObjectValidatorTest.php index 2991f35..34115ad 100644 --- a/tests/src/ObjectValidatorTest.php +++ b/tests/src/ObjectValidatorTest.php @@ -66,6 +66,8 @@ public function validateFailureProvider() public function testConstruct() { $validator = new ObjectValidator(); + + $this->assertInstanceOf('\Phramework\Validate\ObjectValidator', $validator); } /** @@ -656,6 +658,16 @@ public function testXVisibility() 'field1' => 'no' ]); + $this->assertEquals('no', $result->field1); + $this->assertNull($result->field2); + + $result = $validator->parse((object) [ + 'field1' => 'yes', + 'field2' => 'abcd' + ]); + + $this->assertEquals('yes', $result->field1); + $this->assertEquals('abcd', $result->field2); //Expect exception $this->expectException( IncorrectParametersException::class @@ -665,8 +677,6 @@ public function testXVisibility() 'field1' => 'no', 'field2' => 'abcd' ]); - - $this->markTestIncomplete(); } public function testXVisibilityOR()