|
| 1 | +--TEST-- |
| 2 | +array containers behaviour with offsets |
| 3 | +--FILE-- |
| 4 | +<?php |
| 5 | + |
| 6 | +require_once __DIR__ . DIRECTORY_SEPARATOR . 'test_offset_helpers.inc'; |
| 7 | + |
| 8 | +const EXPECTED_OUTPUT_VALID_OFFSETS = <<<OUTPUT |
| 9 | +Read before write: |
| 10 | +
|
| 11 | +Warning: Undefined array key %s in %s on line 8 |
| 12 | +NULL |
| 13 | +Write: |
| 14 | +Read: |
| 15 | +string(1) "v" |
| 16 | +Read-Write: |
| 17 | +isset(): |
| 18 | +bool(true) |
| 19 | +empty(): |
| 20 | +bool(false) |
| 21 | +Coalesce(): |
| 22 | +string(7) "vappend" |
| 23 | +
|
| 24 | +OUTPUT; |
| 25 | + |
| 26 | +$EXPECTED_OUTPUT_VALID_OFFSETS_REGEX = '/^' . expectf_to_regex(EXPECTED_OUTPUT_VALID_OFFSETS) . '$/s'; |
| 27 | + |
| 28 | +const EXPECTF_OUTPUT_FLOAT_OFFSETS = <<<OUTPUT |
| 29 | +Read before write: |
| 30 | +
|
| 31 | +Deprecated: Implicit conversion from float %F to int loses precision in %s on line 8 |
| 32 | +
|
| 33 | +Warning: Undefined array key %s in %s on line 8 |
| 34 | +NULL |
| 35 | +Write: |
| 36 | +
|
| 37 | +Deprecated: Implicit conversion from float %F to int loses precision in %s on line 15 |
| 38 | +Read: |
| 39 | +
|
| 40 | +Deprecated: Implicit conversion from float %F to int loses precision in %s on line 22 |
| 41 | +string(1) "v" |
| 42 | +Read-Write: |
| 43 | +
|
| 44 | +Deprecated: Implicit conversion from float %F to int loses precision in %s on line 29 |
| 45 | +isset(): |
| 46 | +
|
| 47 | +Deprecated: Implicit conversion from float %F to int loses precision in %s on line 36 |
| 48 | +bool(true) |
| 49 | +empty(): |
| 50 | +
|
| 51 | +Deprecated: Implicit conversion from float %F to int loses precision in %s on line 42 |
| 52 | +bool(false) |
| 53 | +Coalesce(): |
| 54 | +
|
| 55 | +Deprecated: Implicit conversion from float %F to int loses precision in %s on line 48 |
| 56 | +string(7) "vappend" |
| 57 | +
|
| 58 | +OUTPUT; |
| 59 | + |
| 60 | +$EXPECTED_OUTPUT_FLOAT_OFFSETS_REGEX = '/^' . expectf_to_regex(EXPECTF_OUTPUT_FLOAT_OFFSETS) . '$/s'; |
| 61 | + |
| 62 | +const EXPECTED_OUTPUT_INVALID_OFFSETS = <<<OUTPUT |
| 63 | +Read before write: |
| 64 | +Cannot access offset of type %s on array |
| 65 | +Write: |
| 66 | +Cannot access offset of type %s on array |
| 67 | +Read: |
| 68 | +Cannot access offset of type %s on array |
| 69 | +Read-Write: |
| 70 | +Cannot access offset of type %s on array |
| 71 | +isset(): |
| 72 | +Cannot access offset of type %s in isset or empty |
| 73 | +empty(): |
| 74 | +Cannot access offset of type %s in isset or empty |
| 75 | +Coalesce(): |
| 76 | +Cannot access offset of type %s on array |
| 77 | +
|
| 78 | +OUTPUT; |
| 79 | + |
| 80 | +ob_start(); |
| 81 | +foreach ($offsets as $dimension) { |
| 82 | + $container = []; |
| 83 | + $error = '[][' . makeOffset($dimension) . '] has different outputs' . "\n"; |
| 84 | + |
| 85 | + include $var_dim_filename; |
| 86 | + $varOutput = ob_get_contents(); |
| 87 | + ob_clean(); |
| 88 | + $varOutput = str_replace( |
| 89 | + [$var_dim_filename], |
| 90 | + ['%s'], |
| 91 | + $varOutput |
| 92 | + ); |
| 93 | + |
| 94 | + if ( |
| 95 | + !preg_match($EXPECTED_OUTPUT_VALID_OFFSETS_REGEX, $varOutput) |
| 96 | + && $varOutput !== EXPECTED_OUTPUT_INVALID_OFFSETS |
| 97 | + && !preg_match($EXPECTED_OUTPUT_FLOAT_OFFSETS_REGEX, $varOutput) |
| 98 | + ) { |
| 99 | + file_put_contents(__DIR__ . DIRECTORY_SEPARATOR . "debug_array_container_{$failuresNb}.txt", $varOutput); |
| 100 | + ++$failuresNb; |
| 101 | + $failures[] = $error; |
| 102 | + } |
| 103 | + ++$testCasesTotal; |
| 104 | +} |
| 105 | +ob_end_clean(); |
| 106 | + |
| 107 | +echo "Executed $testCasesTotal tests\n"; |
| 108 | +if ($failures !== []) { |
| 109 | + echo "Failures:\n" . implode($failures); |
| 110 | +} |
| 111 | + |
| 112 | +?> |
| 113 | +--EXPECT-- |
| 114 | +Executed 21 tests |
0 commit comments