AccountTests   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 41
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 4

Importance

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

2 Methods

Rating   Name   Duplication   Size   Complexity  
A testAccount() 0 8 1
A testAccountVirtualHosts() 0 20 1
1
<?php
2
3
/**
4
 * admin
5
 *
6
 * @category    Tollwerk
7
 * @package     Tollwerk\Admin
8
 * @subpackage  Tollwerk\Admin\Tests
9
 * @author      Joschi Kuphal <[email protected]> / @jkphl
10
 * @copyright   Copyright © 2018 Joschi Kuphal <[email protected]> / @jkphl
11
 * @license     http://opensource.org/licenses/MIT The MIT License (MIT)
12
 */
13
14
/***********************************************************************************
15
 *  The MIT License (MIT)
16
 *
17
 *  Copyright © 2018 Joschi Kuphal <[email protected]> / @jkphl
18
 *
19
 *  Permission is hereby granted, free of charge, to any person obtaining a copy of
20
 *  this software and associated documentation files (the "Software"), to deal in
21
 *  the Software without restriction, including without limitation the rights to
22
 *  use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
23
 *  the Software, and to permit persons to whom the Software is furnished to do so,
24
 *  subject to the following conditions:
25
 *
26
 *  The above copyright notice and this permission notice shall be included in all
27
 *  copies or substantial portions of the Software.
28
 *
29
 *  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
30
 *  IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
31
 *  FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
32
 *  COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
33
 *  IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
34
 *  CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
35
 ***********************************************************************************/
36
37
namespace Tollwerk\Admin\Tests;
38
39
use PHPUnit\Framework\TestCase;
40
use Tollwerk\Admin\Domain\Account\Account;
41
use Tollwerk\Admin\Domain\Factory\DomainFactory;
42
use Tollwerk\Admin\Domain\Vhost\Vhost;
43
44
/**
45
 * Account tests
46
 *
47
 * @package Tollwerk\Admin
48
 * @subpackage Tollwerk\Admin\Tests
49
 */
50
class AccountTests extends TestCase
51
{
52
    /**
53
     * Test the instatiation of an account
54
     */
55
    public function testAccount()
56
    {
57
        $account = new Account('test');
58
        $this->assertInstanceOf(Account::class, $account);
59
        $this->assertEquals('test', $account->getName());
60
        $this->assertFalse($account->isActive());
61
        $this->assertEquals([], $account->getVhosts());
62
    }
63
64
    /**
65
     * Test the registration of virtual hosts
66
     *
67
     * @expectedException \RuntimeException
68
     * @expectedExceptionCode 1475488477
69
     */
70
    public function testAccountVirtualHosts()
71
    {
72
        $account = new Account('test');
73
        $this->assertInstanceOf(Account::class, $account);
74
75
        $domain = DomainFactory::parseString('example.com');
76
        $vhost = new Vhost($domain, __DIR__);
77
        $this->assertInstanceOf(Vhost::class, $vhost, Vhost::PORT_HTTP_DEFAULT);
78
79
        $account->setActive(true);
80
        $this->assertTrue($account->isActive());
81
82
        $account->setVhosts([$vhost]);
83
        $this->assertEquals([$vhost], $account->getVhosts());
84
        $account->removeVirtualHost($vhost);
85
        $this->assertEquals([], $account->getVhosts());
86
        $account->addVirtualHost($vhost);
87
        $this->assertEquals([$vhost], $account->getVhosts());
88
        $account->setVhosts(['test']);
0 ignored issues
show
Documentation introduced by
array('test') is of type array<integer,string,{"0":"string"}>, but the function expects a array<integer,object<Tol...\Vhost\VhostInterface>>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
89
    }
90
}
91