-
-
Notifications
You must be signed in to change notification settings - Fork 186
/
CommandInfoInBreadcrumbsTest.php
68 lines (51 loc) · 1.98 KB
/
CommandInfoInBreadcrumbsTest.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
<?php
namespace Sentry\Laravel\Tests;
use Illuminate\Console\Events\CommandStarting;
use Symfony\Component\Console\Input\ArgvInput;
use Symfony\Component\Console\Output\BufferedOutput;
class CommandInfoInBreadcrumbsTest extends SentryLaravelTestCase
{
public function testCommandInfoAreRecordedWhenEnabled()
{
if ($this->shouldSkip()) {
$this->markTestSkipped('Laravel version <5.5 does not contain the events tested.');
}
$this->resetApplicationWithConfig([
'sentry.breadcrumbs.command_info' => true,
]);
$this->assertTrue($this->app['config']->get('sentry.breadcrumbs.command_info'));
$this->dispatchCommandStartEvent();
$lastBreadcrumb = $this->getLastBreadcrumb();
$this->assertEquals('Starting Artisan command: test:command', $lastBreadcrumb->getMessage());
$this->assertEquals('--foo=bar', $lastBreadcrumb->getMetadata()['input']);
}
public function testCommandInfoAreRecordedWhenDisabled()
{
if ($this->shouldSkip()) {
$this->markTestSkipped('Laravel version <5.5 does not contain the events tested.');
}
$this->resetApplicationWithConfig([
'sentry.breadcrumbs.command_info' => false,
]);
$this->assertFalse($this->app['config']->get('sentry.breadcrumbs.command_info'));
$this->dispatchCommandStartEvent();
$this->assertEmpty($this->getCurrentBreadcrumbs());
}
private function dispatchCommandStartEvent()
{
$dispatcher = $this->app['events'];
$method = method_exists($dispatcher, 'dispatch') ? 'dispatch' : 'fire';
$this->app['events']->$method(
CommandStarting::class,
new CommandStarting(
'test:command',
new ArgvInput(['artisan', '--foo=bar']),
new BufferedOutput()
)
);
}
private function shouldSkip()
{
return !class_exists(CommandStarting::class);
}
}