1 | <?php |
||
2 | |||
3 | declare(strict_types=1); |
||
4 | |||
5 | /* |
||
6 | * This file is part of Ekino New Relic bundle. |
||
7 | * |
||
8 | * (c) Ekino - Thomas Rabaix <[email protected]> |
||
9 | * |
||
10 | * For the full copyright and license information, please view the LICENSE |
||
11 | * file that was distributed with this source code. |
||
12 | */ |
||
13 | |||
14 | namespace Ekino\NewRelicBundle\Tests\NewRelic; |
||
15 | |||
16 | use Ekino\NewRelicBundle\NewRelic\LoggingInteractorDecorator; |
||
17 | use Ekino\NewRelicBundle\NewRelic\NewRelicInteractorInterface; |
||
18 | use PHPUnit\Framework\TestCase; |
||
0 ignored issues
–
show
|
|||
19 | use Psr\Log\LoggerInterface; |
||
20 | |||
21 | class LoggingInteractorDecoratorTest extends TestCase |
||
22 | { |
||
23 | /** |
||
24 | * @dataProvider provideMethods |
||
25 | */ |
||
26 | public function testGeneric(string $method, array $arguments, $return) |
||
27 | { |
||
28 | $logger = $this->createMock(LoggerInterface::class); |
||
29 | $decorated = $this->createMock(LoggingInteractorDecorator::class); |
||
30 | $interactor = new LoggingInteractorDecorator($decorated, $logger); |
||
31 | |||
32 | $logger->expects($this->once())->method('debug'); |
||
33 | $call = $decorated->expects($this->once())->method($method) |
||
34 | ->with(...$arguments); |
||
35 | if (null !== $return) { |
||
36 | $call->willReturn($return); |
||
37 | } |
||
38 | |||
39 | $result = $interactor->$method(...$arguments); |
||
40 | |||
41 | $this->assertSame($return, $result); |
||
42 | } |
||
43 | |||
44 | public function provideMethods() |
||
45 | { |
||
46 | $reflection = new \ReflectionClass(NewRelicInteractorInterface::class); |
||
47 | foreach ($reflection->getMethods() as $method) { |
||
48 | if (!$method->isPublic()) { |
||
49 | continue; |
||
50 | } |
||
51 | if ($method->isStatic()) { |
||
52 | continue; |
||
53 | } |
||
54 | |||
55 | $arguments = \array_map(function (\ReflectionParameter $parameter) { |
||
56 | return $this->getTypeStub($parameter->getType()); |
||
57 | }, $method->getParameters()); |
||
58 | |||
59 | $return = $method->hasReturnType() ? $this->getTypeStub($method->getReturnType()) : null; |
||
60 | |||
61 | yield [$method->getName(), $arguments, $return]; |
||
62 | } |
||
63 | } |
||
64 | |||
65 | private function getTypeStub(?\ReflectionType $type) |
||
66 | { |
||
67 | if (null === $type) { |
||
68 | return \uniqid('', true); |
||
69 | } |
||
70 | |||
71 | switch ($type->getName()) { |
||
72 | case 'string': |
||
73 | return \uniqid('', true); |
||
74 | case 'bool': |
||
75 | return (bool) \rand(0, 1); |
||
76 | case 'float': |
||
77 | return \rand(0, 100) / \rand(1, 10); |
||
78 | case 'int': |
||
79 | return \rand(0, 100); |
||
80 | case 'void': |
||
81 | return null; |
||
82 | case 'Throwable': |
||
83 | return new \Exception(); |
||
84 | case 'callable': |
||
85 | return function () {}; |
||
86 | case 'array': |
||
87 | return \array_fill(0, 2, \uniqid('', true)); |
||
88 | default: |
||
89 | throw new \UnexpectedValueException('Unknown type. '.$type->getName()); |
||
90 | } |
||
91 | } |
||
92 | } |
||
93 |
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:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths