Skip to content

Commit a858026

Browse files
committed
chore(tests): add integration tests for laravel horizon
1 parent ed39176 commit a858026

12 files changed

+404
-0
lines changed
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<?php
2+
3+
/*
4+
* Copyright 2020 New Relic Corporation. All rights reserved.
5+
* SPDX-License-Identifier: Apache-2.0
6+
*/
7+
8+
/* Mock enough bits of Laravel framework to test the HorizonCommand */
9+
10+
namespace Laravel\Horizon\Console {
11+
class HorizonCommand {
12+
public function handle() {
13+
echo "handle function\n";
14+
throw new \Error("Error occurred");
15+
}
16+
}
17+
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<?php
2+
3+
/*
4+
* Copyright 2020 New Relic Corporation. All rights reserved.
5+
* SPDX-License-Identifier: Apache-2.0
6+
*/
7+
8+
/* Mock enough bits of Laravel framework to test the HorizonCommand */
9+
10+
namespace Laravel\Horizon\Console {
11+
class HorizonCommand {
12+
public function handle() {
13+
echo "handle function\n";
14+
throw new \Exception("Error occurred");
15+
}
16+
}
17+
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<?php
2+
3+
/*
4+
* Copyright 2020 New Relic Corporation. All rights reserved.
5+
* SPDX-License-Identifier: Apache-2.0
6+
*/
7+
8+
/* Mock enough bits of Laravel framework to test the HorizonCommand */
9+
10+
namespace Laravel\Horizon\Console {
11+
class HorizonCommand {
12+
public function handle() {
13+
echo "handle function\n";
14+
}
15+
}
16+
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<?php
2+
3+
/*
4+
* Copyright 2020 New Relic Corporation. All rights reserved.
5+
* SPDX-License-Identifier: Apache-2.0
6+
*/
7+
8+
/* Mock enough bits of Laravel framework to test the SupervisorCommand */
9+
10+
namespace Laravel\Horizon\Console {
11+
class SupervisorCommand {
12+
public function handle() {
13+
echo "handle function\n";
14+
throw new \Error("Error occurred");
15+
}
16+
}
17+
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<?php
2+
3+
/*
4+
* Copyright 2020 New Relic Corporation. All rights reserved.
5+
* SPDX-License-Identifier: Apache-2.0
6+
*/
7+
8+
/* Mock enough bits of Laravel framework to test the SupervisorCommand */
9+
10+
namespace Laravel\Horizon\Console {
11+
class SupervisorCommand {
12+
public function handle() {
13+
echo "handle function\n";
14+
throw new \Exception("Error occurred");
15+
}
16+
}
17+
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<?php
2+
3+
/*
4+
* Copyright 2020 New Relic Corporation. All rights reserved.
5+
* SPDX-License-Identifier: Apache-2.0
6+
*/
7+
8+
/* Mock enough bits of Laravel framework to test the SupervisorCommand */
9+
10+
namespace Laravel\Horizon\Console {
11+
class SupervisorCommand {
12+
public function handle() {
13+
echo "handle function\n";
14+
}
15+
}
16+
}
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
<?php
2+
/*
3+
* Copyright 2020 New Relic Corporation. All rights reserved.
4+
* SPDX-License-Identifier: Apache-2.0
5+
*/
6+
7+
/*DESCRIPTION
8+
Ensure that when HorizonCommand::handle is executed, the transaction is properly stopped.
9+
*/
10+
11+
/*INI
12+
newrelic.framework = laravel
13+
*/
14+
15+
/*EXPECT_HARVEST
16+
no
17+
*/
18+
19+
/*EXPECT_TRACED_ERRORS
20+
null
21+
*/
22+
23+
/*EXPECT_ERROR_EVENTS
24+
null
25+
*/
26+
27+
require_once(__DIR__ . '/mock_horizon_error_path.php');
28+
require_once(__DIR__.'/../../../include/integration.php');
29+
30+
use Laravel\Horizon\Console\HorizonCommand;
31+
use NewRelic\Integration\Transaction;
32+
33+
function foobar() {
34+
echo "foobar\n";
35+
}
36+
function get_txn() {
37+
return new Transaction;
38+
}
39+
40+
newrelic_add_custom_tracer('foobar');
41+
foobar();
42+
43+
$txn = get_txn();
44+
foreach ($txn->getTrace()->findSegmentsByName('Custom/foobar') as $segment) {
45+
echo $segment->name;
46+
echo "\n";
47+
}
48+
49+
$horizon = new HorizonCommand();
50+
$horizon->handle();
51+
foobar();
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
<?php
2+
/*
3+
* Copyright 2020 New Relic Corporation. All rights reserved.
4+
* SPDX-License-Identifier: Apache-2.0
5+
*/
6+
7+
/*DESCRIPTION
8+
Ensure that when HorizonCommand::handle is executed, the transaction is properly stopped.
9+
*/
10+
11+
/*INI
12+
newrelic.framework = laravel
13+
*/
14+
15+
/*EXPECT_HARVEST
16+
no
17+
*/
18+
19+
/*EXPECT_TRACED_ERRORS
20+
null
21+
*/
22+
23+
/*EXPECT_ERROR_EVENTS
24+
null
25+
*/
26+
27+
require_once(__DIR__ . '/mock_horizon_exception_path.php');
28+
require_once(__DIR__.'/../../../include/integration.php');
29+
30+
use Laravel\Horizon\Console\HorizonCommand;
31+
use NewRelic\Integration\Transaction;
32+
33+
function foobar() {
34+
echo "foobar\n";
35+
}
36+
function get_txn() {
37+
return new Transaction;
38+
}
39+
40+
newrelic_add_custom_tracer('foobar');
41+
foobar();
42+
43+
$txn = get_txn();
44+
foreach ($txn->getTrace()->findSegmentsByName('Custom/foobar') as $segment) {
45+
echo $segment->name;
46+
echo "\n";
47+
}
48+
49+
$horizon = new HorizonCommand();
50+
$horizon->handle();
51+
foobar();
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
<?php
2+
/*
3+
* Copyright 2020 New Relic Corporation. All rights reserved.
4+
* SPDX-License-Identifier: Apache-2.0
5+
*/
6+
7+
/*DESCRIPTION
8+
Ensure that when HorizonCommand::handle is executed, the transaction is properly stopped.
9+
*/
10+
11+
/*INI
12+
newrelic.framework = laravel
13+
*/
14+
15+
/*EXPECT_HARVEST
16+
no
17+
*/
18+
19+
/*EXPECT
20+
foobar
21+
Custom/foobar
22+
handle function
23+
foobar
24+
*/
25+
26+
require_once(__DIR__ . '/mock_horizon_happy_path.php');
27+
require_once(__DIR__.'/../../../include/integration.php');
28+
29+
use Laravel\Horizon\Console\HorizonCommand;
30+
use NewRelic\Integration\Transaction;
31+
32+
function foobar() {
33+
echo "foobar\n";
34+
}
35+
function get_txn() {
36+
return new Transaction;
37+
}
38+
39+
newrelic_add_custom_tracer('foobar');
40+
foobar();
41+
42+
$txn = get_txn();
43+
foreach ($txn->getTrace()->findSegmentsByName('Custom/foobar') as $segment) {
44+
echo $segment->name;
45+
echo "\n";
46+
}
47+
48+
$horizon = new HorizonCommand();
49+
$horizon->handle();
50+
foobar();
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
<?php
2+
/*
3+
* Copyright 2020 New Relic Corporation. All rights reserved.
4+
* SPDX-License-Identifier: Apache-2.0
5+
*/
6+
7+
/*DESCRIPTION
8+
Ensure that when SupervisorCommand::handle is executed, the transaction is properly stopped.
9+
*/
10+
11+
/*INI
12+
newrelic.framework = laravel
13+
*/
14+
15+
/*EXPECT_HARVEST
16+
no
17+
*/
18+
19+
/*EXPECT_TRACED_ERRORS
20+
null
21+
*/
22+
23+
/*EXPECT_ERROR_EVENTS
24+
null
25+
*/
26+
27+
require_once(__DIR__ . '/mock_supervisor_error_path.php');
28+
require_once(__DIR__.'/../../../include/integration.php');
29+
30+
use Laravel\Horizon\Console\SupervisorCommand;
31+
use NewRelic\Integration\Transaction;
32+
33+
function foobar() {
34+
echo "foobar\n";
35+
}
36+
function get_txn() {
37+
return new Transaction;
38+
}
39+
40+
newrelic_add_custom_tracer('foobar');
41+
foobar();
42+
43+
$txn = get_txn();
44+
foreach ($txn->getTrace()->findSegmentsByName('Custom/foobar') as $segment) {
45+
echo $segment->name;
46+
echo "\n";
47+
}
48+
49+
$supervisor = new SupervisorCommand();
50+
$supervisor->handle();
51+
foobar();

0 commit comments

Comments
 (0)