1--TEST--
2Test binary operands exposing the same behavior at compile as at run time
3--INI--
4memory_limit=256M
5opcache.file_update_protection=1
6--SKIPIF--
7<?php
8if (getenv("SKIP_SLOW_TESTS")) die('skip slow test');
9?>
10--FILE--
11<?php
12
13require_once __DIR__ . DIRECTORY_SEPARATOR . 'test_offset_helpers.inc';
14
15function makeTestFile($container, $offset) {
16    $offset_p = zend_test_var_export($offset);
17    $container_p = zend_test_var_export($container);
18    $fileContent = file_get_contents(__DIR__ . '/test_variable_offsets.inc');
19    $fileContent = str_replace('$dimension', $offset_p, $fileContent);
20    return str_replace('//$container var declaration in const generated file', "\$container = $container_p;", $fileContent);
21}
22
23function normalize_output(string $output, string $filename): string {
24    $output = str_replace(
25        [$filename],
26        ['%s'],
27        $output
28    );
29
30    $output = preg_replace('/\)#\d+ \(/', ')#99 (', $output);
31
32    return $output;
33}
34
35$const_dim_filename = __DIR__ . DIRECTORY_SEPARATOR . 'compare_binary_offsets_temp.php';
36
37ob_start();
38foreach ($containers as $container_orig) {
39    foreach ($offsets as $offset) {
40        $error = zend_test_var_export($container_orig) . '[' . zend_test_var_export($offset) . '] has different outputs' . "\n";
41        file_put_contents($const_dim_filename, makeTestFile($container_orig, $offset));
42
43        include $const_dim_filename;
44        $constOutput = ob_get_contents();
45        ob_clean();
46        $constOutput = normalize_output($constOutput, $const_dim_filename);
47
48        $dimension = $offset;
49        $container = $container_orig;
50        if (is_object($container_orig)) {
51            $container = clone $container_orig;
52        }
53        include $var_dim_filename;
54        $varOutput = ob_get_contents();
55        ob_clean();
56        $varOutput = normalize_output($varOutput, $var_dim_filename);
57
58        if ($constOutput !== $varOutput) {
59            file_put_contents(__DIR__ . DIRECTORY_SEPARATOR . "debug_{$failuresNb}_const.txt", $constOutput);
60            file_put_contents(__DIR__ . DIRECTORY_SEPARATOR . "debug_{$failuresNb}_var.txt", $varOutput);
61            file_put_contents(__DIR__ . DIRECTORY_SEPARATOR . "debug_{$failuresNb}_test_case.txt", makeTestFile($container_orig, $offset));
62            ++$failuresNb;
63            $failures[] = $error;
64        }
65        ++$testCasesTotal;
66    }
67}
68ob_end_clean();
69
70echo "Executed tests\n";
71if ($failures !== []) {
72    echo "Failures:\n" . implode($failures);
73}
74
75?>
76--CLEAN--
77<?php
78$fl = __DIR__ . DIRECTORY_SEPARATOR . 'compare_binary_offsets_temp.php';
79@unlink($fl);
80?>
81--EXPECT--
82Executed tests
83