InitializationTest   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 44
Duplicated Lines 0 %

Importance

Changes 1
Bugs 1 Features 0
Metric Value
wmc 5
eloc 9
c 1
b 1
f 0
dl 0
loc 44
rs 10

5 Methods

Rating   Name   Duplication   Size   Complexity  
A testShouldNotInitializeWithInvalidClassName() 0 7 1
A invalidClassNameProvider() 0 3 1
A testShouldInitializeWithObjectAndClassName() 0 7 1
A testShouldNotInitializeWithNonObjectAndClassName() 0 7 1
A invalidObjectProvider() 0 3 1
1
<?php
2
3
namespace Exsio\PhpObjectDecorator\Tests;
4
5
use Exsio\PhpObjectDecorator\PhpObjectDecorator;
6
use Exsio\PhpObjectDecorator\PhpObjectDecoratorException;
7
use Exsio\PhpObjectDecorator\Tests\Fixtures\ChildObjectToDecorate;
8
use PHPUnit\Framework\TestCase;
9
10
class InitializationTest extends TestCase
11
{
12
13
    public function testShouldInitializeWithObjectAndClassName()
14
    {
15
        //when:
16
        PhpObjectDecorator::decorate(new ChildObjectToDecorate());
17
18
        //then:
19
        $this->assertTrue(true);
20
    }
21
22
    /**
23
     * @dataProvider invalidClassNameProvider
24
     */
25
    public function testShouldNotInitializeWithNonObjectAndClassName(mixed $obj)
26
    {
27
        //expect:
28
        $this->expectException(PhpObjectDecoratorException::class);
29
30
        //when:
31
        PhpObjectDecorator::decorate($obj);
32
    }
33
34
    /**
35
     * @dataProvider invalidClassNameProvider
36
     */
37
    public function testShouldNotInitializeWithInvalidClassName(mixed $className)
38
    {
39
        //expect:
40
        $this->expectException(PhpObjectDecoratorException::class);
41
42
        //when:
43
        PhpObjectDecorator::decorate(new ChildObjectToDecorate())->withClassName($className);
44
    }
45
46
    public function invalidObjectProvider(): array
47
    {
48
        return [["string"], [[]], [10], [true], [null], [new \stdClass()]];
49
    }
50
51
    public function invalidClassNameProvider(): array
52
    {
53
        return [[""]];
54
    }
55
56
57
}