diff --git a/.gitignore b/.gitignore index c37f15c..379303e 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,10 @@ +# IDE +/.idea +/.stfolder +/.phpstorm_helpers /vendor/ /composer.lock + +# phpunit +phpunit.xml diff --git a/.scrutinizer.yml b/.scrutinizer.yml new file mode 100644 index 0000000..97ea95a --- /dev/null +++ b/.scrutinizer.yml @@ -0,0 +1,14 @@ +filter: + excluded_paths: [tests/*] +build: + tests: + override: + - + command: 'vendor/bin/phpunit --coverage-clover=coverage.clover' + coverage: + file: 'coverage.clover' + format: 'clover' +checks: + php: + code_rating: true + duplication: true diff --git a/.travis.yml b/.travis.yml new file mode 100644 index 0000000..919c67a --- /dev/null +++ b/.travis.yml @@ -0,0 +1,9 @@ +language: php +php: + - '5.5' + - '5.6' + - '7.0' + - '7.1' +before_script: + - composer self-update + - composer install --prefer-source diff --git a/README.md b/README.md index 9327fff..56eed24 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,7 @@ +[![Scrutinizer Build](https://img.shields.io/scrutinizer/build/g/MyOnlineStore/ViesBundle.svg?style=flat-square)](https://github.com/MyOnlineStore/ViesBundle) +[![Scrutinizer Coverage](https://img.shields.io/scrutinizer/coverage/g/MyOnlineStore/ViesBundle.svg?style=flat-square)](https://github.com/MyOnlineStore/ViesBundle) +[![Scrutinizer](https://img.shields.io/scrutinizer/g/MyOnlineStore/ViesBundle.svg?style=flat-square)](https://github.com/MyOnlineStore/ViesBundle) + # ViesBundle Symfony 2 Bundle for DragonBe/vies api client. (https://github.com/DragonBe/vies) diff --git a/composer.json b/composer.json index 5dda4c9..65bd8c8 100644 --- a/composer.json +++ b/composer.json @@ -12,7 +12,10 @@ ], "require": { "php": ">=5.5", - "dragonbe/vies": "^1.0" + "dragonbe/vies": "1.0.6", + "symfony/http-kernel": "^2.8", + "symfony/symfony": "^2.8", + "symfony/validator": "^2.8" }, "require-dev": { "phpunit/phpunit": "~4.8" @@ -24,5 +27,12 @@ "psr-4": { "Sandwich\\ViesBundle\\Tests\\": "tests" } + }, + "config": { + "vendor-dir": "vendor", + "sort-packages": true, + "platform": { + "php": "5.5" + } } } diff --git a/phpunit.xml.dist b/phpunit.xml.dist new file mode 100644 index 0000000..7f9a78e --- /dev/null +++ b/phpunit.xml.dist @@ -0,0 +1,22 @@ + + + + + ./tests/ + + + + + ./src + + + diff --git a/src/Validator/Constraint/VatNumber.php b/src/Validator/Constraint/VatNumber.php index 92c043e..ebfd537 100644 --- a/src/Validator/Constraint/VatNumber.php +++ b/src/Validator/Constraint/VatNumber.php @@ -12,12 +12,12 @@ final class VatNumber extends Constraint /** * @var string */ - public $message = 'This is not a valid %format% vat number.'; + public $format = 'NL'; /** * @var string */ - public $format = 'NL'; + public $message = 'This is not a valid %format% vat number.'; /** * @inheritDoc diff --git a/tests/Validator/Constraint/VatNumberTest.php b/tests/Validator/Constraint/VatNumberTest.php new file mode 100644 index 0000000..68545d7 --- /dev/null +++ b/tests/Validator/Constraint/VatNumberTest.php @@ -0,0 +1,34 @@ +constraint = new VatNumber(); + } + + public function testContainsCorrectInitialFormat() + { + self::assertSame('NL', $this->constraint->format); + } + + public function testContainsCorrectMessage() + { + self::assertSame('This is not a valid %format% vat number.', $this->constraint->message); + } + + public function testValidatedByHasCorrectValidator() + { + self::assertSame(VatNumberValidator::class, $this->constraint->validatedBy()); + } +} diff --git a/tests/Validator/Constraint/VatNumberValidatorTest.php b/tests/Validator/Constraint/VatNumberValidatorTest.php index a448bb0..32c6ccb 100644 --- a/tests/Validator/Constraint/VatNumberValidatorTest.php +++ b/tests/Validator/Constraint/VatNumberValidatorTest.php @@ -17,32 +17,32 @@ class VatNumberValidatorTest extends \PHPUnit_Framework_TestCase const MESSAGE = 'horribly wrong'; /** - * @var VatNumberValidator + * @var \PHPUnit_Framework_MockObject_MockObject|Vies */ - private $validator; + private $api; private $constraint; - /** - * @var \PHPUnit_Framework_MockObject_MockObject|ExecutionContextInterface - */ - private $context; - /** * @var \PHPUnit_Framework_MockObject_MockObject|ConstraintViolationBuilderInterface */ private $constraintViolationBuilder; /** - * @var \PHPUnit_Framework_MockObject_MockObject|Vies + * @var \PHPUnit_Framework_MockObject_MockObject|ExecutionContextInterface */ - private $api; + private $context; /** * @var \PHPUnit_Framework_MockObject_MockObject|CheckVatResponse */ private $response; + /** + * @var VatNumberValidator + */ + private $validator; + protected function setUp() { $this->constraint = new VatNumber(['format' => self::FORMAT, 'message' => self::MESSAGE]); @@ -64,34 +64,12 @@ public function testValidateWithEmptyValueWillReturnWithNoViolation() self::assertNull($this->validator->validate(null, $this->constraint)); } - public function testValidateWithNoViesServiceAvailableWillReturnWithNoViolation() - { - $this->api->expects(self::once())->method('getHeartBeat')->willReturn(false); - - $this->api->expects(self::never())->method('validateVat'); - $this->context->expects(self::never())->method('addViolation'); - - self::assertNull($this->validator->validate('foobar', $this->constraint)); - } - - public function testValidateWithVieServiceExceptionWillReturnWithNoViolation() - { - $this->api->expects(self::once())->method('getHeartBeat')->willReturn(true); - - $this->api->expects(self::once())->method('validateVat')->with(self::FORMAT, 'foobar')->willThrowException( - new ViesServiceException() - ); - $this->context->expects(self::never())->method('addViolation'); - - self::assertNull($this->validator->validate(self::FORMAT.'foobar', $this->constraint)); - } - - public function testValidateWithViesExceptionWillReturnWithViolation() + public function testValidateWithInValidVatNumberWillReturnWithViolation() { $this->api->expects(self::once())->method('getHeartBeat')->willReturn(true); - $this->api->expects(self::once())->method('validateVat')->with(self::FORMAT, 'foobar')->willThrowException( - new ViesException() + $this->api->expects(self::once())->method('validateVat')->with(self::FORMAT, 'foobar')->willReturn( + $this->response ); $this->context->expects(self::once())->method('addViolation')->with( @@ -99,9 +77,21 @@ public function testValidateWithViesExceptionWillReturnWithViolation() ['%format%' => self::FORMAT] )->willReturn($this->constraintViolationBuilder); + $this->response->expects(self::once())->method('isValid')->willReturn(false); + $this->validator->validate('foobar', $this->constraint); } + public function testValidateWithNoViesServiceAvailableWillReturnWithNoViolation() + { + $this->api->expects(self::once())->method('getHeartBeat')->willReturn(false); + + $this->api->expects(self::never())->method('validateVat'); + $this->context->expects(self::never())->method('addViolation'); + + self::assertNull($this->validator->validate('foobar', $this->constraint)); + } + public function testValidateWithValidVatNumberWillReturnWithNoViolation() { $this->api->expects(self::once())->method('getHeartBeat')->willReturn(true); @@ -117,12 +107,24 @@ public function testValidateWithValidVatNumberWillReturnWithNoViolation() self::assertNull($this->validator->validate('foobar', $this->constraint)); } - public function testValidateWithInValidVatNumberWillReturnWithViolation() + public function testValidateWithVieServiceExceptionWillReturnWithNoViolation() { $this->api->expects(self::once())->method('getHeartBeat')->willReturn(true); - $this->api->expects(self::once())->method('validateVat')->with(self::FORMAT, 'foobar')->willReturn( - $this->response + $this->api->expects(self::once())->method('validateVat')->with(self::FORMAT, 'foobar')->willThrowException( + new ViesServiceException() + ); + $this->context->expects(self::never())->method('addViolation'); + + self::assertNull($this->validator->validate(self::FORMAT.'foobar', $this->constraint)); + } + + public function testValidateWithViesExceptionWillReturnWithViolation() + { + $this->api->expects(self::once())->method('getHeartBeat')->willReturn(true); + + $this->api->expects(self::once())->method('validateVat')->with(self::FORMAT, 'foobar')->willThrowException( + new ViesException() ); $this->context->expects(self::once())->method('addViolation')->with( @@ -130,8 +132,6 @@ public function testValidateWithInValidVatNumberWillReturnWithViolation() ['%format%' => self::FORMAT] )->willReturn($this->constraintViolationBuilder); - $this->response->expects(self::once())->method('isValid')->willReturn(false); - $this->validator->validate('foobar', $this->constraint); } }