Completed
Push — master ( 17598f...abee1f )
by Kirill
13s queued 11s
created

ExceptionsTest   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 47
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 23
dl 0
loc 47
rs 10
c 0
b 0
f 0
wmc 5

5 Methods

Rating   Name   Duplication   Size   Complexity  
A testArgumentException() 0 16 1
A testInvalidBinding() 0 7 1
A invalidInjection() 0 2 1
A testClone() 0 5 1
A testInvalidInjectionParameter() 0 7 1
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\Core;
13
14
use PHPUnit\Framework\TestCase;
15
use Psr\Container\ContainerExceptionInterface;
16
use Spiral\Core\Container;
17
use Spiral\Core\Exception\Container\ArgumentException;
18
use Spiral\Core\Exception\Container\AutowireException;
19
use Spiral\Core\Exception\Container\ContainerException;
20
use Spiral\Core\Exception\DependencyException;
21
use Spiral\Core\Exception\LogicException;
22
23
class ExceptionsTest extends TestCase
24
{
25
    public function testInvalidBinding(): void
26
    {
27
        $this->expectExceptionMessage("Invalid binding for 'invalid'");
28
        $this->expectException(\Spiral\Core\Exception\Container\ContainerException::class);
29
        $container = new Container();
30
        $container->bind('invalid', ['invalid']);
31
        $container->get('invalid');
32
    }
33
34
    public function testClone(): void
35
    {
36
        $this->expectException(LogicException::class);
37
        $container = new Container();
38
        clone $container;
39
    }
40
41
    public function testInvalidInjectionParameter(): void
42
    {
43
        $this->expectExceptionMessage("Class Spiral\Tests\Core\InvalidClass does not exist");
44
        $this->expectException(\Spiral\Core\Exception\Container\ContainerException::class);
45
        $container = new Container();
46
47
        $container->resolveArguments(new \ReflectionMethod($this, 'invalidInjection'));
48
    }
49
50
    public function testArgumentException(string $param = null): void
0 ignored issues
show
Unused Code introduced by
The parameter $param is not used and could be removed. ( Ignorable by Annotation )

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

50
    public function testArgumentException(/** @scrutinizer ignore-unused */ string $param = null): void

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
51
    {
52
        $method = new \ReflectionMethod($this, 'testArgumentException');
53
54
        $e = new ArgumentException(
55
            $method->getParameters()[0],
56
            $method
57
        );
58
59
        $this->assertInstanceOf(AutowireException::class, $e);
60
        $this->assertInstanceOf(ContainerException::class, $e);
61
        $this->assertInstanceOf(DependencyException::class, $e);
62
        $this->assertInstanceOf(ContainerExceptionInterface::class, $e);
63
64
        $this->assertSame($method, $e->getContext());
65
        $this->assertSame('param', $e->getParameter()->getName());
66
    }
67
68
    protected function invalidInjection(InvalidClass $class): void
0 ignored issues
show
Unused Code introduced by
The parameter $class is not used and could be removed. ( Ignorable by Annotation )

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

68
    protected function invalidInjection(/** @scrutinizer ignore-unused */ InvalidClass $class): void

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
Bug introduced by
The type Spiral\Tests\Core\InvalidClass was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
69
    {
70
    }
71
}
72