Completed
Push — master ( 2eebbc...f22af2 )
by Dmitry
01:57
created

testSetOptionThrowsExceptionWithoutIgnoreFlag()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 5
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 3
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
    public function testSetOptionDoNotThrowsExceptionWithIgnoreFlag()
23
    {
24
        $mock = $this->buildConfigurableClass();
25
        $mock->setOptions(['incorrectName' => 100], true);
26
    }
27
28
29
    public function testUseSetterIfExist()
30
    {
31
        $mock = $this->buildConfigurableClass();
32
        $mock->setOptions(['withSetterProperty' => 2]);
33
        $this->assertEquals($mock->withSetterProperty, 3);  // Setter logic: 2 + 1
34
    }
35
36
    public function testInitPublicProperty()
37
    {
38
        $mock = $this->buildConfigurableClass();
39
        $mock->setOptions(['withoutSetterProperty' => 2]);
40
        $this->assertEquals($mock->withoutSetterProperty, 2);
41
    }
42
43
44
    protected function buildConfigurableClass()
45
    {
46
        return new MockClassForTestingConfigurableTrait();
47
    }
48
}
49
50
class MockClassForTestingConfigurableTrait
0 ignored issues
show
Coding Style Compatibility introduced by
PSR1 recommends that each class should be in its own file to aid autoloaders.

Having each class in a dedicated file usually plays nice with PSR autoloaders and is therefore a well established practice. If you use other autoloaders, you might not want to follow this rule.

Loading history...
51
{
52
    use ConfigurableTrait;
53
54
    public $withoutSetterProperty;
55
    public $withSetterProperty;
56
57
    public function setWithSetterProperty($value)
58
    {
59
        $this->withSetterProperty = $value + 1;
60
    }
61
}