MockClassForTestingConfigurableTrait   A
last analyzed

Complexity

Total Complexity 1

Size/Duplication

Total Lines 12
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Importance

Changes 0
Metric Value
wmc 1
lcom 0
cbo 1
dl 0
loc 12
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A setWithSetterProperty() 0 4 1
1
<?php
2
/**
3
 * @author Dmitry Gladyshev <[email protected]>
4
 */
5
6
namespace Rucaptcha\Test;
7
8
use PHPUnit\Framework\TestCase;
9
use Rucaptcha\ConfigurableTrait;
10
11
class ConfigurableTraitTest extends TestCase
12
{
13
    /**
14
     * @expectedException \Rucaptcha\Exception\InvalidArgumentException
15
     */
16
    public function testSetOptionThrowsExceptionWithoutIgnoreFlag()
17
    {
18
        $mock = $this->buildConfigurableClass();
19
        $mock->setOptions(['incorrectName' => 100], false);
20
    }
21
22
23
    public function testUseSetterIfExist()
24
    {
25
        $mock = $this->buildConfigurableClass();
26
        $mock->setOptions(['withSetterProperty' => 2]);
27
        $this->assertEquals($mock->withSetterProperty, 3);  // Setter logic: 2 + 1
28
    }
29
30
    public function testInitPublicProperty()
31
    {
32
        $mock = $this->buildConfigurableClass();
33
        $mock->setOptions(['withoutSetterProperty' => 2]);
34
        $this->assertEquals($mock->withoutSetterProperty, 2);
35
    }
36
37
38
    protected function buildConfigurableClass()
39
    {
40
        return new MockClassForTestingConfigurableTrait();
41
    }
42
}
43
44
class MockClassForTestingConfigurableTrait
45
{
46
    use ConfigurableTrait;
47
48
    public $withoutSetterProperty;
49
    public $withSetterProperty;
50
51
    public function setWithSetterProperty($value)
52
    {
53
        $this->withSetterProperty = $value + 1;
54
    }
55
}