-
-
Notifications
You must be signed in to change notification settings - Fork 278
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #448 from acelaya/feature/improve-msi
Feature/improve msi
- Loading branch information
Showing
8 changed files
with
212 additions
and
69 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
<?php | ||
declare(strict_types=1); | ||
|
||
namespace ShlinkioTest\Shlink\Core\Exception; | ||
|
||
use LogicException; | ||
use PHPUnit\Framework\TestCase; | ||
use RuntimeException; | ||
use Shlinkio\Shlink\Core\Exception\ValidationException; | ||
use Throwable; | ||
use Zend\InputFilter\InputFilterInterface; | ||
|
||
use function print_r; | ||
use function random_int; | ||
|
||
class ValidationExceptionTest extends TestCase | ||
{ | ||
/** | ||
* @test | ||
* @dataProvider provideExceptionData | ||
*/ | ||
public function createsExceptionWrappingExpectedData( | ||
array $args, | ||
string $expectedMessage, | ||
array $expectedInvalidElements, | ||
int $expectedCode, | ||
?Throwable $expectedPrev | ||
): void { | ||
$e = new ValidationException(...$args); | ||
|
||
$this->assertEquals($expectedMessage, $e->getMessage()); | ||
$this->assertEquals($expectedInvalidElements, $e->getInvalidElements()); | ||
$this->assertEquals($expectedCode, $e->getCode()); | ||
$this->assertEquals($expectedPrev, $e->getPrevious()); | ||
} | ||
|
||
public function provideExceptionData(): iterable | ||
{ | ||
yield 'empty args' => [[], '', [], 0, null]; | ||
yield 'with message' => [['something'], 'something', [], 0, null]; | ||
yield 'with elements' => [['something_else', [1, 2, 3]], 'something_else', [1, 2, 3], 0, null]; | ||
yield 'with code' => [['foo', [], $foo = random_int(-100, 100)], 'foo', [], $foo, null]; | ||
yield 'with prev' => [['bar', [], 8, $e = new RuntimeException()], 'bar', [], 8, $e]; | ||
} | ||
|
||
/** | ||
* @test | ||
* @dataProvider provideExceptions | ||
*/ | ||
public function createsExceptionFromInputFilter(?Throwable $prev): void | ||
{ | ||
$invalidData = [ | ||
'foo' => 'bar', | ||
'something' => ['baz', 'foo'], | ||
]; | ||
$barValue = print_r(['baz', 'foo'], true); | ||
$expectedMessage = <<<EOT | ||
Provided data is not valid. These are the messages: | ||
'foo' => bar | ||
'something' => {$barValue} | ||
EOT; | ||
|
||
$inputFilter = $this->prophesize(InputFilterInterface::class); | ||
$getMessages = $inputFilter->getMessages()->willReturn($invalidData); | ||
|
||
$e = ValidationException::fromInputFilter($inputFilter->reveal()); | ||
|
||
$this->assertEquals($invalidData, $e->getInvalidElements()); | ||
$this->assertEquals($expectedMessage, $e->getMessage()); | ||
$this->assertEquals(-1, $e->getCode()); | ||
$this->assertEquals($prev, $e->getPrevious()); | ||
$getMessages->shouldHaveBeenCalledOnce(); | ||
} | ||
|
||
public function provideExceptions(): iterable | ||
{ | ||
return [[null, new RuntimeException(), new LogicException()]]; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.