Skip to content

Commit 0df55d0

Browse files
style: apply php-cs-fixer to tests/Security/SetupStructureTest.php
1 parent 4191256 commit 0df55d0

1 file changed

Lines changed: 38 additions & 3 deletions

File tree

tests/Security/SetupStructureTest.php

Lines changed: 38 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,7 @@
77
+-------------------------------------------------------------------------+
88
*/
99

10-
/*
11-
* Verify setup.php defines required plugin hooks and info function.
12-
*/
10+
// Verify setup.php defines required plugin hooks and info function.
1311

1412
function thold_read_setup_source() {
1513
$setupPath = realpath(__DIR__ . '/../../setup.php');
@@ -47,3 +45,40 @@ function thold_read_setup_source() {
4745
expect($source)->toContain('parse_ini_file');
4846
expect($source)->toContain("return \$info['info'];");
4947
});
48+
49+
it('setup.php file exists and is readable at expected path', function () {
50+
$setupPath = __DIR__ . '/../../setup.php';
51+
expect(file_exists($setupPath))->toBeTrue('setup.php does not exist at expected location');
52+
expect(is_readable($setupPath))->toBeTrue('setup.php exists but is not readable');
53+
expect(realpath($setupPath))->not->toBeFalse('realpath() failed to resolve setup.php');
54+
});
55+
56+
it('registers required poller and device hooks via api_plugin_register_hook', function () {
57+
$source = thold_read_setup_source();
58+
expect($source)->toContain("'poller_output'");
59+
expect($source)->toContain("'poller_bottom'");
60+
expect($source)->toContain("'device_action_array'");
61+
expect($source)->toContain("'api_device_save'");
62+
});
63+
64+
it('api_plugin_register_hook calls use at least four arguments', function () {
65+
$source = thold_read_setup_source();
66+
$matches = [];
67+
preg_match_all('/api_plugin_register_hook\s*\([^;)]+\)/', $source, $matches);
68+
69+
expect(count($matches[0]))->toBeGreaterThan(0, 'No api_plugin_register_hook calls found in setup.php');
70+
71+
foreach ($matches[0] as $call) {
72+
$argCount = substr_count($call, ',') + 1;
73+
expect($argCount)->toBeGreaterThanOrEqual(
74+
4,
75+
"Hook call has fewer than 4 arguments: {$call}"
76+
);
77+
}
78+
});
79+
80+
it('api_plugin_register_hook hook names are non-empty string literals', function () {
81+
$source = thold_read_setup_source();
82+
expect($source)->not->toMatch("/api_plugin_register_hook\s*\(\s*[^,]+,\s*''\s*,/");
83+
expect($source)->not->toMatch('/api_plugin_register_hook\s*\(\s*[^,]+,\s*""\s*,/');
84+
});

0 commit comments

Comments
 (0)