1 | <?php |
||
2 | |||
3 | /* |
||
4 | * This file is part of Ekino New Relic bundle. |
||
5 | * |
||
6 | * (c) Ekino - Thomas Rabaix <[email protected]> |
||
7 | * |
||
8 | * For the full copyright and license information, please view the LICENSE |
||
9 | * file that was distributed with this source code. |
||
10 | */ |
||
11 | |||
12 | namespace Ekino\Bundle\NewRelicBundle\Tests\Listener; |
||
13 | |||
14 | use Ekino\Bundle\NewRelicBundle\Exception\ThrowableException; |
||
0 ignored issues
–
show
|
|||
15 | use Ekino\Bundle\NewRelicBundle\Listener\CommandListener; |
||
16 | use Ekino\Bundle\NewRelicBundle\NewRelic\NewRelic; |
||
17 | use Ekino\Bundle\NewRelicBundle\NewRelic\NewRelicInteractorInterface; |
||
18 | use PHPUnit\Framework\TestCase; |
||
19 | use Symfony\Component\Console\Command\Command; |
||
20 | use Symfony\Component\Console\Event\ConsoleCommandEvent; |
||
21 | use Symfony\Component\Console\Event\ConsoleErrorEvent; |
||
22 | use Symfony\Component\Console\Input\ArrayInput; |
||
23 | use Symfony\Component\Console\Input\InputArgument; |
||
24 | use Symfony\Component\Console\Input\InputDefinition; |
||
25 | use Symfony\Component\Console\Input\InputOption; |
||
26 | use Symfony\Component\Console\Output\OutputInterface; |
||
27 | |||
28 | class CommandListenerTest extends TestCase |
||
29 | { |
||
30 | public function testCommandMarkedAsBackgroundJob() |
||
31 | { |
||
32 | if (!class_exists('Symfony\Component\Console\Event\ConsoleCommandEvent')) { |
||
33 | $this->markTestSkipped('Console Events is only available from Symfony 2.3'); |
||
34 | } |
||
35 | |||
36 | $parameters = array( |
||
37 | '--foo' => true, |
||
38 | '--foobar' => array('baz', 'baz_2'), |
||
39 | 'name' => 'bar', |
||
40 | ); |
||
41 | |||
42 | $definition = new InputDefinition(array( |
||
43 | new InputOption('foo'), |
||
44 | new InputOption('foobar', 'fb', InputOption::VALUE_REQUIRED | InputOption::VALUE_IS_ARRAY), |
||
45 | new InputArgument('name', InputArgument::REQUIRED), |
||
46 | )); |
||
47 | |||
48 | $interactor = $this->getMockBuilder(NewRelicInteractorInterface::class)->getMock(); |
||
49 | $interactor->expects($this->once())->method('setTransactionName')->with($this->equalTo('test:newrelic')); |
||
50 | $interactor->expects($this->once())->method('enableBackgroundJob'); |
||
51 | |||
52 | $interactor->expects($this->at(3))->method('addCustomParameter')->with('--foo', true); |
||
53 | $interactor->expects($this->at(4))->method('addCustomParameter')->with('--foobar[0]', 'baz'); |
||
54 | $interactor->expects($this->at(5))->method('addCustomParameter')->with('--foobar[1]', 'baz_2'); |
||
55 | $interactor->expects($this->at(6))->method('addCustomParameter')->with('name', 'bar'); |
||
56 | |||
57 | $command = new Command('test:newrelic'); |
||
58 | $input = new ArrayInput($parameters, $definition); |
||
59 | |||
60 | $output = $this->getMockBuilder(OutputInterface::class)->getMock(); |
||
61 | |||
62 | $event = new ConsoleCommandEvent($command, $input, $output); |
||
63 | |||
64 | $listener = new CommandListener(new NewRelic('App name', 'Token'), $interactor, array()); |
||
65 | $listener->onConsoleCommand($event); |
||
66 | } |
||
67 | |||
68 | public function testIgnoreBackgroundJob () |
||
69 | { |
||
70 | $interactor = $this->getMockBuilder(NewRelicInteractorInterface::class)->getMock(); |
||
71 | $interactor->expects($this->never())->method('startTransaction'); |
||
72 | |||
73 | $command = new Command('test:ignored-commnand'); |
||
74 | $input = new ArrayInput(array(), new InputDefinition(array())); |
||
75 | |||
76 | $output = $this->getMockBuilder(OutputInterface::class)->getMock(); |
||
77 | |||
78 | $event = new ConsoleCommandEvent($command, $input, $output); |
||
79 | |||
80 | $listener = new CommandListener(new NewRelic('App name', 'Token'), $interactor, array('test:ignored-command')); |
||
81 | $listener->onConsoleCommand($event); |
||
82 | } |
||
83 | |||
84 | public function testConsoleError() |
||
85 | { |
||
86 | $exception = new \Exception('', 1); |
||
87 | |||
88 | $newrelic = $this->getMockBuilder(NewRelic::class)->disableOriginalConstructor()->getMock(); |
||
89 | $interactor = $this->getMockBuilder(NewRelicInteractorInterface::class)->getMock(); |
||
90 | $interactor->expects($this->once())->method('noticeThrowable')->with($exception); |
||
91 | |||
92 | $command = new Command('test:exception'); |
||
93 | |||
94 | $input = new ArrayInput(array(), new InputDefinition(array())); |
||
95 | $output = $this->getMockBuilder(OutputInterface::class)->getMock(); |
||
96 | |||
97 | |||
98 | $event = new ConsoleErrorEvent($input, $output, $exception, $command); |
||
99 | |||
100 | $listener = new CommandListener($newrelic, $interactor, array('test:exception')); |
||
101 | $listener->onConsoleError($event); |
||
102 | } |
||
103 | |||
104 | public function testConsoleErrorsWithThrowable() |
||
105 | { |
||
106 | $exception = new \Error(); |
||
107 | |||
108 | $newrelic = $this->getMockBuilder(NewRelic::class)->disableOriginalConstructor()->getMock(); |
||
109 | $interactor = $this->getMockBuilder(NewRelicInteractorInterface::class)->getMock(); |
||
110 | $interactor->expects($this->once())->method('noticeThrowable')->with($exception); |
||
111 | $command = new Command('test:exception'); |
||
112 | |||
113 | $input = new ArrayInput(array(), new InputDefinition(array())); |
||
114 | $output = $this->getMockBuilder(OutputInterface::class)->getMock(); |
||
115 | |||
116 | $event = new ConsoleErrorEvent($input, $output, $exception, $command); |
||
117 | |||
118 | $listener = new CommandListener($newrelic, $interactor, array('test:exception')); |
||
119 | $listener->onConsoleError($event); |
||
120 | } |
||
121 | } |
||
122 |
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