-
Open tests/PluginTest.php and verify the file header matches:
<?php
namespace Detain\MyAdminWebhostingIp\Tests;
use Detain\MyAdminWebhostingIp\Plugin;
use PHPUnit\Framework\TestCase;
use ReflectionClass;
Add private ReflectionClass $reflector; and a setUp() that sets $this->reflector = new ReflectionClass(Plugin::class);.
-
Static property tests — assert exact values via Plugin::$property:
$this->assertSame('webhosting', Plugin::$module);
$this->assertSame('addon', Plugin::$type);
Verify property is public+static via $this->reflector->getProperty($name)->isPublic().
-
getHooks() tests — call Plugin::getHooks(), assert:
- Returns array with exactly 2 keys
- Keys are
Plugin::$module . '.load_addons' and Plugin::$module . '.settings'
- Each value is
[Plugin::class, 'getAddon'] / [Plugin::class, 'getSettings']
is_callable($callback) is true for each entry
-
Reflection signature tests — use $this->reflector->getMethod($name) to assert visibility and parameters without invoking:
$method = $this->reflector->getMethod('doEnable');
$this->assertTrue($method->isPublic());
$this->assertTrue($method->isStatic());
$this->assertSame(2, $method->getNumberOfRequiredParameters());
$params = $method->getParameters();
$this->assertSame('serviceOrder', $params[0]->getName());
$this->assertSame('repeatInvoiceId', $params[1]->getName());
$this->assertSame('regexMatch', $params[2]->getName());
$this->assertFalse($params[2]->getDefaultValue());
Apply the same pattern to doDisable, getAddon, getSettings, getIps.
-
Source inspection tests — extract method body with file() + ReflectionMethod line numbers, then assertStringContainsString:
$method = $this->reflector->getMethod('doEnable');
$filename = $method->getFileName();
$source = implode('', array_slice(
file($filename),
$method->getStartLine() - 1,
$method->getEndLine() - $method->getStartLine() + 1
));
$this->assertStringContainsString('get_module_db', $source);
$this->assertStringContainsString('myadmin_log', $source);
$this->assertStringContainsString('update', $source);
For doDisable, also assert adminMail and website_ip_canceled.tpl.
For getAddon, assert AddonHandler, set_cost, WEBSITE_IP_COST, register, addAddon.
For getSettings, assert setTarget('module'), setTarget('global'), add_text_setting, website_ip_cost.
For getIps, assert 'main', 'used', 'free', 'shared', listips().
-
Run and verify — all tests must pass before finishing:
vendor/bin/phpunit tests/ -v