@@ -0,0 +1,42 @@
|
||||
<?php
|
||||
|
||||
test('composition loads only its verified local calculation when explicitly enabled', function (string $mode) {
|
||||
$root = dirname(__DIR__, 2);
|
||||
$bundle = $root.'/storage/framework/testing/cost-bootstrap-'.bin2hex(random_bytes(6));
|
||||
mkdir($bundle, 0700, true);
|
||||
foreach (['integrations/sgf/operational/bootstrap.php', 'integrations/sgf/operational/RuntimeContext.php', 'integrations/sgf/operational/Composition.php', 'integrations/sgf/sourcing/bootstrap.php'] as $stub) {
|
||||
if (! is_dir(dirname($bundle.'/'.$stub))) {
|
||||
mkdir(dirname($bundle.'/'.$stub), 0700, true);
|
||||
}
|
||||
file_put_contents($bundle.'/'.$stub, '<?php // Test double for unrelated application boot.');
|
||||
}
|
||||
copy($root.'/integrations/sgf/operational/entry.php', $bundle.'/bootstrap.php');
|
||||
$relative = 'packages/purchasing/src/StockCosting.php';
|
||||
mkdir(dirname($bundle.'/'.$relative), 0700, true);
|
||||
copy($root.'/packages/purchasing/src/StockCosting.php', $bundle.'/'.$relative);
|
||||
$pin = hash_file('sha256', $bundle.'/'.$relative);
|
||||
file_put_contents($bundle.'/manifest.json', json_encode(['format' => 'tempo.operational-review.v2', 'support_files' => [$relative => $pin]], JSON_THROW_ON_ERROR));
|
||||
if ($mode === 'tampered') {
|
||||
file_put_contents($bundle.'/'.$relative, '<?php // tampered');
|
||||
}
|
||||
if ($mode === 'disabled') {
|
||||
unlink($bundle.'/'.$relative);
|
||||
}
|
||||
$script = 'require '.var_export($root.'/vendor/autoload.php', true).';'
|
||||
.'Illuminate\\Container\\Container::getInstance()->instance("config", new Illuminate\\Config\\Repository(["merchandise_invoices"=>["costs_enabled"=>'.($mode === 'disabled' ? 'false' : 'true').']]));';
|
||||
if ($mode === 'different_loaded_version') {
|
||||
file_put_contents($bundle.'/different.php', '<?php namespace Tempo\\Purchasing\\Inventory; final class StockCosting {}');
|
||||
$script .= 'require '.var_export($bundle.'/different.php', true).';';
|
||||
}
|
||||
$script .= 'try { require '.var_export($bundle.'/bootstrap.php', true).'; echo "BOOT_OK:".(int)class_exists(Tempo\\Purchasing\\Inventory\\StockCosting::class,false); } catch (RuntimeException $error) { echo "REFUSED:".$error->getMessage(); }';
|
||||
// Subprocess avoids sharing a PHP class definition between composition variants.
|
||||
$process = proc_open([PHP_BINARY, '-r', $script], [0 => ['pipe', 'r'], 1 => ['pipe', 'w'], 2 => ['pipe', 'w']], $pipes);
|
||||
expect(is_resource($process))->toBeTrue();
|
||||
fclose($pipes[0]);
|
||||
$out = stream_get_contents($pipes[1]);
|
||||
$error = stream_get_contents($pipes[2]);
|
||||
fclose($pipes[1]);
|
||||
fclose($pipes[2]);
|
||||
expect(proc_close($process))->toBe(0, $error);
|
||||
expect($out)->toStartWith(in_array($mode, ['tampered', 'different_loaded_version'], true) ? 'REFUSED:' : 'BOOT_OK:'.($mode === 'disabled' ? '0' : '1'));
|
||||
})->with(['enabled', 'disabled', 'tampered', 'different_loaded_version']);
|
||||
Reference in New Issue
Block a user