[Validator] fixed CS
This commit is contained in:
parent
cf526ff846
commit
8482ad2e80
@ -1,13 +1,13 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Symfony package.
|
||||
*
|
||||
* (c) Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
/*
|
||||
* This file is part of the Symfony package.
|
||||
*
|
||||
* (c) Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Symfony\Component\Validator\Constraints;
|
||||
|
||||
@ -16,10 +16,8 @@ use Symfony\Component\Validator\Exception\MissingOptionsException;
|
||||
|
||||
/**
|
||||
* @Annotation
|
||||
*
|
||||
*
|
||||
* @author The Whole Life To Learn <thewholelifetolearn@gmail.com>
|
||||
*
|
||||
* @api
|
||||
*/
|
||||
class Isbn extends Constraint
|
||||
{
|
||||
@ -28,7 +26,7 @@ class Isbn extends Constraint
|
||||
public $bothIsbnMessage = 'This value is neither a valid ISBN-10 nor a valid ISBN-13.';
|
||||
public $isbn10;
|
||||
public $isbn13;
|
||||
|
||||
|
||||
public function __construct($options = null)
|
||||
{
|
||||
if (null !== $options && !is_array($options)) {
|
||||
@ -37,11 +35,11 @@ class Isbn extends Constraint
|
||||
'isbn13' => $options,
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
parent::__construct($options);
|
||||
|
||||
|
||||
if (null === $this->isbn10 && null === $this->isbn13) {
|
||||
throw new MissingOptionsException('Either option "isbn10" or "isbn13" must be given for constraint ' . __CLASS__, array('isbn10', 'isbn13'));
|
||||
throw new MissingOptionsException(sprintf('Either option "isbn10" or "isbn13" must be given for constraint "%s".', __CLASS__), array('isbn10', 'isbn13'));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -16,12 +16,11 @@ use Symfony\Component\Validator\ConstraintValidator;
|
||||
use Symfony\Component\Validator\Exception\UnexpectedTypeException;
|
||||
|
||||
/**
|
||||
* Validates wether the value is a valid ISBN-10 or ISBN-13
|
||||
*
|
||||
* @see https://en.wikipedia.org/wiki/Isbn
|
||||
* Validates wether the value is a valid ISBN-10 or ISBN-13.
|
||||
*
|
||||
* @author The Whole Life To Learn <thewholelifetolearn@gmail.com>
|
||||
*
|
||||
* @api
|
||||
* @see https://en.wikipedia.org/wiki/Isbn
|
||||
*/
|
||||
class IsbnValidator extends ConstraintValidator
|
||||
{
|
||||
@ -41,7 +40,7 @@ class IsbnValidator extends ConstraintValidator
|
||||
if (!is_numeric($value)) {
|
||||
$value = str_replace('-', '', $value);
|
||||
}
|
||||
|
||||
|
||||
$validation = 0;
|
||||
$value = strtoupper($value);
|
||||
$valueLength = strlen($value);
|
||||
|
@ -16,26 +16,19 @@ use Symfony\Component\Validator\Constraints\IsbnValidator;
|
||||
|
||||
/**
|
||||
* @see https://en.wikipedia.org/wiki/Isbn
|
||||
*
|
||||
*/
|
||||
class IsbnValidatorTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
protected $context;
|
||||
protected $validator;
|
||||
|
||||
|
||||
public function setUp()
|
||||
{
|
||||
$this->context = $this->getMock('Symfony\Component\Validator\ExecutionContext', array(), array(), '', false);
|
||||
$this->validator = new IsbnValidator();
|
||||
$this->validator->initialize($this->context);
|
||||
}
|
||||
|
||||
public function tearDown()
|
||||
{
|
||||
$this->context = null;
|
||||
$this->validator = null;
|
||||
}
|
||||
|
||||
|
||||
public function getValidIsbn10()
|
||||
{
|
||||
return array(
|
||||
@ -53,7 +46,7 @@ class IsbnValidatorTest extends \PHPUnit_Framework_TestCase
|
||||
array('0-4712-92311'),
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
public function getInvalidIsbn10()
|
||||
{
|
||||
return array(
|
||||
@ -67,7 +60,7 @@ class IsbnValidatorTest extends \PHPUnit_Framework_TestCase
|
||||
array('2870#971#648'),
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
public function getValidIsbn13()
|
||||
{
|
||||
return array(
|
||||
@ -85,7 +78,7 @@ class IsbnValidatorTest extends \PHPUnit_Framework_TestCase
|
||||
array('978-0471292319'),
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
public function getInvalidIsbn13()
|
||||
{
|
||||
return array(
|
||||
@ -101,7 +94,7 @@ class IsbnValidatorTest extends \PHPUnit_Framework_TestCase
|
||||
array('978#0471292319'),
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
public function getValidIsbn()
|
||||
{
|
||||
return array_merge(
|
||||
@ -109,7 +102,7 @@ class IsbnValidatorTest extends \PHPUnit_Framework_TestCase
|
||||
$this->getValidIsbn13()
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
public function getInvalidIsbn()
|
||||
{
|
||||
return array_merge(
|
||||
@ -117,27 +110,27 @@ class IsbnValidatorTest extends \PHPUnit_Framework_TestCase
|
||||
$this->getInvalidIsbn13()
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
public function testNullIsValid()
|
||||
{
|
||||
$constraint = new Isbn(true);
|
||||
$this->context
|
||||
->expects($this->never())
|
||||
->method('addViolation');
|
||||
|
||||
|
||||
$this->validator->validate(null, $constraint);
|
||||
}
|
||||
|
||||
|
||||
public function testEmptyStringIsValid()
|
||||
{
|
||||
$constraint = new Isbn(true);
|
||||
$this->context
|
||||
->expects($this->never())
|
||||
->method('addViolation');
|
||||
|
||||
|
||||
$this->validator->validate('', $constraint);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @expectedException \Symfony\Component\Validator\Exception\UnexpectedTypeException
|
||||
*/
|
||||
@ -146,7 +139,7 @@ class IsbnValidatorTest extends \PHPUnit_Framework_TestCase
|
||||
$constraint = new Isbn(true);
|
||||
$this->validator->validate(new \stdClass(), $constraint);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @dataProvider getValidIsbn10
|
||||
*/
|
||||
@ -156,10 +149,10 @@ class IsbnValidatorTest extends \PHPUnit_Framework_TestCase
|
||||
$this->context
|
||||
->expects($this->never())
|
||||
->method('addViolation');
|
||||
|
||||
|
||||
$this->validator->validate($isbn, $constraint);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @dataProvider getInvalidIsbn10
|
||||
*/
|
||||
@ -173,7 +166,7 @@ class IsbnValidatorTest extends \PHPUnit_Framework_TestCase
|
||||
|
||||
$this->validator->validate($isbn, $constraint);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @dataProvider getValidIsbn13
|
||||
*/
|
||||
@ -183,10 +176,10 @@ class IsbnValidatorTest extends \PHPUnit_Framework_TestCase
|
||||
$this->context
|
||||
->expects($this->never())
|
||||
->method('addViolation');
|
||||
|
||||
|
||||
$this->validator->validate($isbn, $constraint);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @dataProvider getInvalidIsbn13
|
||||
*/
|
||||
@ -197,10 +190,10 @@ class IsbnValidatorTest extends \PHPUnit_Framework_TestCase
|
||||
->expects($this->once())
|
||||
->method('addViolation')
|
||||
->with($constraint->isbn13Message);
|
||||
|
||||
|
||||
$this->validator->validate($isbn, $constraint);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @dataProvider getValidIsbn
|
||||
*/
|
||||
@ -210,10 +203,10 @@ class IsbnValidatorTest extends \PHPUnit_Framework_TestCase
|
||||
$this->context
|
||||
->expects($this->never())
|
||||
->method('addViolation');
|
||||
|
||||
|
||||
$this->validator->validate($isbn, $constraint);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @dataProvider getInvalidIsbn
|
||||
*/
|
||||
@ -224,7 +217,7 @@ class IsbnValidatorTest extends \PHPUnit_Framework_TestCase
|
||||
->expects($this->once())
|
||||
->method('addViolation')
|
||||
->with($constraint->bothIsbnMessage);
|
||||
|
||||
|
||||
$this->validator->validate($isbn, $constraint);
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user