Passed
Pull Request — master (#407)
by Kirill
05:29
created

ClassBasedTraitTest::setUp()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

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