zangra-dev /
bpost-api-library
| 1 | <?php |
||
| 2 | |||
| 3 | namespace Tests\Common; |
||
| 4 | |||
| 5 | use Bpost\BpostApiClient\Common\ValidatedValue; |
||
| 6 | use Bpost\BpostApiClient\Exception\BpostLogicException; |
||
| 7 | use Bpost\BpostApiClient\Exception\BpostLogicException\BpostInvalidLengthException; |
||
| 8 | use Bpost\BpostApiClient\Exception\BpostLogicException\BpostInvalidPatternException; |
||
| 9 | use Bpost\BpostApiClient\Exception\BpostLogicException\BpostInvalidValueException; |
||
| 10 | use PHPUnit_Framework_TestCase; |
||
|
0 ignored issues
–
show
|
|||
| 11 | |||
| 12 | class ValidatedValueFake extends ValidatedValue |
||
| 13 | { |
||
| 14 | /** |
||
| 15 | * @throws BpostLogicException |
||
| 16 | */ |
||
| 17 | public function validate() |
||
| 18 | { |
||
| 19 | if ($this->getValue() === 'aze') { |
||
| 20 | throw new BpostLogicException('aze'); |
||
| 21 | } |
||
| 22 | } |
||
| 23 | } |
||
| 24 | |||
| 25 | class ValidatedValueTest extends PHPUnit_Framework_TestCase |
||
| 26 | { |
||
| 27 | /** |
||
| 28 | * @expectedException \Bpost\BpostApiClient\Exception\BpostLogicException |
||
| 29 | */ |
||
| 30 | public function testGetValue() |
||
| 31 | { |
||
| 32 | $fake = new ValidatedValueFake('qsd'); |
||
| 33 | $this->assertSame('qsd', $fake->getValue()); |
||
| 34 | |||
| 35 | $fake = new ValidatedValueFake('qsd'); |
||
| 36 | $this->assertSame('qsd', (string) $fake); |
||
| 37 | |||
| 38 | new ValidatedValueFake('aze'); |
||
| 39 | } |
||
| 40 | |||
| 41 | public function testValidateLength() |
||
| 42 | { |
||
| 43 | $fake = new ValidatedValueFake('qsd'); |
||
| 44 | try { |
||
| 45 | $fake->validateLength(10); |
||
| 46 | $this->assertTrue(true); |
||
| 47 | } catch (BpostInvalidLengthException $e) { |
||
| 48 | $this->fail('Exception launched for valid value: "qsd" (tested with length=10)'); |
||
| 49 | } |
||
| 50 | |||
| 51 | try { |
||
| 52 | $fake->validateLength(2); |
||
| 53 | $this->fail('Exception uncaught for invalid value: "qsd" (tested with length=2)'); |
||
| 54 | } catch (BpostInvalidLengthException $e) { |
||
| 55 | $this->assertTrue(true); |
||
| 56 | } |
||
| 57 | } |
||
| 58 | |||
| 59 | public function testValidateChoice() |
||
| 60 | { |
||
| 61 | $fake = new ValidatedValueFake('qsd'); |
||
| 62 | try { |
||
| 63 | $fake->validateChoice(array('aze', 'qsd')); |
||
| 64 | $this->assertTrue(true); |
||
| 65 | } catch (BpostInvalidValueException $e) { |
||
| 66 | $this->fail('Exception launched for valid value: "qsd" (tested with ["aze", "qsd"])'); |
||
| 67 | } |
||
| 68 | |||
| 69 | try { |
||
| 70 | $fake->validateChoice(array('aze', 'wxc')); |
||
| 71 | $this->fail('Exception uncaught for invalid value: "qsd" (tested with ["aze", "wxc"])'); |
||
| 72 | } catch (BpostInvalidValueException $e) { |
||
| 73 | $this->assertTrue(true); |
||
| 74 | } |
||
| 75 | } |
||
| 76 | |||
| 77 | public function testValidatePattern() |
||
| 78 | { |
||
| 79 | $fake = new ValidatedValueFake('[email protected]'); |
||
| 80 | try { |
||
| 81 | $fake->validatePattern('([a-zA-Z0-9_\.\-+])+@(([a-zA-Z0-9-])+\.)+([a-zA-Z0-9]{2,4})+'); |
||
| 82 | $this->assertTrue(true); |
||
| 83 | } catch (BpostInvalidPatternException $e) { |
||
| 84 | $this->fail('Exception launched for valid value: "[email protected]"'); |
||
| 85 | } |
||
| 86 | |||
| 87 | try { |
||
| 88 | $fake->validatePattern('([a-zA-Z0-9_\.\-+])+(([a-zA-Z0-9-])+\.)+([a-zA-Z0-9]{2,4})+'); |
||
| 89 | $this->fail('Exception uncaught for invalid value: "[email protected]"'); |
||
| 90 | } catch (BpostInvalidPatternException $e) { |
||
| 91 | $this->assertTrue(true); |
||
| 92 | } |
||
| 93 | } |
||
| 94 | } |
||
| 95 |
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths