Permalink
Browse files

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.
  • Loading branch information...
1 parent 13ff749 commit 2e6fe3a1483d403f7dfad8da3051a16a203b11e0 @augustohp augustohp committed Dec 18, 2012
Showing with 110 additions and 36 deletions.
  1. +1 −4 .travis.yml
  2. +9 −1 composer.json
  3. +100 −31 tests/library/Respect/Validation/Rules/ZendTest.php
View
@@ -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"
View
@@ -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');
@augustohp

augustohp Dec 18, 2012

Owner

This Zend Validator moved to the I18N namespace. 🐼

- $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'));
+ $this->assertAttributeInstanceOf(
+ $instanceOf = 'Zend\Validator\ValidatorInterface',
+ $attribute = 'zendValidator',
+ $instance = $v
+ );
}
- public function testInstanceOk()
+ /**
+ * @depends test_zend_dependency
+ */
+ public function test_constructor_with_zend_validator_partial_namespace()
{
- $v = new Zend(new \Zend\Validator\Alnum);
- $this->assertTrue($v->validate('wp2oiur'));
- $this->assertTrue($v->assert('wp2oiur'));
+ $v = new Zend('Sitemap\Lastmod');
+ $this->assertAttributeInstanceOf(
+ $instanceOf = 'Zend\Validator\ValidatorInterface',
+ $attribute = 'zendValidator',
+ $instance = $v
+ );
}
- public function testNamespaceOk()
+ /**
+ * @depends test_constructor_with_validator_name
+ * @depends test_constructor_with_zend_validator_partial_namespace
+ */
+ public function test_constructor_with_validator_name_and_params()
{
- $v = new Zend('Sitemap\\Lastmod');
+ $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'
+ );
}
/**
- * @expectedException Respect\Validation\Exceptions\ZendException
+ * @depends test_constructor_with_validator_name
*/
- public function testSimpleNot()
+ public function test_zend_date_validator_with_respect_methods()
{
- $v = new Zend('alnum');
- $this->assertFalse($v->validate('#$%#$%'));
- $this->assertFalse($v->assert('#$%#$%'));
+ $v = new Zend('Date');
+ $date = new DateTime;
+ $this->assertTrue($v->validate($date));
+ $this->assertTrue($v->assert($date));
}
- public function testParamsOk()
+ /**
+ * @depends test_constructor_with_validator_name
+ * @depends test_zend_date_validator_with_respect_methods
+ * @expectedException Respect\Validation\Exceptions\ZendException
+ */
+ public function test_respect_exception_for_failed_validation()
{
- $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 @@ public function testParamsNot()
}
-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
{
}
}

0 comments on commit 2e6fe3a

Please sign in to comment.