Skip to content

Commit d10d2ca

Browse files
committed
add console tests, update controller test
1 parent ec2f89a commit d10d2ca

File tree

9 files changed

+500
-27
lines changed

9 files changed

+500
-27
lines changed
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Sentry\SentryBundle\Command;
6+
7+
use Psr\Log\LoggerInterface;
8+
use Symfony\Component\Console\Command\Command;
9+
use Symfony\Component\Console\Input\InputInterface;
10+
use Symfony\Component\Console\Output\OutputInterface;
11+
12+
class SentryBreadcrumbTestCommand extends Command
13+
{
14+
/**
15+
* @var LoggerInterface
16+
*/
17+
private $logger;
18+
19+
public function __construct(LoggerInterface $logger)
20+
{
21+
parent::__construct('sentry:breadcrumb:test');
22+
$this->logger = $logger;
23+
}
24+
25+
protected function execute(InputInterface $input, OutputInterface $output): int
26+
{
27+
$this->logger->error('Breadcrumb error log line');
28+
29+
throw new \RuntimeException('Breadcrumb error');
30+
}
31+
}
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Sentry\SentryBundle\Command;
6+
7+
use Psr\Log\LoggerInterface;
8+
use Symfony\Component\Console\Command\Command;
9+
use Symfony\Component\Console\Input\InputInterface;
10+
use Symfony\Component\Console\Output\OutputInterface;
11+
12+
class SentryDummyTestCommand extends Command
13+
{
14+
/**
15+
* @var LoggerInterface
16+
*/
17+
private $logger;
18+
19+
public function __construct(LoggerInterface $logger)
20+
{
21+
parent::__construct('sentry:dummy:test');
22+
$this->logger = $logger;
23+
}
24+
25+
protected function execute(InputInterface $input, OutputInterface $output): int
26+
{
27+
$this->logger->error('This is a dummy message');
28+
29+
return 0;
30+
}
31+
}
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Sentry\SentryBundle\Command;
6+
7+
use Psr\Log\LoggerInterface;
8+
use Symfony\Component\Console\Command\Command;
9+
use Symfony\Component\Console\Input\ArrayInput;
10+
use Symfony\Component\Console\Input\InputInterface;
11+
use Symfony\Component\Console\Output\NullOutput;
12+
use Symfony\Component\Console\Output\OutputInterface;
13+
14+
class SentrySubcommandTestCommand extends Command
15+
{
16+
/**
17+
* @var LoggerInterface
18+
*/
19+
private $logger;
20+
21+
/**
22+
* @var Command
23+
*/
24+
private $subcommand;
25+
26+
public function __construct(LoggerInterface $logger, Command $subcommand)
27+
{
28+
parent::__construct('sentry:subcommand:test');
29+
$this->logger = $logger;
30+
$this->subcommand = $subcommand;
31+
}
32+
33+
protected function execute(InputInterface $input, OutputInterface $output): int
34+
{
35+
$this->logger->error('Subcommand will run now');
36+
37+
if (null !== $this->getApplication()) {
38+
$this->getApplication()->doRun(new ArrayInput(['command' => $this->subcommand->getName()]), new NullOutput());
39+
}
40+
41+
$this->logger->error('Breadcrumb after subcommand');
42+
43+
return 0;
44+
}
45+
}

src/EventListener/BufferFlusher.php

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66

77
use Monolog\Handler\BufferHandler;
88
use Symfony\Component\Console\ConsoleEvents;
9+
use Symfony\Component\Console\Event\ConsoleCommandEvent;
10+
use Symfony\Component\Console\Event\ConsoleErrorEvent;
911
use Symfony\Component\Console\Event\ConsoleTerminateEvent;
1012
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
1113
use Symfony\Component\HttpKernel\Event\TerminateEvent;
@@ -30,7 +32,9 @@ public static function getSubscribedEvents(): array
3032
{
3133
return [
3234
KernelEvents::TERMINATE => ['onKernelTerminate', 10],
35+
ConsoleEvents::COMMAND => ['onConsoleCommand', 10],
3336
ConsoleEvents::TERMINATE => ['onConsoleTerminate', 10],
37+
ConsoleEvents::ERROR => ['onConsoleError', 10],
3438
];
3539
}
3640

@@ -44,6 +48,16 @@ public function onConsoleTerminate(ConsoleTerminateEvent $event): void
4448
$this->flushBuffers();
4549
}
4650

51+
public function onConsoleError(ConsoleErrorEvent $event): void
52+
{
53+
$this->flushBuffers();
54+
}
55+
56+
public function onConsoleCommand(ConsoleCommandEvent $event): void
57+
{
58+
$this->flushBuffers();
59+
}
60+
4761
private function flushBuffers(): void
4862
{
4963
foreach ($this->bufferHandlers as $handler) {

0 commit comments

Comments
 (0)