Skip to content

Commit

Permalink
Add VerificationStatus functionality and associated tests
Browse files Browse the repository at this point in the history
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
b24io-sdk committed Jul 8, 2024
1 parent f0d0d2b commit 861b0b2
Show file tree
Hide file tree
Showing 5 changed files with 146 additions and 1 deletion.
23 changes: 23 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,28 @@
# loyalty-php-sdk

## 3.4.0 Upcoming

### Added
* add support for email account for contacts


## 3.3.0 (2024.07.10)

### Added

* add `MobilePhoneItemResult` – information about mobile phone.
* add support for mobile phone for `ContactItemResult`
* add support for mobile phone for `CardItemResult`

### Changed

* change signature for method `Loyalty\SDK\Services\Admin\Contacts::add`, argument `$mobilePhone` can be nullable.

## 3.2.0 (2024.05.23)

* Downgrade branch v3 to `PHP 7.4`
* Bump branch v4 to `PHP 8.2`

## 3.1.0 (2024.05.11)

* add requirements:
Expand Down
67 changes: 67 additions & 0 deletions src/Common/VerificationStatus.php
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;
}
}
2 changes: 1 addition & 1 deletion src/Core/ApiClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ public function getResponse(
$this->logger->info(
'getResponse.start',
[
'context' => $context,
'context' => (string)$context,
'apiMethod' => $apiMethod,
'domainUrl' => $this->credentials->domainUrl,
'parameters' => $parameters,
Expand Down
3 changes: 3 additions & 0 deletions src/Core/Result/AbstractItem.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
use DateTimeImmutable;
use Exception;
use IteratorAggregate;
use libphonenumber\PhoneNumberUtil;
use Money\Currencies\ISOCurrencies;
use Money\Parser\DecimalMoneyParser;
use Symfony\Component\Uid\Uuid;
Expand All @@ -25,6 +26,7 @@ abstract class AbstractItem implements IteratorAggregate
*/
protected array $data;
protected DecimalMoneyParser $decimalMoneyParser;
protected PhoneNumberUtil $phoneNumberUtil;

/**
* @param array<string, mixed> $data
Expand All @@ -33,6 +35,7 @@ public function __construct(array $data)
{
$this->data = $data;
$this->decimalMoneyParser = new DecimalMoneyParser(new ISOCurrencies());
$this->phoneNumberUtil = PhoneNumberUtil::getInstance();
}

/**
Expand Down
52 changes: 52 additions & 0 deletions tests/Unit/Common/VerificationStatusTest.php
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()
];
}
}

0 comments on commit 861b0b2

Please sign in to comment.