|
1
|
|
|
<?php |
|
2
|
|
|
declare(strict_types=1); |
|
3
|
|
|
|
|
4
|
|
|
/* |
|
5
|
|
|
* This file is part of the package neoblack/free-at-home-api. |
|
6
|
|
|
* |
|
7
|
|
|
* For the full copyright and license information, please read the |
|
8
|
|
|
* LICENSE file that was distributed with this source code. |
|
9
|
|
|
*/ |
|
10
|
|
|
|
|
11
|
|
|
namespace NeoBlack\FreeAtHomeApi\Test\Unit\Entity; |
|
12
|
|
|
|
|
13
|
|
|
use NeoBlack\FreeAtHomeApi\Entity\Credentials; |
|
14
|
|
|
use NeoBlack\FreeAtHomeApi\Exception\CredentialsException; |
|
15
|
|
|
use PHPUnit\Framework\TestCase; |
|
16
|
|
|
|
|
17
|
|
|
class CredentialsTest extends TestCase |
|
18
|
|
|
{ |
|
19
|
|
|
public function credentialsDataProvider(): array |
|
20
|
|
|
{ |
|
21
|
|
|
return [ |
|
22
|
|
|
'with username and password' => ['username', 'password', null, null], |
|
23
|
|
|
'with username and empty password' => ['username', '', CredentialsException::class, 1536353831], |
|
24
|
|
|
'with empty username and password' => ['', 'password', CredentialsException::class, 1536353801], |
|
25
|
|
|
'with empty username and empty password' => ['', '', CredentialsException::class, 1536353801], |
|
26
|
|
|
]; |
|
27
|
|
|
} |
|
28
|
|
|
|
|
29
|
|
|
/** |
|
30
|
|
|
* @test |
|
31
|
|
|
* @dataProvider credentialsDataProvider |
|
32
|
|
|
* @param string $username |
|
33
|
|
|
* @param string $password |
|
34
|
|
|
* @param string|null $exceptionClass |
|
35
|
|
|
* @param int $exceptionCode |
|
36
|
|
|
*/ |
|
37
|
|
|
public function objectCanBeCreated(string $username, string $password, string $exceptionClass = null, int $exceptionCode = null): void |
|
38
|
|
|
{ |
|
39
|
|
|
if ($exceptionClass !== null) { |
|
40
|
|
|
$this->expectException($exceptionClass); |
|
41
|
|
|
} |
|
42
|
|
|
if ($exceptionCode !== null) { |
|
43
|
|
|
$this->expectExceptionCode($exceptionCode); |
|
44
|
|
|
} |
|
45
|
|
|
$credentials = new Credentials($username, $password); |
|
46
|
|
|
$this->assertSame($username, $credentials->getUsername()); |
|
47
|
|
|
$this->assertSame($password, $credentials->getPassword()); |
|
48
|
|
|
} |
|
49
|
|
|
} |
|
50
|
|
|
|