ConfigurableTraitTest::testUseSetterIfExist()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 6
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 0
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
}