This repository has been archived by the owner on Sep 29, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 104
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Added More Unit Tests to Validation Classes - Updated Logic accordingly
- Loading branch information
japatel
committed
Jan 9, 2015
1 parent
095ab24
commit f7cfd0f
Showing
6 changed files
with
170 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
<?php | ||
namespace PayPal\Test\Validation; | ||
|
||
use PayPal\Validation\ArgumentValidator; | ||
|
||
class ArgumentValidatorTest extends \PHPUnit_Framework_TestCase | ||
{ | ||
|
||
public static function positiveProvider() | ||
{ | ||
return array( | ||
array("1"), | ||
array("something here"), | ||
array(1), | ||
array(array(1,2,3)), | ||
array(0.123), | ||
array(true), | ||
array(false), | ||
array(array()), | ||
); | ||
} | ||
|
||
public static function invalidProvider() | ||
{ | ||
return array( | ||
array(null), | ||
array(''), | ||
array(' ') | ||
); | ||
} | ||
|
||
/** | ||
* | ||
* @dataProvider positiveProvider | ||
*/ | ||
public function testValidate($input) | ||
{ | ||
$this->assertTrue(ArgumentValidator::validate($input, "Name")); | ||
} | ||
|
||
/** | ||
* | ||
* @dataProvider invalidProvider | ||
* @expectedException \InvalidArgumentException | ||
*/ | ||
public function testInvalidDataValidate($input) | ||
{ | ||
$this->assertTrue(ArgumentValidator::validate($input, "Name")); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
<?php | ||
namespace PayPal\Test\Validation; | ||
|
||
use PayPal\Validation\JsonValidator; | ||
|
||
class JsonValidatorTest extends \PHPUnit_Framework_TestCase | ||
{ | ||
|
||
public static function positiveProvider() | ||
{ | ||
return array( | ||
array(null), | ||
array(''), | ||
array("{}"), | ||
array('{"json":"value", "bool":false, "int":1, "float": 0.123, "array": [{"json":"value", "bool":false, "int":1, "float": 0.123},{"json":"value", "bool":false, "int":1, "float": 0.123} ]}') | ||
); | ||
} | ||
|
||
public static function invalidProvider() | ||
{ | ||
return array( | ||
array('{'), | ||
array('}'), | ||
array(' '), | ||
array(array('1' => '23')), | ||
array('{"json":"value, "bool":false, "int":1, "float": 0.123, "array": [{"json":"value, "bool":false, "int":1, "float": 0.123}"json":"value, "bool":false, "int":1, "float": 0.123} ]}') | ||
); | ||
} | ||
|
||
/** | ||
* | ||
* @dataProvider positiveProvider | ||
*/ | ||
public function testValidate($input) | ||
{ | ||
$this->assertTrue(JsonValidator::validate($input)); | ||
} | ||
|
||
/** | ||
* | ||
* @dataProvider invalidProvider | ||
* @expectedException \InvalidArgumentException | ||
*/ | ||
public function testInvalidJson($input) | ||
{ | ||
JsonValidator::validate($input); | ||
} | ||
|
||
/** | ||
* | ||
* @dataProvider invalidProvider | ||
*/ | ||
public function testInvalidJsonSilent($input) | ||
{ | ||
$this->assertFalse(JsonValidator::validate($input, true)); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
<?php | ||
namespace PayPal\Test\Validation; | ||
|
||
use PayPal\Test\Common\SimpleClass; | ||
use PayPal\Validation\ModelAccessorValidator; | ||
|
||
class ModelAccessValidatorTest extends \PHPUnit_Framework_TestCase | ||
{ | ||
|
||
public static function positiveProvider() | ||
{ | ||
return array( | ||
array(new SimpleClass(), 'name'), | ||
array(new SimpleClass(), 'description') | ||
); | ||
} | ||
|
||
public static function invalidProvider() | ||
{ | ||
return array( | ||
array(null, null,'must be an instance of PayPal\Common\PayPalModel, null given'), | ||
array(array(), array() ,'must be an instance of PayPal\Common\PayPalModel, array given'), | ||
array(new SimpleClass(), null,'Error'), | ||
array(new SimpleClass(), array(),'Error'), | ||
array(null, 'name','must be an instance of PayPal\Common\PayPalModel, null given'), | ||
array(new SimpleClass(),'notfound', 'Missing Accessor: PayPal\\Test\\Common\\SimpleClass:setnotfound') | ||
); | ||
} | ||
|
||
/** | ||
* | ||
* @dataProvider positiveProvider | ||
*/ | ||
public function testValidate($class, $name) | ||
{ | ||
$this->assertTrue(ModelAccessorValidator::validate($class, $name)); | ||
} | ||
|
||
/** | ||
* | ||
* @dataProvider invalidProvider | ||
*/ | ||
public function testInvalidValidate($class, $name, $exMessage) | ||
{ try { | ||
$this->assertFalse(ModelAccessorValidator::validate($class, $name)); | ||
} catch(\Exception $ex) { | ||
$this->assertContains($exMessage, $ex->getMessage()); | ||
} | ||
} | ||
} |