-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add VerificationStatus functionality and associated tests
This commit introduces the VerificationStatus class and its related methods. The class is responsible for managing different verification statuses. Associated unit tests have also been added to validate its functionality. Additionally, a minor change has been made in the ApiClient to ensure the 'context' is always a string. Signed-off-by: B24io <app@b24.io>
- Loading branch information
Showing
5 changed files
with
146 additions
and
1 deletion.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace B24io\Loyalty\SDK\Common; | ||
|
||
use B24io\Loyalty\SDK\Core\Exceptions\InvalidArgumentException; | ||
|
||
class VerificationStatus | ||
{ | ||
private const unverified = 'unverified'; | ||
private const verified = 'verified'; | ||
private const in_process = 'in_process'; | ||
private string $value; | ||
|
||
/** | ||
* @throws InvalidArgumentException | ||
*/ | ||
public function __construct(string $verificationStatus) | ||
{ | ||
$allowed = [self::unverified, self::verified, self::in_process]; | ||
if (!in_array($verificationStatus, $allowed)) { | ||
throw new InvalidArgumentException(sprintf('unknown verification status %s, use one of %s', $verificationStatus, implode(', ', $allowed))); | ||
} | ||
$this->value = $verificationStatus; | ||
} | ||
|
||
public function __toString() | ||
{ | ||
return $this->value; | ||
} | ||
|
||
public static function unverified(): self | ||
{ | ||
return new self(self::unverified); | ||
} | ||
|
||
public static function verified(): self | ||
{ | ||
return new self(self::verified); | ||
} | ||
|
||
public static function inProcess(): self | ||
{ | ||
return new self(self::in_process); | ||
} | ||
|
||
public function equals(self $status): bool | ||
{ | ||
return $this->value === (string)$status; | ||
} | ||
|
||
public function isUnverified(): bool | ||
{ | ||
return $this->value === self::unverified; | ||
} | ||
|
||
public function isVerified(): bool | ||
{ | ||
return $this->value === self::verified; | ||
} | ||
|
||
public function isInProcess(): bool | ||
{ | ||
return $this->value === self::in_process; | ||
} | ||
} |
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,52 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace B24io\Loyalty\SDK\Tests\Unit\Common; | ||
|
||
use B24io\Loyalty\SDK\Common\VerificationStatus; | ||
use B24io\Loyalty\SDK\Core\Exceptions\InvalidArgumentException; | ||
use Generator; | ||
use PHPUnit\Framework\TestCase; | ||
use Throwable; | ||
|
||
class VerificationStatusTest extends TestCase | ||
{ | ||
/** | ||
* @param string $verificationStatus | ||
* @param Throwable|null $throwable | ||
* @return void | ||
* @throws InvalidArgumentException | ||
* @dataProvider verificationStatusesDataProvider | ||
*/ | ||
public function testConstruct(string $verificationStatus, ?Throwable $throwable): void | ||
{ | ||
if ($throwable instanceof Throwable) { | ||
$this->expectException(get_class($throwable)); | ||
} | ||
|
||
$status = new VerificationStatus($verificationStatus); | ||
|
||
$this->assertEquals((string)$status, $verificationStatus); | ||
} | ||
|
||
public static function verificationStatusesDataProvider(): Generator | ||
{ | ||
yield 'unverified' => [ | ||
'unverified', | ||
null | ||
]; | ||
yield 'verified' => [ | ||
'verified', | ||
null | ||
]; | ||
yield 'in_process' => [ | ||
'in_process', | ||
null | ||
]; | ||
yield 'unknown_state' => [ | ||
'unknown_state', | ||
new InvalidArgumentException() | ||
]; | ||
} | ||
} |