-
Notifications
You must be signed in to change notification settings - Fork 169
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
162 additions
and
102 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<files psalm-version="4.4.1@9fd7a7d885b3a216cff8dec9d8c21a132f275224"> | ||
<file src="src/EventListener/ConsoleCommandListener.php"> | ||
<InvalidExtendClass occurrences="1"> | ||
<code>ConsoleListener</code> | ||
</InvalidExtendClass> | ||
<MethodSignatureMismatch occurrences="1"> | ||
<code>public function __construct(HubInterface $hub)</code> | ||
</MethodSignatureMismatch> | ||
</file> | ||
</files> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,115 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Sentry\SentryBundle\Tests\EventListener; | ||
|
||
use PHPUnit\Framework\MockObject\MockObject; | ||
use PHPUnit\Framework\TestCase; | ||
use Sentry\Event; | ||
use Sentry\SentryBundle\EventListener\ConsoleListener; | ||
use Sentry\State\HubInterface; | ||
use Sentry\State\Scope; | ||
use Symfony\Component\Console\Command\Command; | ||
use Symfony\Component\Console\Event\ConsoleCommandEvent; | ||
use Symfony\Component\Console\Event\ConsoleErrorEvent; | ||
use Symfony\Component\Console\Event\ConsoleTerminateEvent; | ||
use Symfony\Component\Console\Input\InputInterface; | ||
use Symfony\Component\Console\Output\OutputInterface; | ||
|
||
abstract class AbstractConsoleListenerTest extends TestCase | ||
{ | ||
/** | ||
* @var MockObject&HubInterface | ||
*/ | ||
private $hub; | ||
|
||
/** | ||
* @var ConsoleListener | ||
*/ | ||
private $listener; | ||
|
||
protected function setUp(): void | ||
{ | ||
$listenerClass = static::getListenerClass(); | ||
|
||
$this->hub = $this->createMock(HubInterface::class); | ||
$this->listener = new $listenerClass($this->hub); | ||
} | ||
|
||
/** | ||
* @dataProvider handleConsoleCommmandEventDataProvider | ||
* | ||
* @param array<string, string> $expectedTags | ||
*/ | ||
public function testHandleConsoleCommandEvent(ConsoleCommandEvent $consoleEvent, array $expectedTags): void | ||
{ | ||
$scope = new Scope(); | ||
|
||
$this->hub->expects($this->once()) | ||
->method('pushScope') | ||
->willReturn($scope); | ||
|
||
$this->listener->handleConsoleCommandEvent($consoleEvent); | ||
|
||
$event = $scope->applyToEvent(Event::createEvent()); | ||
|
||
$this->assertSame($expectedTags, $event->getTags()); | ||
} | ||
|
||
/** | ||
* @return \Generator<mixed> | ||
*/ | ||
public function handleConsoleCommmandEventDataProvider(): \Generator | ||
{ | ||
yield [ | ||
new ConsoleCommandEvent(null, $this->createMock(InputInterface::class), $this->createMock(OutputInterface::class)), | ||
[], | ||
]; | ||
|
||
yield [ | ||
new ConsoleCommandEvent(new Command(), $this->createMock(InputInterface::class), $this->createMock(OutputInterface::class)), | ||
[], | ||
]; | ||
|
||
yield [ | ||
new ConsoleCommandEvent(new Command('foo:bar'), $this->createMock(InputInterface::class), $this->createMock(OutputInterface::class)), | ||
['console.command' => 'foo:bar'], | ||
]; | ||
} | ||
|
||
public function testHandleConsoleTerminateEvent(): void | ||
{ | ||
$this->hub->expects($this->once()) | ||
->method('popScope'); | ||
|
||
$this->listener->handleConsoleTerminateEvent(new ConsoleTerminateEvent(new Command(), $this->createMock(InputInterface::class), $this->createMock(OutputInterface::class), 0)); | ||
} | ||
|
||
public function testHandleConsoleErrorEvent(): void | ||
{ | ||
$scope = new Scope(); | ||
$consoleEvent = new ConsoleErrorEvent($this->createMock(InputInterface::class), $this->createMock(OutputInterface::class), new \Exception()); | ||
|
||
$this->hub->expects($this->once()) | ||
->method('configureScope') | ||
->willReturnCallback(static function (callable $callback) use ($scope): void { | ||
$callback($scope); | ||
}); | ||
|
||
$this->hub->expects($this->once()) | ||
->method('captureException') | ||
->with($consoleEvent->getError()); | ||
|
||
$this->listener->handleConsoleErrorEvent($consoleEvent); | ||
|
||
$event = $scope->applyToEvent(Event::createEvent()); | ||
|
||
$this->assertSame(['console.command.exit_code' => '1'], $event->getTags()); | ||
} | ||
|
||
/** | ||
* @return class-string<ConsoleListener> | ||
*/ | ||
abstract protected static function getListenerClass(): string; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Sentry\SentryBundle\Tests\EventListener; | ||
|
||
use Sentry\SentryBundle\EventListener\ConsoleCommandListener; | ||
|
||
/** | ||
* @group legacy | ||
* | ||
* @deprecated since version 4.1, to be removed in 5.0 | ||
*/ | ||
final class ConsoleCommandListenerTest extends AbstractConsoleListenerTest | ||
{ | ||
/** | ||
* {@inheritdoc} | ||
*/ | ||
protected static function getListenerClass(): string | ||
{ | ||
return ConsoleCommandListener::class; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters