133 lines
5.1 KiB
PHP
133 lines
5.1 KiB
PHP
<?php
|
|
|
|
use Toolbox\Commands\DoctorCommand;
|
|
use Toolbox\Compatibility;
|
|
use Toolbox\Console;
|
|
use Toolbox\Lock;
|
|
|
|
Harness::suite('group5');
|
|
|
|
Harness::it('compatibilidad: core por encima de lo probado avisa', function () {
|
|
$r = Compatibility::evaluateCore('1.5.0', '>=1.1', '1.4');
|
|
eq(Compatibility::UNTESTED, $r['status']);
|
|
});
|
|
|
|
Harness::it('compatibilidad: dentro del rango es OK', function () {
|
|
$r = Compatibility::evaluateCore('1.5.0', '>=1.1', '1.5');
|
|
eq(Compatibility::OK, $r['status']);
|
|
});
|
|
|
|
Harness::it('compatibilidad: core insuficiente', function () {
|
|
$r = Compatibility::evaluateCore('1.5.0', '>=1.6', null);
|
|
eq(Compatibility::INSUFFICIENT, $r['status']);
|
|
});
|
|
|
|
Harness::it('compatibilidad: sin datos', function () {
|
|
$r = Compatibility::evaluateCore('1.5.0', null, null);
|
|
eq(Compatibility::UNKNOWN, $r['status']);
|
|
});
|
|
|
|
Harness::it('compatibilidad: versión de core desconocida no inventa 0.0.0', function () {
|
|
$r = Compatibility::evaluateCore(null, '>=1.0', '1.0');
|
|
eq(Compatibility::UNKNOWN, $r['status']);
|
|
ok(str_contains($r['message'], 'desconocida'));
|
|
});
|
|
|
|
Harness::it('compatibilidad PHP', function () {
|
|
eq(Compatibility::OK, Compatibility::evaluatePhp('>=8.1', '8.5.0')['status']);
|
|
eq(Compatibility::INSUFFICIENT, Compatibility::evaluatePhp('>=9.0', '8.5.0')['status']);
|
|
eq(Compatibility::UNKNOWN, Compatibility::evaluatePhp(null, '8.5.0')['status']);
|
|
});
|
|
|
|
Harness::it('doctor no modifica lock ni archivos', function () {
|
|
$root = tmpdir('proj');
|
|
$tool = tmpdir('tool');
|
|
|
|
$lock = Lock::empty();
|
|
$lock->setCore(['version' => '1.5.0', 'commit' => 'abc', 'files' => []]);
|
|
$lock->setComponent('http:aria2', ['package' => 'http', 'version' => '1.2.0', 'toolbox_commit' => 'D', 'mode' => 'copy', 'files' => []]);
|
|
$lock->save($root);
|
|
|
|
write_file($tool . '/packages/http/duckbrain.json', json_encode([
|
|
'name' => 'http', 'version' => '1.2.0',
|
|
'core' => ['requires' => '>=1.1', 'tested' => '1.4'],
|
|
'components' => ['aria2' => ['files' => ['src/Libs/Aria2.php']]],
|
|
]));
|
|
|
|
$before = file_get_contents(Lock::path($root));
|
|
|
|
$cmd = new DoctorCommand(new Console());
|
|
$code = $cmd->run(['--root=' . $root, '--toolbox=' . $tool]);
|
|
eq(0, $code);
|
|
|
|
eq($before, file_get_contents(Lock::path($root)), 'el lock no debe cambiar');
|
|
ok(!is_file($root . '/.duckbrain/manifest.json'), 'doctor no crea manifest');
|
|
|
|
rrmdir($root);
|
|
rrmdir($tool);
|
|
});
|
|
|
|
Harness::it('core independiente: sin aviso en add incluso sin core conocido', function () {
|
|
$root = tmpdir('proj');
|
|
$tool = tmpdir('tool');
|
|
write_file($tool . '/packages/http/duckbrain.json', json_encode([
|
|
'name' => 'http', 'version' => '1.0.0', 'description' => 'HTTP',
|
|
'core' => 'none',
|
|
'components' => ['aria2' => ['files' => ['src/Libs/Aria2.php']]],
|
|
]));
|
|
write_file($tool . '/packages/http/src/Libs/Aria2.php', "<?php\n");
|
|
write_file($root . '/src/Libs/Router.php', "<?php\n");
|
|
|
|
$lock = Lock::load($root);
|
|
$lock->setCore(['version' => null, 'commit' => 'x', 'files' => []]);
|
|
$lock->save($root);
|
|
|
|
$out = fopen('php://memory', 'rw');
|
|
$inst = new Toolbox\Installer($root, $tool, new Console($out));
|
|
$res = $inst->add(['http:aria2'], []);
|
|
rewind($out);
|
|
$text = (string) stream_get_contents($out);
|
|
|
|
eq([], $res['warnings'], 'independiente no produce aviso');
|
|
eq([], $res['aborted'], 'nada se aborta');
|
|
ok(str_contains(implode(',', $res['installed']), 'http:aria2'), 'instala normal');
|
|
ok(!str_contains($text, 'sin datos'), 'sin ruido en consola');
|
|
|
|
// control: mismo fixture sin declaración sí avisa
|
|
write_file($tool . '/packages/http/duckbrain.json', json_encode([
|
|
'name' => 'http', 'version' => '1.0.1', 'description' => 'HTTP',
|
|
'components' => ['aria2' => ['files' => ['src/Libs/Aria2.php']]],
|
|
]));
|
|
$out2 = fopen('php://memory', 'rw');
|
|
$res2 = (new Toolbox\Installer($root, $tool, new Console($out2)))->add(['http:aria2'], ['yes' => true]);
|
|
ok($res2['warnings'] !== [], 'sin declaración sigue avisando');
|
|
|
|
rrmdir($root);
|
|
rrmdir($tool);
|
|
});
|
|
|
|
Harness::it('doctor muestra independiente sin rangos y sin fallo', function () {
|
|
$root = tmpdir('proj');
|
|
$tool = tmpdir('tool');
|
|
write_file($tool . '/packages/db/duckbrain.json', json_encode([
|
|
'name' => 'db', 'version' => '1.0.0', 'description' => 'DB',
|
|
'components' => ['sql' => ['files' => ['src/Libs/Sql.php'], 'core' => 'none']],
|
|
]));
|
|
write_file($tool . '/packages/db/src/Libs/Sql.php', "<?php\n");
|
|
|
|
$lock = Lock::load($root);
|
|
$lock->setCore(['version' => '1.5.0', 'commit' => 'c', 'files' => []]);
|
|
$lock->setComponent('db:sql', ['package' => 'db', 'version' => '1.0.0', 'mode' => 'copy', 'files' => []]);
|
|
$lock->save($root);
|
|
|
|
$out = fopen('php://memory', 'rw');
|
|
$code = (new DoctorCommand(new Console($out)))->run(['--root=' . $root, '--toolbox=' . $tool]);
|
|
rewind($out);
|
|
$text = (string) stream_get_contents($out);
|
|
|
|
eq(0, $code);
|
|
ok(str_contains($text, 'INDEPENDIENTE'), 'estado independiente visible');
|
|
rrmdir($root);
|
|
rrmdir($tool);
|
|
});
|