From 1787b6943a40a8d0f5b52f25cc26a5a50a18def4 Mon Sep 17 00:00:00 2001 From: Mahendra Rai Date: Thu, 6 Oct 2016 22:26:57 +0100 Subject: [PATCH 1/2] PassInvalidException now returns an exception message --- src/Passbook/Exception/PassInvalidException.php | 9 ++++++++- src/Passbook/PassFactory.php | 2 +- .../Tests/Exception/PassInvalidExceptionTest.php | 12 +++++++++++- 3 files changed, 20 insertions(+), 3 deletions(-) diff --git a/src/Passbook/Exception/PassInvalidException.php b/src/Passbook/Exception/PassInvalidException.php index 5112663..898e564 100644 --- a/src/Passbook/Exception/PassInvalidException.php +++ b/src/Passbook/Exception/PassInvalidException.php @@ -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(); } diff --git a/src/Passbook/PassFactory.php b/src/Passbook/PassFactory.php index 148ff83..28eea7f 100644 --- a/src/Passbook/PassFactory.php +++ b/src/Passbook/PassFactory.php @@ -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()); }; } diff --git a/tests/Passbook/Tests/Exception/PassInvalidExceptionTest.php b/tests/Passbook/Tests/Exception/PassInvalidExceptionTest.php index cd13140..0759b71 100644 --- a/tests/Passbook/Tests/Exception/PassInvalidExceptionTest.php +++ b/tests/Passbook/Tests/Exception/PassInvalidExceptionTest.php @@ -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()); + } + } From ded750ca310fb967f076955be4e2b04294d6bf7e Mon Sep 17 00:00:00 2001 From: Mahendra Rai Date: Thu, 6 Oct 2016 22:35:02 +0100 Subject: [PATCH 2/2] fixed variable typo --- src/Passbook/Exception/PassInvalidException.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Passbook/Exception/PassInvalidException.php b/src/Passbook/Exception/PassInvalidException.php index 898e564..27dcd0b 100644 --- a/src/Passbook/Exception/PassInvalidException.php +++ b/src/Passbook/Exception/PassInvalidException.php @@ -15,7 +15,7 @@ class PassInvalidException extends \RuntimeException /** * Construct a PassInvalidException either with or without an array of errors. * - * @param string $string + * @param string $message * @param string[]|null $errors */ public function __construct($message = '', array $errors = null)