Skip to content

Commit 5a90282

Browse files
committed
add integration tests
1 parent 2d515f1 commit 5a90282

8 files changed

+272
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
<?php
2+
/*
3+
* Copyright 2020 New Relic Corporation. All rights reserved.
4+
* SPDX-License-Identifier: Apache-2.0
5+
*/
6+
7+
/* Verify agent behavior when map key is not a string */
8+
9+
namespace Drupal\Core\Extension {
10+
interface ModuleHandlerInterface
11+
{
12+
public function invokeAllWith($hook_str, $callback);
13+
}
14+
class ModuleHandler implements ModuleHandlerInterface
15+
{
16+
protected array $hookImplementationsMap = array(
17+
'hookname' => array('classname' => array('methodname' => 'modulename')),
18+
1 => array('classname_b' => array('methodname_b' => 'modulename_b')),
19+
'hookname_c' => array('classname_c', array('methodname_c', 'modulename_c')),
20+
);
21+
22+
// to avoid editor warnings
23+
public function invokeAllWith($hook_str, $callback)
24+
{
25+
return null;
26+
}
27+
28+
// for debugging purposes
29+
public function dump()
30+
{
31+
var_dump($this->hookImplementationsMap);
32+
}
33+
}
34+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
<?php
2+
/*
3+
* Copyright 2020 New Relic Corporation. All rights reserved.
4+
* SPDX-License-Identifier: Apache-2.0
5+
*/
6+
7+
/* Verify agent behavior when hookImplemementationsMap is not an array */
8+
9+
namespace Drupal\Core\Extension {
10+
interface ModuleHandlerInterface
11+
{
12+
public function invokeAllWith($hook_str, $callback);
13+
}
14+
class ModuleHandler implements ModuleHandlerInterface
15+
{
16+
protected string $hookImplementationsMap = 'just a string';
17+
18+
// to avoid editor warnings
19+
public function invokeAllWith($hook_str, $callback)
20+
{
21+
return null;
22+
}
23+
24+
// for debugging purposes
25+
public function dump()
26+
{
27+
var_dump($this->hookImplementationsMap);
28+
}
29+
}
30+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
<?php
2+
/*
3+
* Copyright 2020 New Relic Corporation. All rights reserved.
4+
* SPDX-License-Identifier: Apache-2.0
5+
*/
6+
7+
/* Verify agent behavior when module name is not a string */
8+
9+
namespace Drupal\Core\Extension {
10+
interface ModuleHandlerInterface
11+
{
12+
public function invokeAllWith($hook_str, $callback);
13+
}
14+
class ModuleHandler implements ModuleHandlerInterface
15+
{
16+
protected array $hookImplementationsMap = array(
17+
'hookname' => array('classname' => array('methodname' => 'modulename')),
18+
'hookname_b' => array('classname_b' => array('methodname_b' => array(1, 2, 3))),
19+
'hookname_c' => array('classname_c' => array('methodname_c' => 'modulename_c')),
20+
);
21+
22+
// to avoid editor warnings
23+
public function invokeAllWith($hook_str, $callback)
24+
{
25+
return null;
26+
}
27+
28+
// for debugging purposes
29+
public function dump()
30+
{
31+
var_dump($this->hookImplementationsMap);
32+
}
33+
}
34+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
<?php
2+
/*
3+
* Copyright 2020 New Relic Corporation. All rights reserved.
4+
* SPDX-License-Identifier: Apache-2.0
5+
*/
6+
7+
/* Verify agent behavior when key value is not an array */
8+
9+
namespace Drupal\Core\Extension {
10+
interface ModuleHandlerInterface
11+
{
12+
public function invokeAllWith($hook_str, $callback);
13+
}
14+
class ModuleHandler implements ModuleHandlerInterface
15+
{
16+
protected array $hookImplementationsMap = array(
17+
'hookname' => array('classname' => array('methodname' => 'modulename')),
18+
'hookname_b' => array('classname_b' => 'just a string'),
19+
'hookname_c' => array('classname_c' => array('methodname_c' => 'modulename_c')),
20+
);
21+
22+
// to avoid editor warnings
23+
public function invokeAllWith($hook_str, $callback)
24+
{
25+
return null;
26+
}
27+
28+
// for debugging purposes
29+
public function dump()
30+
{
31+
var_dump($this->hookImplementationsMap);
32+
}
33+
}
34+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
<?php
2+
/*
3+
* Copyright 2020 New Relic Corporation. All rights reserved.
4+
* SPDX-License-Identifier: Apache-2.0
5+
*/
6+
7+
/*DESCRIPTION
8+
Verify agent does not crash when map key is not a string.
9+
*/
10+
11+
/*INI
12+
newrelic.framework = drupal8
13+
*/
14+
15+
/*EXPECT_TRACED_ERRORS null */
16+
17+
/*EXPECT_ERROR_EVENTS null */
18+
19+
/*EXPECT
20+
*/
21+
22+
require_once __DIR__ . '/mock_module_handler_invalid_key.php';
23+
24+
// This specific API is needed for us to instrument the ModuleHandler
25+
class Drupal
26+
{
27+
public function moduleHandler()
28+
{
29+
return new Drupal\Core\Extension\ModuleHandler();
30+
}
31+
}
32+
33+
// Create module handler
34+
$drupal = new Drupal();
35+
$handler = $drupal->moduleHandler();
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
<?php
2+
/*
3+
* Copyright 2020 New Relic Corporation. All rights reserved.
4+
* SPDX-License-Identifier: Apache-2.0
5+
*/
6+
7+
/*DESCRIPTION
8+
Verify the agent does not crash when handling an invalid hookImplementationsMap property.
9+
*/
10+
11+
/*INI
12+
newrelic.framework = drupal8
13+
*/
14+
15+
/*EXPECT_TRACED_ERRORS null */
16+
17+
/*EXPECT_ERROR_EVENTS null */
18+
19+
/*EXPECT
20+
*/
21+
22+
require_once __DIR__ . '/mock_module_handler_invalid_map.php';
23+
24+
// This specific API is needed for us to instrument the ModuleHandler
25+
class Drupal
26+
{
27+
public function moduleHandler()
28+
{
29+
return new Drupal\Core\Extension\ModuleHandler();
30+
}
31+
}
32+
33+
// Create module handler
34+
$drupal = new Drupal();
35+
$handler = $drupal->moduleHandler();
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
<?php
2+
/*
3+
* Copyright 2020 New Relic Corporation. All rights reserved.
4+
* SPDX-License-Identifier: Apache-2.0
5+
*/
6+
7+
/*DESCRIPTION
8+
Verify agent does not crash when module name is not a string.
9+
*/
10+
11+
/*INI
12+
newrelic.framework = drupal8
13+
*/
14+
15+
/*EXPECT_TRACED_ERRORS null */
16+
17+
/*EXPECT_ERROR_EVENTS null */
18+
19+
/*EXPECT
20+
*/
21+
22+
require_once __DIR__ . '/mock_module_handler_invalid_module.php';
23+
24+
// This specific API is needed for us to instrument the ModuleHandler
25+
class Drupal
26+
{
27+
public function moduleHandler()
28+
{
29+
return new Drupal\Core\Extension\ModuleHandler();
30+
}
31+
}
32+
33+
// Create module handler
34+
$drupal = new Drupal();
35+
$handler = $drupal->moduleHandler();
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
<?php
2+
/*
3+
* Copyright 2020 New Relic Corporation. All rights reserved.
4+
* SPDX-License-Identifier: Apache-2.0
5+
*/
6+
7+
/*DESCRIPTION
8+
Verify agent does not crash when key value is not an array.
9+
*/
10+
11+
/*INI
12+
newrelic.framework = drupal8
13+
*/
14+
15+
/*EXPECT_TRACED_ERRORS null */
16+
17+
/*EXPECT_ERROR_EVENTS null */
18+
19+
/*EXPECT
20+
*/
21+
22+
require_once __DIR__ . '/mock_module_handler_invalid_value.php';
23+
24+
// This specific API is needed for us to instrument the ModuleHandler
25+
class Drupal
26+
{
27+
public function moduleHandler()
28+
{
29+
return new Drupal\Core\Extension\ModuleHandler();
30+
}
31+
}
32+
33+
// Create module handler
34+
$drupal = new Drupal();
35+
$handler = $drupal->moduleHandler();

0 commit comments

Comments
 (0)