|
| 1 | +--TEST-- |
| 2 | +String containers behaviour with offsets |
| 3 | +--XFAIL-- |
| 4 | +INF offset on string doesn't behave like other floats for isset()/empty() |
| 5 | +--FILE-- |
| 6 | +<?php |
| 7 | + |
| 8 | +require_once __DIR__ . DIRECTORY_SEPARATOR . 'test_offset_helpers.inc'; |
| 9 | + |
| 10 | +const EXPECTED_OUTPUT_VALID_OFFSETS = <<<OUTPUT |
| 11 | +Read before write: |
| 12 | +
|
| 13 | +Warning: Uninitialized string offset %d in %s on line %d |
| 14 | +string(0) "" |
| 15 | +Write: |
| 16 | +Read: |
| 17 | +string(1) "v" |
| 18 | +Read-Write: |
| 19 | +Cannot use assign-op operators with string offsets |
| 20 | +isset(): |
| 21 | +bool(true) |
| 22 | +empty(): |
| 23 | +bool(false) |
| 24 | +Coalesce(): |
| 25 | +string(1) "v" |
| 26 | +
|
| 27 | +OUTPUT; |
| 28 | + |
| 29 | +$EXPECTED_OUTPUT_VALID_OFFSETS_REGEX = '/^' . expectf_to_regex(EXPECTED_OUTPUT_VALID_OFFSETS) . '$/s'; |
| 30 | + |
| 31 | +const EXPECTED_OUTPUT_STRING_CAST_OFFSETS = <<<OUTPUT |
| 32 | +Read before write: |
| 33 | +
|
| 34 | +Warning: String offset cast occurred in %s on line 8 |
| 35 | +
|
| 36 | +Warning: Uninitialized string offset %d in %s on line 8 |
| 37 | +string(0) "" |
| 38 | +Write: |
| 39 | +
|
| 40 | +Warning: String offset cast occurred in %s on line 15 |
| 41 | +Read: |
| 42 | +
|
| 43 | +Warning: String offset cast occurred in %s on line 22 |
| 44 | +string(1) "v" |
| 45 | +Read-Write: |
| 46 | +
|
| 47 | +Warning: String offset cast occurred in %s on line 29 |
| 48 | +Cannot use assign-op operators with string offsets |
| 49 | +isset(): |
| 50 | +bool(true) |
| 51 | +empty(): |
| 52 | +bool(false) |
| 53 | +Coalesce(): |
| 54 | +string(1) "v" |
| 55 | +
|
| 56 | +OUTPUT; |
| 57 | + |
| 58 | +$EXPECTED_OUTPUT_STRING_CAST_OFFSETS_REGEX = '/^' . expectf_to_regex(EXPECTED_OUTPUT_STRING_CAST_OFFSETS) . '$/s'; |
| 59 | + |
| 60 | +const EXPECTF_OUTPUT_FLOAT_OFFSETS = <<<OUTPUT |
| 61 | +Read before write: |
| 62 | +
|
| 63 | +Warning: String offset cast occurred in %s on line 8 |
| 64 | +
|
| 65 | +Warning: Uninitialized string offset %d in %s on line 8 |
| 66 | +string(0) "" |
| 67 | +Write: |
| 68 | +
|
| 69 | +Warning: String offset cast occurred in %s on line 15 |
| 70 | +Read: |
| 71 | +
|
| 72 | +Warning: String offset cast occurred in %s on line 22 |
| 73 | +string(1) "v" |
| 74 | +Read-Write: |
| 75 | +
|
| 76 | +Warning: String offset cast occurred in %s on line 29 |
| 77 | +Cannot use assign-op operators with string offsets |
| 78 | +isset(): |
| 79 | +
|
| 80 | +Deprecated: Implicit conversion from float %F to int loses precision in %s on line 36 |
| 81 | +bool(true) |
| 82 | +empty(): |
| 83 | +
|
| 84 | +Deprecated: Implicit conversion from float %F to int loses precision in %s on line 42 |
| 85 | +bool(false) |
| 86 | +Coalesce(): |
| 87 | +
|
| 88 | +Deprecated: Implicit conversion from float %F to int loses precision in %s on line 48 |
| 89 | +string(7) "vappend" |
| 90 | +
|
| 91 | +OUTPUT; |
| 92 | + |
| 93 | +$EXPECTED_OUTPUT_FLOAT_OFFSETS_REGEX = '/^' . expectf_to_regex(EXPECTF_OUTPUT_FLOAT_OFFSETS) . '$/s'; |
| 94 | + |
| 95 | +const EXPECTED_OUTPUT_INVALID_OFFSETS = <<<OUTPUT |
| 96 | +Read before write: |
| 97 | +Cannot access offset of type %s on string |
| 98 | +Write: |
| 99 | +Cannot access offset of type %s on string |
| 100 | +Read: |
| 101 | +Cannot access offset of type %s on string |
| 102 | +Read-Write: |
| 103 | +Cannot access offset of type %s on string |
| 104 | +isset(): |
| 105 | +bool(false) |
| 106 | +empty(): |
| 107 | +bool(true) |
| 108 | +Coalesce(): |
| 109 | +Cannot access offset of type %s on string |
| 110 | +
|
| 111 | +OUTPUT; |
| 112 | + |
| 113 | +$EXPECTED_OUTPUT_INVALID_OFFSETS_REGEX = '/^' . expectf_to_regex(EXPECTED_OUTPUT_INVALID_OFFSETS) . '$/s'; |
| 114 | + |
| 115 | +const EXPECTED_OUTPUT_INVALID_OFFSETS_AS_STRINGS = <<<OUTPUT |
| 116 | +Read before write: |
| 117 | +Cannot access offset of type string on string |
| 118 | +Write: |
| 119 | +Cannot access offset of type string on string |
| 120 | +Read: |
| 121 | +Cannot access offset of type string on string |
| 122 | +Read-Write: |
| 123 | +Cannot access offset of type string on string |
| 124 | +isset(): |
| 125 | +bool(false) |
| 126 | +empty(): |
| 127 | +bool(true) |
| 128 | +Coalesce(): |
| 129 | +string(7) "default" |
| 130 | +
|
| 131 | +OUTPUT; |
| 132 | + |
| 133 | +const EXPECTED_OUTPUT_INVALID_OFFSETS_AS_LEADING_NUMERIC_STRINGS = <<<OUTPUT |
| 134 | +Read before write: |
| 135 | +
|
| 136 | +Warning: Illegal string offset %s in %s on line 8 |
| 137 | +
|
| 138 | +Warning: Uninitialized string offset %d in %s on line 8 |
| 139 | +string(0) "" |
| 140 | +Write: |
| 141 | +
|
| 142 | +Warning: Illegal string offset %s in %s on line 15 |
| 143 | +Read: |
| 144 | +
|
| 145 | +Warning: Illegal string offset %s in %s on line 22 |
| 146 | +string(1) "v" |
| 147 | +Read-Write: |
| 148 | +
|
| 149 | +Warning: Illegal string offset %s in %s on line 29 |
| 150 | +Cannot use assign-op operators with string offsets |
| 151 | +isset(): |
| 152 | +bool(false) |
| 153 | +empty(): |
| 154 | +bool(true) |
| 155 | +Coalesce(): |
| 156 | +
|
| 157 | +Warning: Illegal string offset %s in %s on line 48 |
| 158 | +string(1) "v" |
| 159 | +
|
| 160 | +OUTPUT; |
| 161 | + |
| 162 | +$EXPECTED_OUTPUT_INVALID_OFFSETS_AS_LEADING_NUMERIC_STRINGS_REGEX = '/^' . expectf_to_regex(EXPECTED_OUTPUT_INVALID_OFFSETS_AS_LEADING_NUMERIC_STRINGS) . '$/s'; |
| 163 | + |
| 164 | +ob_start(); |
| 165 | +foreach ($offsets as $dimension) { |
| 166 | + $container = ''; |
| 167 | + $error = '""[' . makeOffset($dimension) . '] has different outputs' . "\n"; |
| 168 | + |
| 169 | + include $var_dim_filename; |
| 170 | + $varOutput = ob_get_contents(); |
| 171 | + ob_clean(); |
| 172 | + $varOutput = str_replace( |
| 173 | + [$var_dim_filename], |
| 174 | + ['%s'], |
| 175 | + $varOutput |
| 176 | + ); |
| 177 | + |
| 178 | + if ( |
| 179 | + !preg_match($EXPECTED_OUTPUT_VALID_OFFSETS_REGEX, $varOutput) |
| 180 | + && !preg_match($EXPECTED_OUTPUT_STRING_CAST_OFFSETS_REGEX, $varOutput) |
| 181 | + && !preg_match($EXPECTED_OUTPUT_INVALID_OFFSETS_REGEX, $varOutput) |
| 182 | + && !preg_match($EXPECTED_OUTPUT_FLOAT_OFFSETS_REGEX, $varOutput) |
| 183 | + && $varOutput !== EXPECTED_OUTPUT_INVALID_OFFSETS_AS_STRINGS |
| 184 | + && !preg_match($EXPECTED_OUTPUT_INVALID_OFFSETS_AS_LEADING_NUMERIC_STRINGS_REGEX, $varOutput) |
| 185 | + ) { |
| 186 | + //file_put_contents(__DIR__ . DIRECTORY_SEPARATOR . "debug_string_container_{$failuresNb}.txt", $varOutput); |
| 187 | + ++$failuresNb; |
| 188 | + $failures[] = $error; |
| 189 | + } |
| 190 | + ++$testCasesTotal; |
| 191 | +} |
| 192 | +ob_end_clean(); |
| 193 | + |
| 194 | +echo "Executed $testCasesTotal tests\n"; |
| 195 | +if ($failures !== []) { |
| 196 | + echo "Failures:\n" . implode($failures); |
| 197 | +} |
| 198 | + |
| 199 | +?> |
| 200 | +--EXPECT-- |
| 201 | +Executed 21 tests |
0 commit comments