Skip to content

Commit

Permalink
Replace InvalidArgumentException with ParameterValidationException
Browse files Browse the repository at this point in the history
The commit includes the replacement of all instances of InvalidArgumentException with ParameterValidationException in the setMInfo function of the Request class. Due to this change, the relevant unit tests have also been updated to expect ParameterValidationException instead of InvalidArgumentException.
  • Loading branch information
veneliniliev committed Jul 16, 2024
1 parent 46242d0 commit 64e2b80
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 8 deletions.
9 changes: 5 additions & 4 deletions src/Request.php
Original file line number Diff line number Diff line change
Expand Up @@ -287,29 +287,30 @@ public function getMInfo()
* @param array $mInfo
*
* @return Request
* @throws ParameterValidationException
*/
public function setMInfo($mInfo)
{
// Check for required fields (cardholderName and email or mobilePhone)
if (!isset($mInfo['cardholderName']) ||
(!isset($mInfo['email']) && !isset($mInfo['mobilePhone']))) {
throw new InvalidArgumentException('CardholderName and email or MobilePhone must be provided');
throw new ParameterValidationException('CardholderName and email or MobilePhone must be provided');
}

// Check the maximum length of cardholderName
if (strlen($mInfo['cardholderName']) > 45) {
throw new InvalidArgumentException('CardHolderName must be at most 45 characters');
throw new ParameterValidationException('CardHolderName must be at most 45 characters');
}

// Check for a valid email address format
if (isset($mInfo['email']) && !filter_var($mInfo['email'], FILTER_VALIDATE_EMAIL)) {
throw new InvalidArgumentException('Email must be a valid email address');
throw new ParameterValidationException('Email must be a valid email address');
}

// Check the structure for the mobile phone
if (isset($mInfo['mobilePhone'])) {
if (!isset($mInfo['mobilePhone']['cc']) || !isset($mInfo['mobilePhone']['subscriber'])) {
throw new InvalidArgumentException('MobilePhone must contain both cc and subscriber');
throw new ParameterValidationException('MobilePhone must contain both cc and subscriber');
}
}

Expand Down
12 changes: 8 additions & 4 deletions tests/Unit/SaleRequestMInfoTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,14 @@
namespace VenelinIliev\Borica3ds\Tests\Unit;

use PHPUnit\Framework\TestCase;
use VenelinIliev\Borica3ds\Exceptions\ParameterValidationException;
use VenelinIliev\Borica3ds\SaleRequest;

class SaleRequestMInfoTest extends TestCase
{
/**
* @throws ParameterValidationException
*/
public function testGetMInfo()
{
$request = new SaleRequest();
Expand All @@ -27,7 +31,7 @@ public function testGetMInfo()

public function testMInfoWithInvalidEmail()
{
$this->expectException(\InvalidArgumentException::class);
$this->expectException(ParameterValidationException::class);

$request = new SaleRequest();
$request->setMInfo([
Expand All @@ -38,7 +42,7 @@ public function testMInfoWithInvalidEmail()

public function testMInfoWithInvalidCardholderNameLength()
{
$this->expectException(\InvalidArgumentException::class);
$this->expectException(ParameterValidationException::class);

$request = new SaleRequest();
$request->setMInfo([
Expand All @@ -49,15 +53,15 @@ public function testMInfoWithInvalidCardholderNameLength()

public function testMInfoWithMissingRequiredFields()
{
$this->expectException(\InvalidArgumentException::class);
$this->expectException(ParameterValidationException::class);

$request = new SaleRequest();
$request->setMInfo(['email' => '[email protected]']);
}

public function testMInfoWithInvalidMobilePhoneStructure()
{
$this->expectException(\InvalidArgumentException::class);
$this->expectException(ParameterValidationException::class);

$request = new SaleRequest();
$request->setMInfo([
Expand Down

0 comments on commit 64e2b80

Please sign in to comment.