mirror of
https://github.com/opdavies/glassboxx-sdk-php.git
synced 2025-02-17 22:50:48 +00:00
Merge b728750543 into 40c4f5f603
This commit is contained in:
commit
d5cd6a7780
3 changed files with 55 additions and 0 deletions
|
|
@ -12,6 +12,7 @@
|
|||
"minimum-stability": "stable",
|
||||
"require": {
|
||||
"ext-json": "*",
|
||||
"beberlei/assert": "^3.2",
|
||||
"symfony/http-client": "^5.0"
|
||||
},
|
||||
"autoload": {
|
||||
|
|
|
|||
|
|
@ -4,6 +4,8 @@ declare(strict_types=1);
|
|||
|
||||
namespace Opdavies\Glassboxx;
|
||||
|
||||
use Assert\Assert;
|
||||
|
||||
class Config
|
||||
{
|
||||
/** @var int $vendorId */
|
||||
|
|
@ -20,6 +22,12 @@ class Config
|
|||
string $username,
|
||||
string $password
|
||||
) {
|
||||
Assert::that($vendorId)
|
||||
->greaterOrEqualThan(1, 'Vendor ID cannot be a negative number');
|
||||
|
||||
Assert::that($username)->notEmpty('Username cannot be empty');
|
||||
Assert::that($password)->notEmpty('Password cannot be empty');
|
||||
|
||||
$this->password = $password;
|
||||
$this->username = $username;
|
||||
$this->vendorId = $vendorId;
|
||||
|
|
|
|||
|
|
@ -4,6 +4,7 @@ declare(strict_types=1);
|
|||
|
||||
namespace Opdavies\Glassboxx\Tests;
|
||||
|
||||
use Assert\AssertionFailedException;
|
||||
use Opdavies\Glassboxx\Config;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
|
|
@ -21,4 +22,49 @@ class ConfigTest extends TestCase
|
|||
$this->assertSame('opdavies', $config->getUsername());
|
||||
$this->assertSame('secret', $config->getPassword());
|
||||
}
|
||||
|
||||
public function badCreateDataProvider(): array
|
||||
{
|
||||
return [
|
||||
'Negative vendor ID' => [
|
||||
'vendor id' => -1,
|
||||
'username' => 'user',
|
||||
'password' => 'secret',
|
||||
'message' => 'Vendor ID cannot be a negative number',
|
||||
],
|
||||
'Username is an empty string' => [
|
||||
'vendor id' => 123,
|
||||
'username' => '',
|
||||
'password' => 'secret',
|
||||
'message' => 'Username cannot be empty',
|
||||
],
|
||||
'Password is an empty string' => [
|
||||
'vendor id' => 123,
|
||||
'username' => 'user',
|
||||
'password' => '',
|
||||
'message' => 'Password cannot be empty',
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider badCreateDataProvider
|
||||
*
|
||||
* @param int $vendorId
|
||||
* @param string $username
|
||||
* @param string $password
|
||||
* @param string $message
|
||||
*/
|
||||
public function testThatAnExceptionIsThrownWhenBadData(
|
||||
int $vendorId,
|
||||
string $username,
|
||||
string $password,
|
||||
string $message
|
||||
) {
|
||||
$this->expectException(AssertionFailedException::class);
|
||||
$this->expectExceptionMessage($message);
|
||||
|
||||
new Config($vendorId, $username, $password);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue