Skip to content

Commit

Permalink
PassInvalidException now returns an exception message
Browse files Browse the repository at this point in the history
  • Loading branch information
mahemrai committed Oct 6, 2016
1 parent 121d2a6 commit 1787b69
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 3 deletions.
9 changes: 8 additions & 1 deletion src/Passbook/Exception/PassInvalidException.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,20 @@
*/
class PassInvalidException extends \RuntimeException
{
/**
* @var array
*/
protected $errors;

/**
* Construct a PassInvalidException either with or without an array of errors.
*
* @param string $string
* @param string[]|null $errors
*/
public function __construct(array $errors = null)
public function __construct($message = '', array $errors = null)
{
parent::__construct($message);
$this->errors = $errors ? $errors : array();
}

Expand Down
2 changes: 1 addition & 1 deletion src/Passbook/PassFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,7 @@ public function package(PassInterface $pass, $passName = '')

if ($this->passValidator) {
if (!$this->passValidator->validate($pass)){
throw new PassInvalidException($this->passValidator->getErrors());
throw new PassInvalidException('Failed to validate passbook', $this->passValidator->getErrors());
};
}

Expand Down
12 changes: 11 additions & 1 deletion tests/Passbook/Tests/Exception/PassInvalidExceptionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,20 @@ public function testNewExceptionWithoutErrorsArray()
public function testNewExceptionWithErrorsArray()
{
$errors = array('error 1', 'error 2');
$exception = new PassInvalidException($errors);
$exception = new PassInvalidException('', $errors);

self::assertTrue(is_array($exception->getErrors()));
self::assertEquals($errors, $exception->getErrors());
}

public function testNewExceptionWithMessageAndArray()
{
$errors = array('error 1', 'error 2');
$exception = new PassInvalidException('Exception message', $errors);

self::assertTrue(is_array($exception->getErrors()));
self::assertEquals($errors, $exception->getErrors());
self::assertSame('Exception message', $exception->getMessage());
}

}

0 comments on commit 1787b69

Please sign in to comment.