Skip to content

Commit

Permalink
Merge pull request #4 from MyOnlineStore/add-scrutinzer-travis
Browse files Browse the repository at this point in the history
add Scrutinizer config and Travis config
  • Loading branch information
digibeuk authored Mar 16, 2018
2 parents ba36405 + e24df3f commit b4e4620
Show file tree
Hide file tree
Showing 9 changed files with 142 additions and 42 deletions.
7 changes: 7 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
# IDE
/.idea
/.stfolder
/.phpstorm_helpers

/vendor/
/composer.lock

# phpunit
phpunit.xml
14 changes: 14 additions & 0 deletions .scrutinizer.yml
Original file line number Diff line number Diff line change
@@ -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
9 changes: 9 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
language: php
php:
- '5.5'
- '5.6'
- '7.0'
- '7.1'
before_script:
- composer self-update
- composer install --prefer-source
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -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)
Expand Down
12 changes: 11 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -24,5 +27,12 @@
"psr-4": {
"Sandwich\\ViesBundle\\Tests\\": "tests"
}
},
"config": {
"vendor-dir": "vendor",
"sort-packages": true,
"platform": {
"php": "5.5"
}
}
}
22 changes: 22 additions & 0 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit backupGlobals="false"
backupStaticAttributes="false"
bootstrap="vendor/autoload.php"
colors="true"
convertErrorsToExceptions="true"
convertNoticesToExceptions="true"
convertWarningsToExceptions="true"
processIsolation="false"
stopOnFailure="false"
syntaxCheck="false">
<testsuites>
<testsuite name="ViesBundle Test Suite">
<directory>./tests/</directory>
</testsuite>
</testsuites>
<filter>
<whitelist>
<directory>./src</directory>
</whitelist>
</filter>
</phpunit>
4 changes: 2 additions & 2 deletions src/Validator/Constraint/VatNumber.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
34 changes: 34 additions & 0 deletions tests/Validator/Constraint/VatNumberTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<?php

namespace Sandwich\ViesBundle\Tests\Validator\Constraint;

use Sandwich\ViesBundle\Validator\Constraint\VatNumber;
use Sandwich\ViesBundle\Validator\Constraint\VatNumberValidator;

final class VatNumberTest extends \PHPUnit_Framework_TestCase
{
/**
* @var VatNumber
*/
private $constraint;

protected function setUp()
{
$this->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());
}
}
78 changes: 39 additions & 39 deletions tests/Validator/Constraint/VatNumberValidatorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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]);
Expand All @@ -64,44 +64,34 @@ 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(
self::MESSAGE,
['%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);
Expand All @@ -117,21 +107,31 @@ 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(
self::MESSAGE,
['%format%' => self::FORMAT]
)->willReturn($this->constraintViolationBuilder);

$this->response->expects(self::once())->method('isValid')->willReturn(false);

$this->validator->validate('foobar', $this->constraint);
}
}

0 comments on commit b4e4620

Please sign in to comment.