Passed
Pull Request — master (#407)
by Kirill
06:33
created

ClassBasedTraitTest   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 42
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 12
c 1
b 0
f 0
dl 0
loc 42
rs 10
wmc 4

4 Methods

Rating   Name   Duplication   Size   Complexity  
A setUp() 0 5 1
A testGetClass() 0 5 1
A testSetClass() 0 3 1
A testSetClassFailed() 0 10 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Spiral\Tests\Storage\Unit\Config\DTO\Traits;
6
7
use Spiral\Storage\Exception\StorageException;
8
use Spiral\Tests\Storage\Unit\UnitTestCase;
9
use Spiral\Storage\Config\DTO\Traits\ClassBasedTrait;
10
11
class ClassBasedTraitTest extends UnitTestCase
12
{
13
    /**
14
     * @var ClassBasedTrait
15
     */
16
    private $trait;
17
18
    protected function setUp(): void
19
    {
20
        parent::setUp();
21
22
        $this->trait = $this->getMockForTrait(ClassBasedTrait::class);
0 ignored issues
show
Documentation Bug introduced by
It seems like $this->getMockForTrait(S...ClassBasedTrait::class) of type PHPUnit\Framework\MockObject\MockObject is incompatible with the declared type Spiral\Storage\Config\DTO\Traits\ClassBasedTrait of property $trait.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
23
    }
24
25
    /**
26
     * @throws StorageException
27
     */
28
    public function testSetClass(): void
29
    {
30
        $this->assertInstanceOf(get_class($this->trait), $this->trait->setClass(static::class));
31
    }
32
33
    public function testSetClassFailed(): void
34
    {
35
        $wrongClass = static::class . 1;
36
37
        $this->expectException(StorageException::class);
38
        $this->expectExceptionMessage(
39
            \sprintf('Class `%s` not exists. %s', $wrongClass, '')
40
        );
41
42
        $this->trait->setClass($wrongClass);
43
    }
44
45
    /**
46
     * @throws StorageException
47
     */
48
    public function testGetClass(): void
49
    {
50
        $this->trait->setClass(static::class);
51
52
        $this->assertEquals(static::class, $this->trait->getClass());
53
    }
54
}
55