|
294 | 294 | expect(substr_count($content, 'match_tolerate_misses:'))->toBe(1); |
295 | 295 | expect($content)->toContain(' match_tolerate_misses: true'); |
296 | 296 | }); |
| 297 | + |
| 298 | + it('returns true when file cannot be read', function () { |
| 299 | + set_error_handler(fn () => true, E_WARNING); |
| 300 | + try { |
| 301 | + $result = Helper::fixKaliopMigrationYaml('/nonexistent_test_path_xyz/file.yml', new NullLogger()); |
| 302 | + expect($result)->toBeTrue(); |
| 303 | + } finally { |
| 304 | + restore_error_handler(); |
| 305 | + } |
| 306 | + }); |
| 307 | + |
| 308 | + it('inserts field-settings at correct position when block ends with blank line and has no validator-configuration', function () { |
| 309 | + // The block collector includes trailing empty lines; the while loop on line 134 |
| 310 | + // must back up past the trailing blank before splicing field-settings in. |
| 311 | + $yaml = "-\n type: content_type\n mode: create\n attributes:\n -\n identifier: title\n type: ibexa_string\n\n -\n identifier: body\n type: ibexa_richtext\n"; |
| 312 | + file_put_contents($this->tmpFile, $yaml); |
| 313 | + |
| 314 | + $result = Helper::fixKaliopMigrationYaml($this->tmpFile, new NullLogger()); |
| 315 | + $content = file_get_contents($this->tmpFile); |
| 316 | + |
| 317 | + expect($result)->toBeTrue(); |
| 318 | + expect($content)->toContain(' field-settings: { }'); |
| 319 | + }); |
| 320 | + |
| 321 | + it('inserts validator-configuration at correct position when ibexa_boolean block ends with blank line', function () { |
| 322 | + // Block has field-settings but no validator-configuration, and ends with a blank line; |
| 323 | + // the while loop on line 143 must back up past the trailing blank. |
| 324 | + $yaml = "-\n type: content_type\n mode: create\n attributes:\n -\n identifier: active\n type: ibexa_boolean\n field-settings: { }\n\n -\n identifier: body\n type: ibexa_richtext\n"; |
| 325 | + file_put_contents($this->tmpFile, $yaml); |
| 326 | + |
| 327 | + $result = Helper::fixKaliopMigrationYaml($this->tmpFile, new NullLogger()); |
| 328 | + $content = file_get_contents($this->tmpFile); |
| 329 | + |
| 330 | + expect($result)->toBeTrue(); |
| 331 | + expect($content)->toContain(' validator-configuration: { }'); |
| 332 | + }); |
| 333 | + |
| 334 | + it('inserts match_tolerate_misses before sibling key that follows match block', function () { |
| 335 | + // A non-8-space-indented key immediately after match: triggers the elseif branch (lines 205-207). |
| 336 | + $yaml = "-\n type: content_type\n mode: delete\n match:\n content_type_identifier: some_type\n"; |
| 337 | + file_put_contents($this->tmpFile, $yaml); |
| 338 | + |
| 339 | + $result = Helper::fixKaliopMigrationYaml($this->tmpFile, new NullLogger()); |
| 340 | + $content = file_get_contents($this->tmpFile); |
| 341 | + |
| 342 | + expect($result)->toBeTrue(); |
| 343 | + expect($content)->toContain(' match_tolerate_misses: true'); |
| 344 | + }); |
297 | 345 | }); |
0 commit comments