testShouldNotInitializeWithInvalidClassName()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

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