Completed
Push — master ( 49f631...00219d )
by Frank
03:48
created

CredentialsTest   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 33
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 0
Metric Value
wmc 4
lcom 1
cbo 2
dl 0
loc 33
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A credentialsDataProvider() 0 9 1
A objectCanBeCreated() 0 12 3
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