Files
FOSSBilling/tests/Unit/Box/AppAdminTest.php
Adam Daley 2fbecd5b99 Harden null handling across core, adapters, and templates (#4384)
* Harden null handling across core, adapters, and templates

Guard the currency fraction-digit lookup when zlib is unavailable, map unknown GeoIP country codes to incomplete records, tolerate object app options and controllers without a register method, default missing ResellerClub and PayPal IPN fields, and hide server rows when a hosting order has no server.

* Guard non-string GeoIP country codes before enum lookup
2026-09-21 11:55:52 +01:00

55 lines
1.3 KiB
PHP

<?php
/**
* Copyright 2022-2026 FOSSBilling
* SPDX-License-Identifier: Apache-2.0.
*
* @copyright FOSSBilling (https://www.fossbilling.org)
* @license http://www.apache.org/licenses/LICENSE-2.0 Apache-2.0
*/
declare(strict_types=1);
use Symfony\Component\HttpFoundation\Request;
function appAdminWithController(object $controller): Box_AppAdmin
{
$mod = Mockery::mock();
$mod->shouldReceive('getAdminController')->andReturn($controller);
$app = new class extends Box_AppAdmin {
public function setMod(string $mod): void
{
$this->mod = $mod;
}
};
$di = new Pimple\Container();
$di['request'] = Request::create('http://localhost/test');
$di['mod'] = $di->protect(static fn (): object => $mod);
$app->setDi($di);
$app->setMod('example');
return $app;
}
test('init skips controllers without a register method', function (): void {
appAdminWithController(new stdClass())->init();
expect(true)->toBeTrue();
});
test('init registers controllers that have a register method', function (): void {
$controller = new class {
public bool $registered = false;
public function register(object $app): void
{
$this->registered = true;
}
};
appAdminWithController($controller)->init();
expect($controller->registered)->toBeTrue();
});