Skip to content

Commit

Permalink
Use InvalidArgumentException in place of UnexpectedValueException
Browse files Browse the repository at this point in the history
  • Loading branch information
webeweb committed Jun 14, 2019
1 parent b2698f9 commit e730e47
Show file tree
Hide file tree
Showing 15 changed files with 46 additions and 40 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
CHANGELOG
=========

### [2.4.0](https://github.com/webeweb/smsmode-library/tree/v2.4.0) (2019-06-14)

- Use InvalidArgumentException in place of UnexpectedValueException

### [2.3.0](https://github.com/webeweb/smsmode-library/tree/v2.3.0) (2019-06-08)

- Change license
Expand Down
6 changes: 3 additions & 3 deletions src/Model/Request/SendingSMSBatchRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

namespace WBW\Library\SMSMode\Model\Request;

use UnexpectedValueException;
use InvalidArgumentException;
use WBW\Library\SMSMode\API\SendingSMSBatchInterface;
use WBW\Library\SMSMode\Model\AbstractRequest;
use WBW\Library\SMSMode\Traits\ClasseMsgTrait;
Expand Down Expand Up @@ -71,11 +71,11 @@ public function getResourcePath() {
*
* @param string $fichier The fichier.
* @return SendingSMSBatchRequest Returns this sending SMS batch request.
* @throws UnexpectedValueException Throws an unexpected value exception if the file does not exist.
* @throws InvalidArgumentException Throws an invalid argument exception if the file does not exist.
*/
public function setFichier($fichier) {
if (false === realpath($fichier)) {
throw new UnexpectedValueException(sprintf("File \"%s\" could not be found.", $fichier));
throw new InvalidArgumentException(sprintf("File \"%s\" could not be found.", $fichier));
}
$this->fichier = $fichier;
return $this;
Expand Down
5 changes: 3 additions & 2 deletions src/Model/Request/SendingSMSMessageRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

namespace WBW\Library\SMSMode\Model\Request;

use InvalidArgumentException;
use UnexpectedValueException;
use WBW\Library\SMSMode\API\SendingSMSMessageInterface;
use WBW\Library\SMSMode\Model\AbstractRequest;
Expand Down Expand Up @@ -188,11 +189,11 @@ protected function setNumero(array $numero) {
*
* @param int|null $stop The stop.
* @return SendingSMSMessageRequest Returns this sending SMS message request.
* @throws \UnexpectedValueException Throws an unexpected value exception if the classe msg is invalid.
* @throws InvalidArgumentException Throws an invalid argument exception if the classe msg is invalid.
*/
public function setStop($stop) {
if (null !== $stop && false === in_array($stop, $this->enumStop())) {
throw new UnexpectedValueException(sprintf("The stop \"%s\" is invalid", $stop));
throw new InvalidArgumentException(sprintf("The stop \"%s\" is invalid", $stop));
}
$this->stop = $stop;
return $this;
Expand Down
5 changes: 3 additions & 2 deletions src/Model/Request/SendingTextToSpeechSMSRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

namespace WBW\Library\SMSMode\Model\Request;

use InvalidArgumentException;
use UnexpectedValueException;
use WBW\Library\SMSMode\API\SendingTextToSpeechSMSInterface;
use WBW\Library\SMSMode\Model\AbstractRequest;
Expand Down Expand Up @@ -131,11 +132,11 @@ public function getTitle() {
*
* @param string $language The language.
* @return SendingTextToSpeechSMSRequest Returns this sending text-to-speech request.
* @throws UnexpectedValueException Throws an unexpected value exception if the language is invalid.
* @throws InvalidArgumentException Throws an invalid argument exception if the language is invalid.
*/
public function setLanguage($language) {
if (null !== $language && false === in_array($language, $this->enumLanguage())) {
throw new UnexpectedValueException(sprintf("The language \"%s\" is invalid", $language));
throw new InvalidArgumentException(sprintf("The language \"%s\" is invalid", $language));
}
$this->language = $language;
return $this;
Expand Down
6 changes: 3 additions & 3 deletions src/Normalizer/NumeroNormalizer.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

namespace WBW\Library\SMSMode\Normalizer;

use UnexpectedValueException;
use InvalidArgumentException;

/**
* Numero normalizer.
Expand All @@ -26,11 +26,11 @@ class NumeroNormalizer {
*
* @param string $numero The numero.
* @return void
* @throws UnexpectedValueException Throws an unexpected value exception if the numero is invalid.
* @throws InvalidArgumentException Throws an invalid argument exception if the numero is invalid.
*/
public static function checkNumero($numero) {
if (0 === preg_match("/^[0-9]{1,}$/", $numero)) {
throw new UnexpectedValueException(sprintf("The numero \"%s\" is invalid", $numero));
throw new InvalidArgumentException(sprintf("The numero \"%s\" is invalid", $numero));
}
}

Expand Down
6 changes: 3 additions & 3 deletions src/Traits/ClasseMsgTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

namespace WBW\Library\SMSMode\Traits;

use UnexpectedValueException;
use InvalidArgumentException;
use WBW\Library\SMSMode\API\SendingSMSBatchInterface;

/**
Expand Down Expand Up @@ -54,11 +54,11 @@ public function getClasseMsg() {
* Set the classe msg.
*
* @param int $classeMsg The classe msg.
* @throws UnexpectedValueException Throws an unexpected value exception exception if the classe msg is invalid.
* @throws InvalidArgumentException Throws an invalid argument exception exception if the classe msg is invalid.
*/
public function setClasseMsg($classeMsg) {
if (null !== $classeMsg && false === in_array($classeMsg, $this->enumClasseMsg())) {
throw new UnexpectedValueException(sprintf("The classe msg \"%s\" is invalid", $classeMsg));
throw new InvalidArgumentException(sprintf("The classe msg \"%s\" is invalid", $classeMsg));
}
$this->classeMsg = $classeMsg;
return $this;
Expand Down
6 changes: 3 additions & 3 deletions src/Traits/NbrMsgTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

namespace WBW\Library\SMSMode\Traits;

use UnexpectedValueException;
use InvalidArgumentException;

/**
* Nbr msg trait.
Expand Down Expand Up @@ -41,11 +41,11 @@ public function getNbrMsg() {
* Set the nbr msg.
*
* @param int $nbrMsg The nbr msg.
* @throws UnexpectedValueException Throws an illegal argument exception if the nbr msg is less than 1.
* @throws InvalidArgumentException Throws an invalid argument exception if the nbr msg is less than 1.
*/
public function setNbrMsg($nbrMsg) {
if (null === $nbrMsg || $nbrMsg < 1) {
throw new UnexpectedValueException("The \"nbr msg\" must be greater than 0");
throw new InvalidArgumentException("The \"nbr msg\" must be greater than 0");
}
$this->nbrMsg = $nbrMsg;
return $this;
Expand Down
6 changes: 3 additions & 3 deletions src/Traits/OffsetTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

namespace WBW\Library\SMSMode\Traits;

use UnexpectedValueException;
use InvalidArgumentException;

/**
* Offset trait.
Expand Down Expand Up @@ -41,11 +41,11 @@ public function getOffset() {
* Set the offset.
*
* @param int $offset The offset.
* @throws UnexpectedValueException Throws an illegal argument exception if the offset is less than 1.
* @throws InvalidArgumentException Throws an invalid argument exception if the offset is less than 1.
*/
public function setOffset($offset) {
if (null !== $offset && $offset < 1) {
throw new UnexpectedValueException("The \"offset\" must be greater than 0");
throw new InvalidArgumentException("The \"offset\" must be greater than 0");
}
$this->offset = $offset;
return $this;
Expand Down
6 changes: 3 additions & 3 deletions tests/Model/Request/SendingSMSBatchRequestTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
namespace WBW\Library\SMSMode\Tests\Model\Request;

use Exception;
use UnexpectedValueException;
use InvalidArgumentException;
use WBW\Library\SMSMode\Model\Request\SendingSMSBatchRequest;
use WBW\Library\SMSMode\Tests\AbstractTestCase;

Expand Down Expand Up @@ -67,7 +67,7 @@ public function testSetFichier() {
*
* @return void
*/
public function testSetFichierWithUnexpectedValueException() {
public function testSetFichierWithInvalidArgumentException() {

$obj = new SendingSMSBatchRequest();

Expand All @@ -76,7 +76,7 @@ public function testSetFichierWithUnexpectedValueException() {
$obj->setFichier("fichier");
} catch (Exception $ex) {

$this->assertInstanceOf(UnexpectedValueException::class, $ex);
$this->assertInstanceOf(InvalidArgumentException::class, $ex);
$this->assertEquals("File \"fichier\" could not be found.", $ex->getMessage());
}
}
Expand Down
6 changes: 3 additions & 3 deletions tests/Model/Request/SendingSMSMessageRequestTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
namespace WBW\Library\SMSMode\Tests\Model\Request;

use Exception;
use UnexpectedValueException;
use InvalidArgumentException;
use WBW\Library\SMSMode\API\SendingSMSMessageInterface;
use WBW\Library\SMSMode\Model\Request\SendingSMSMessageRequest;
use WBW\Library\SMSMode\Tests\AbstractTestCase;
Expand Down Expand Up @@ -128,7 +128,7 @@ public function testSetStop() {
*
* @return void
*/
public function testSetStopWithUnexpectedValueException() {
public function testSetStopWithInvalidArgumentException() {

$obj = new SendingSMSMessageRequest();

Expand All @@ -137,7 +137,7 @@ public function testSetStopWithUnexpectedValueException() {
$obj->setStop(-1);
} catch (Exception $ex) {

$this->assertInstanceOf(UnexpectedValueException::class, $ex);
$this->assertInstanceOf(InvalidArgumentException::class, $ex);
$this->assertEquals("The stop \"-1\" is invalid", $ex->getMessage());
}
}
Expand Down
6 changes: 3 additions & 3 deletions tests/Model/Request/SendingTextToSpeechSMSRequestTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
namespace WBW\Library\SMSMode\Tests\Model\Request;

use Exception;
use UnexpectedValueException;
use InvalidArgumentException;
use WBW\Library\SMSMode\API\SendingTextToSpeechSMSInterface;
use WBW\Library\SMSMode\Model\Request\SendingTextToSpeechSMSRequest;
use WBW\Library\SMSMode\Tests\AbstractTestCase;
Expand Down Expand Up @@ -98,7 +98,7 @@ public function testSetLanguage() {
*
* @return void
*/
public function testSetLanguageWithUnexpectedValueException() {
public function testSetLanguageWithInvalidArgumentException() {

$obj = new SendingTextToSpeechSMSRequest();

Expand All @@ -107,7 +107,7 @@ public function testSetLanguageWithUnexpectedValueException() {
$obj->setLanguage("language");
} catch (Exception $ex) {

$this->assertInstanceOf(UnexpectedValueException::class, $ex);
$this->assertInstanceOf(InvalidArgumentException::class, $ex);
$this->assertEquals("The language \"language\" is invalid", $ex->getMessage());
}
}
Expand Down
6 changes: 3 additions & 3 deletions tests/Normalizer/NumeroNormalizerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
namespace WBW\Library\SMSMode\Tests\Normalizer;

use Exception;
use UnexpectedValueException;
use InvalidArgumentException;
use WBW\Library\SMSMode\Normalizer\NumeroNormalizer;
use WBW\Library\SMSMode\Tests\AbstractTestCase;

Expand Down Expand Up @@ -41,14 +41,14 @@ public function testCheckNumero() {
* @return void
* @throws Exception Throws an exception if an error occurs.
*/
public function testCheckNumeroWithUnexpectedValueException() {
public function testCheckNumeroWithInvalidArgumentException() {

try {

NumeroNormalizer::checkNumero("exception");
} catch (Exception $ex) {

$this->assertInstanceOf(UnexpectedValueException::class, $ex);
$this->assertInstanceOf(InvalidArgumentException::class, $ex);
$this->assertEquals("The numero \"exception\" is invalid", $ex->getMessage());
}
}
Expand Down
6 changes: 3 additions & 3 deletions tests/Traits/ClasseMsgTraitTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
namespace WBW\Library\SMSMode\Tests\Traits;

use Exception;
use UnexpectedValueException;
use InvalidArgumentException;
use WBW\Library\SMSMode\API\SendingSMSBatchInterface;
use WBW\Library\SMSMode\Tests\AbstractTestCase;
use WBW\Library\SMSMode\Tests\Fixtures\Traits\TestClasseMsgTrait;
Expand Down Expand Up @@ -74,7 +74,7 @@ public function testSetClasseMsg() {
*
* @return void
*/
public function testSetClasseMsgWithUnexpectedValueException() {
public function testSetClasseMsgWithInvalidArgumentException() {

$obj = new TestClasseMsgTrait();

Expand All @@ -83,7 +83,7 @@ public function testSetClasseMsgWithUnexpectedValueException() {
$obj->setClasseMsg(0);
} catch (Exception $ex) {

$this->assertInstanceOf(UnexpectedValueException::class, $ex);
$this->assertInstanceOf(InvalidArgumentException::class, $ex);
$this->assertEquals("The classe msg \"0\" is invalid", $ex->getMessage());
}
}
Expand Down
6 changes: 3 additions & 3 deletions tests/Traits/NbrMsgTraitTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
namespace WBW\Library\SMSMode\Tests\Traits;

use Exception;
use UnexpectedValueException;
use InvalidArgumentException;
use WBW\Library\SMSMode\Tests\AbstractTestCase;
use WBW\Library\SMSMode\Tests\Fixtures\Traits\TestNbrMsgTrait;

Expand Down Expand Up @@ -54,7 +54,7 @@ public function testSetNbrMsg() {
*
* @return void
*/
public function testSetNbrMsgWithUnexpectedValueException() {
public function testSetNbrMsgWithInvalidArgumentException() {

$obj = new TestNbrMsgTrait();

Expand All @@ -63,7 +63,7 @@ public function testSetNbrMsgWithUnexpectedValueException() {
$obj->setNbrMsg(0);
} catch (Exception $ex) {

$this->assertInstanceOf(UnexpectedValueException::class, $ex);
$this->assertInstanceOf(InvalidArgumentException::class, $ex);
$this->assertEquals("The \"nbr msg\" must be greater than 0", $ex->getMessage());
}
}
Expand Down
6 changes: 3 additions & 3 deletions tests/Traits/OffsetTraitTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
namespace WBW\Library\SMSMode\Tests\Traits;

use Exception;
use UnexpectedValueException;
use InvalidArgumentException;
use WBW\Library\SMSMode\Tests\AbstractTestCase;
use WBW\Library\SMSMode\Tests\Fixtures\Traits\TestOffsetTrait;

Expand Down Expand Up @@ -54,7 +54,7 @@ public function testSetOffset() {
*
* @return void
*/
public function testSetOffsetWithUnexpectedValueException() {
public function testSetOffsetWithInvalidArgumentException() {

$obj = new TestOffsetTrait();

Expand All @@ -63,7 +63,7 @@ public function testSetOffsetWithUnexpectedValueException() {
$obj->setOffset(0);
} catch (Exception $ex) {

$this->assertInstanceOf(UnexpectedValueException::class, $ex);
$this->assertInstanceOf(InvalidArgumentException::class, $ex);
$this->assertEquals("The \"offset\" must be greater than 0", $ex->getMessage());
}
}
Expand Down

0 comments on commit e730e47

Please sign in to comment.