Completed
Push — master ( bf8f9b...649baf )
by Kirill
32s queued 23s
created

src/Prototype/tests/TraitTest.php (3 issues)

Labels
Severity
1
<?php
2
3
/**
4
 * Spiral Framework.
5
 *
6
 * @license   MIT
7
 * @author    Anton Titov (Wolfy-J)
8
 */
9
10
declare(strict_types=1);
11
12
namespace Spiral\Tests\Prototype;
13
14
use PHPUnit\Framework\TestCase;
15
use Spiral\Core\Container;
16
use Spiral\Core\ContainerScope;
17
use Spiral\Core\Exception\ScopeException;
18
use Spiral\Prototype\Exception\PrototypeException;
19
use Spiral\Prototype\PrototypeRegistry;
20
use Spiral\Tests\Prototype\Fixtures\TestClass;
21
22
class TraitTest extends TestCase
23
{
24
    public function testNoScope(): void
25
    {
26
        $this->expectException(ScopeException::class);
27
28
        $t = new TestClass();
29
        $t->getTest();
30
    }
31
32
    public function testNoScopeBound(): void
33
    {
34
        $this->expectException(ScopeException::class);
35
36
        $t = new TestClass();
37
38
        $c = new Container();
39
40
        ContainerScope::runScope($c, static function () use ($t): void {
41
            $t->getTest();
42
        });
43
    }
44
45
    public function testCascade(): void
46
    {
47
        $this->expectException(PrototypeException::class);
48
49
        $t = new TestClass();
50
        $c = new Container();
51
        $c->bindSingleton(PrototypeRegistry::class, $p = new PrototypeRegistry($c));
0 ignored issues
show
$p = new Spiral\Prototype\PrototypeRegistry($c) of type Spiral\Prototype\PrototypeRegistry is incompatible with the type array|callable|string expected by parameter $resolver of Spiral\Core\Container::bindSingleton(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

51
        $c->bindSingleton(PrototypeRegistry::class, /** @scrutinizer ignore-type */ $p = new PrototypeRegistry($c));
Loading history...
52
        $p->bindProperty('testClass', 'Invalid');
53
54
        ContainerScope::runScope($c, static function () use ($t): void {
55
            $t->getTest();
56
        });
57
    }
58
59
    public function testOK(): void
60
    {
61
        $t = new TestClass();
62
        $c = new Container();
63
        $c->bindSingleton(PrototypeRegistry::class, $p = new PrototypeRegistry($c));
0 ignored issues
show
$p = new Spiral\Prototype\PrototypeRegistry($c) of type Spiral\Prototype\PrototypeRegistry is incompatible with the type array|callable|string expected by parameter $resolver of Spiral\Core\Container::bindSingleton(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

63
        $c->bindSingleton(PrototypeRegistry::class, /** @scrutinizer ignore-type */ $p = new PrototypeRegistry($c));
Loading history...
64
        $c->bindSingleton(TestClass::class, $t);
0 ignored issues
show
$t of type Spiral\Tests\Prototype\Fixtures\TestClass is incompatible with the type array|callable|string expected by parameter $resolver of Spiral\Core\Container::bindSingleton(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

64
        $c->bindSingleton(TestClass::class, /** @scrutinizer ignore-type */ $t);
Loading history...
65
        $p->bindProperty('testClass', TestClass::class);
66
67
        $r = ContainerScope::runScope($c, static function () use ($t) {
68
            return $t->getTest();
69
        });
70
71
        $this->assertSame($t, $r);
72
    }
73
}
74