mirror of
https://github.com/Respect/Validation.git
synced 2024-06-07 00:02:33 +02:00
Fix Travis: make it use composer.
- Refactor Zend validator tests - Fixed my email on composer.json - Added dev packages in composer.json: - Zend\Validator 2.* - Symfony\Component\Valitor 2.* PS: This is just a quick fix before Foundation can run this on his own.
This commit is contained in:
parent
13ff74966d
commit
2e6fe3a148
|
@ -6,9 +6,6 @@ php:
|
|||
- 5.4
|
||||
|
||||
before_script:
|
||||
- "pyrus channel-discover pear.symfony.com"
|
||||
- "pyrus channel-discover packages.zendframework.com"
|
||||
- "pyrus install -f pear.symfony.com/Validator"
|
||||
- "pyrus install -f packages.zendframework.com/Zend_Validator"
|
||||
- "composer install --dev"
|
||||
- "make foundation"
|
||||
- "phpenv rehash"
|
||||
|
|
|
@ -13,7 +13,7 @@
|
|||
},
|
||||
{
|
||||
"name": "Augusto Pascutti",
|
||||
"email": "contato@augustopascutti.com"
|
||||
"email": "augusto@phpsp.org.br"
|
||||
},
|
||||
{
|
||||
"name": "Carlos Andr\u00e9 Ferrari",
|
||||
|
@ -80,6 +80,14 @@
|
|||
"email": "t.brodt@gmail.com"
|
||||
}
|
||||
],
|
||||
"repositories": [{
|
||||
"type": "composer",
|
||||
"url": "https://packages.zendframework.com/"
|
||||
}],
|
||||
"require-dev": {
|
||||
"zendframework/zend-validator": "2.*",
|
||||
"symfony/validator": "2.*"
|
||||
},
|
||||
"autoload": {
|
||||
"psr-0": {
|
||||
"Respect\\Validation": "library\/"
|
||||
|
|
|
@ -2,66 +2,134 @@
|
|||
|
||||
namespace Respect\Validation\Rules;
|
||||
|
||||
use DateTime;
|
||||
|
||||
class ZendTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
|
||||
public function setUp()
|
||||
public function test_zend_dependency()
|
||||
{
|
||||
if (!class_exists('\Zend\Validator\Alnum')) {
|
||||
$this->markTestSkipped('No ZendFramework installed');
|
||||
}
|
||||
$this->assertTrue(
|
||||
class_exists('\Zend\Validator\Date'),
|
||||
'Zend Framework 2 Validator not installed.'
|
||||
);
|
||||
}
|
||||
|
||||
public function testSimpleOk()
|
||||
/**
|
||||
* @depends test_zend_dependency
|
||||
*/
|
||||
public function test_constructor_with_validator_name()
|
||||
{
|
||||
$v = new Zend('Alnum');
|
||||
$this->assertTrue($v->validate('wp2oiur'));
|
||||
$this->assertTrue($v->assert('wp2oiur'));
|
||||
$v = new Zend('Date');
|
||||
$this->assertAttributeInstanceOf(
|
||||
$instanceOf = 'Zend\Validator\ValidatorInterface',
|
||||
$attribute = 'zendValidator',
|
||||
$instance = $v
|
||||
);
|
||||
}
|
||||
|
||||
public function testFullNsOk()
|
||||
/**
|
||||
* @depends test_constructor_with_validator_name
|
||||
*/
|
||||
public function test_constructor_with_validator_class_name()
|
||||
{
|
||||
$v = new Zend('Zend\\Validator\\Alnum');
|
||||
$this->assertTrue($v->validate('wp2oiur'));
|
||||
$this->assertTrue($v->assert('wp2oiur'));
|
||||
$v = new Zend('Zend\Validator\Date');
|
||||
$this->assertAttributeInstanceOf(
|
||||
$instanceOf = 'Zend\Validator\ValidatorInterface',
|
||||
$attribute = 'zendValidator',
|
||||
$instance = $v
|
||||
);
|
||||
}
|
||||
|
||||
public function testExtended()
|
||||
/**
|
||||
* @depends test_zend_dependency
|
||||
*/
|
||||
public function test_constructor_with_zend_validator_instance()
|
||||
{
|
||||
$zendInstance = new \Zend\Validator\Date;
|
||||
$v = new Zend($zendInstance);
|
||||
$this->assertAttributeSame(
|
||||
$expected = $zendInstance,
|
||||
$attribute = 'zendValidator',
|
||||
$instance = $v
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @depends test_zend_dependency
|
||||
* @depends test_constructor_with_zend_validator_instance
|
||||
*/
|
||||
public function test_userland_validator_extending_zend_interface()
|
||||
{
|
||||
$v = new Zend(new MyValidator);
|
||||
$this->assertTrue($v->validate('wp2oiur'));
|
||||
$this->assertTrue($v->assert('wp2oiur'));
|
||||
}
|
||||
|
||||
public function testInstanceOk()
|
||||
{
|
||||
$v = new Zend(new \Zend\Validator\Alnum);
|
||||
$this->assertTrue($v->validate('wp2oiur'));
|
||||
$this->assertTrue($v->assert('wp2oiur'));
|
||||
}
|
||||
|
||||
public function testNamespaceOk()
|
||||
{
|
||||
$v = new Zend('Sitemap\\Lastmod');
|
||||
$this->assertAttributeInstanceOf(
|
||||
$instanceOf = 'Zend\Validator\ValidatorInterface',
|
||||
$attribute = 'zendValidator',
|
||||
$instance = $v
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @depends test_zend_dependency
|
||||
*/
|
||||
public function test_constructor_with_zend_validator_partial_namespace()
|
||||
{
|
||||
$v = new Zend('Sitemap\Lastmod');
|
||||
$this->assertAttributeInstanceOf(
|
||||
$instanceOf = 'Zend\Validator\ValidatorInterface',
|
||||
$attribute = 'zendValidator',
|
||||
$instance = $v
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @depends test_constructor_with_validator_name
|
||||
* @depends test_constructor_with_zend_validator_partial_namespace
|
||||
*/
|
||||
public function test_constructor_with_validator_name_and_params()
|
||||
{
|
||||
$zendValidatorName = 'StringLength';
|
||||
$zendValidatorParams = array('min' => 10, 'max' => 25);
|
||||
$v = new Zend($zendValidatorName, $zendValidatorParams);
|
||||
$this->assertTrue(
|
||||
$v->validate('12345678901'),
|
||||
'The value should be valid for Zend\'s validator'
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @depends test_constructor_with_validator_name
|
||||
*/
|
||||
public function test_zend_date_validator_with_respect_methods()
|
||||
{
|
||||
$v = new Zend('Date');
|
||||
$date = new DateTime;
|
||||
$this->assertTrue($v->validate($date));
|
||||
$this->assertTrue($v->assert($date));
|
||||
}
|
||||
|
||||
/**
|
||||
* @depends test_constructor_with_validator_name
|
||||
* @depends test_zend_date_validator_with_respect_methods
|
||||
* @expectedException Respect\Validation\Exceptions\ZendException
|
||||
*/
|
||||
public function testSimpleNot()
|
||||
public function test_respect_exception_for_failed_validation()
|
||||
{
|
||||
$v = new Zend('alnum');
|
||||
$this->assertFalse($v->validate('#$%#$%'));
|
||||
$this->assertFalse($v->assert('#$%#$%'));
|
||||
}
|
||||
|
||||
public function testParamsOk()
|
||||
{
|
||||
$v = new Zend('StringLength', array('min' => 10, 'max' => 25));
|
||||
$this->assertTrue($v->assert('owurhfojgboerjng'));
|
||||
$v = new Zend('Date');
|
||||
$notValid = 'a';
|
||||
$this->assertFalse(
|
||||
$v->validate($notValid),
|
||||
'The validator returned true for an invalid value, this won\'t cause an exception later on.'
|
||||
);
|
||||
$this->assertFalse(
|
||||
$v->assert($notValid)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @depends test_constructor_with_validator_name
|
||||
* @depends test_constructor_with_validator_name_and_params
|
||||
* @depends test_zend_date_validator_with_respect_methods
|
||||
* @expectedException Respect\Validation\Exceptions\ZendException
|
||||
*/
|
||||
public function testParamsNot()
|
||||
|
@ -72,8 +140,9 @@ class ZendTest extends \PHPUnit_Framework_TestCase
|
|||
|
||||
}
|
||||
|
||||
if (class_exists('Zend\Validator\Alnum')) {
|
||||
class MyValidator extends \Zend\Validator\Alnum
|
||||
// Stubs
|
||||
if (class_exists('\Zend\Validator\Date')) {
|
||||
class MyValidator extends \Zend\Validator\Date
|
||||
{
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue