@@ -650,25 +650,27 @@ public static function getObjectForMapTests()
650
650
651
651
public function testObjectsSupportDisabledWithExceptions ()
652
652
{
653
- $ this ->expectException (ParseException::class);
654
653
$ yaml = <<<'EOF'
655
654
foo: !php/object:O:30:"Symfony\Tests\Component\Yaml\B":1:{s:1:"b";s:3:"foo";}
656
655
bar: 1
657
656
EOF;
658
657
658
+ $ this ->expectException (ParseException::class);
659
+
659
660
$ this ->parser ->parse ($ yaml , Yaml::PARSE_EXCEPTION_ON_INVALID_TYPE );
660
661
}
661
662
662
663
public function testMappingKeyInMultiLineStringThrowsException ()
663
664
{
664
- $ this ->expectException (ParseException::class);
665
- $ this ->expectExceptionMessage ('Mapping values are not allowed in multi-line blocks at line 2 (near "dbal:wrong"). ' );
666
-
667
665
$ yaml = <<<'EOF'
668
666
data:
669
667
dbal:wrong
670
668
default_connection: monolith
671
669
EOF;
670
+
671
+ $ this ->expectException (ParseException::class);
672
+ $ this ->expectExceptionMessage ('Mapping values are not allowed in multi-line blocks at line 2 (near "dbal:wrong"). ' );
673
+
672
674
$ this ->parser ->parse ($ yaml );
673
675
}
674
676
@@ -707,7 +709,6 @@ public function testNonUtf8Exception()
707
709
708
710
public function testUnindentedCollectionException ()
709
711
{
710
- $ this ->expectException (ParseException::class);
711
712
$ yaml = <<<'EOF'
712
713
713
714
collection:
@@ -717,12 +718,13 @@ public function testUnindentedCollectionException()
717
718
718
719
EOF;
719
720
721
+ $ this ->expectException (ParseException::class);
722
+
720
723
$ this ->parser ->parse ($ yaml );
721
724
}
722
725
723
726
public function testShortcutKeyUnindentedCollectionException ()
724
727
{
725
- $ this ->expectException (ParseException::class);
726
728
$ yaml = <<<'EOF'
727
729
728
730
collection:
@@ -731,6 +733,8 @@ public function testShortcutKeyUnindentedCollectionException()
731
733
732
734
EOF;
733
735
736
+ $ this ->expectException (ParseException::class);
737
+
734
738
$ this ->parser ->parse ($ yaml );
735
739
}
736
740
@@ -929,8 +933,6 @@ public function testScalarInSequence()
929
933
*/
930
934
public function testMappingDuplicateKeyBlock ()
931
935
{
932
- $ this ->expectException (ParseException::class);
933
- $ this ->expectExceptionMessage ('Duplicate key "child" detected ' );
934
936
$ input = <<<'EOD'
935
937
parent:
936
938
child: first
@@ -939,28 +941,24 @@ public function testMappingDuplicateKeyBlock()
939
941
child: duplicate
940
942
child: duplicate
941
943
EOD;
942
- $ expected = [
943
- 'parent ' => [
944
- 'child ' => 'first ' ,
945
- ],
946
- ];
947
- $ this ->assertSame ($ expected , Yaml::parse ($ input ));
944
+
945
+ $ this ->expectException (ParseException::class);
946
+ $ this ->expectExceptionMessage ('Duplicate key "child" detected ' );
947
+
948
+ Yaml::parse ($ input );
948
949
}
949
950
950
951
public function testMappingDuplicateKeyFlow ()
951
952
{
952
- $ this ->expectException (ParseException::class);
953
- $ this ->expectExceptionMessage ('Duplicate key "child" detected ' );
954
953
$ input = <<<'EOD'
955
954
parent: { child: first, child: duplicate }
956
955
parent: { child: duplicate, child: duplicate }
957
956
EOD;
958
- $ expected = [
959
- 'parent ' => [
960
- 'child ' => 'first ' ,
961
- ],
962
- ];
963
- $ this ->assertSame ($ expected , Yaml::parse ($ input ));
957
+
958
+ $ this ->expectException (ParseException::class);
959
+ $ this ->expectExceptionMessage ('Duplicate key "child" detected ' );
960
+
961
+ Yaml::parse ($ input );
964
962
}
965
963
966
964
/**
@@ -1202,26 +1200,28 @@ public function testYamlDirective()
1202
1200
1203
1201
public function testFloatKeys ()
1204
1202
{
1205
- $ this ->expectException (ParseException::class);
1206
- $ this ->expectExceptionMessage ('Numeric keys are not supported. Quote your evaluable mapping keys instead ' );
1207
1203
$ yaml = <<<'EOF'
1208
1204
foo:
1209
1205
1.2: "bar"
1210
1206
1.3: "baz"
1211
1207
EOF;
1212
1208
1209
+ $ this ->expectException (ParseException::class);
1210
+ $ this ->expectExceptionMessage ('Numeric keys are not supported. Quote your evaluable mapping keys instead ' );
1211
+
1213
1212
$ this ->parser ->parse ($ yaml );
1214
1213
}
1215
1214
1216
1215
public function testBooleanKeys ()
1217
1216
{
1218
- $ this ->expectException (ParseException::class);
1219
- $ this ->expectExceptionMessage ('Non-string keys are not supported. Quote your evaluable mapping keys instead ' );
1220
1217
$ yaml = <<<'EOF'
1221
1218
true: foo
1222
1219
false: bar
1223
1220
EOF;
1224
1221
1222
+ $ this ->expectException (ParseException::class);
1223
+ $ this ->expectExceptionMessage ('Non-string keys are not supported. Quote your evaluable mapping keys instead ' );
1224
+
1225
1225
$ this ->parser ->parse ($ yaml );
1226
1226
}
1227
1227
@@ -1252,12 +1252,13 @@ public function testExplicitStringCasting()
1252
1252
1253
1253
public function testColonInMappingValueException ()
1254
1254
{
1255
- $ this ->expectException (ParseException::class);
1256
- $ this ->expectExceptionMessage ('A colon cannot be used in an unquoted mapping value ' );
1257
1255
$ yaml = <<<'EOF'
1258
1256
foo: bar: baz
1259
1257
EOF;
1260
1258
1259
+ $ this ->expectException (ParseException::class);
1260
+ $ this ->expectExceptionMessage ('A colon cannot be used in an unquoted mapping value ' );
1261
+
1261
1262
$ this ->parser ->parse ($ yaml );
1262
1263
}
1263
1264
@@ -2347,54 +2348,58 @@ public function testExceptionWhenUsingUnsupportedBuiltInTags()
2347
2348
2348
2349
public function testComplexMappingThrowsParseException ()
2349
2350
{
2350
- $ this ->expectException (ParseException::class);
2351
- $ this ->expectExceptionMessage ('Complex mappings are not supported at line 1 (near "? "1""). ' );
2352
2351
$ yaml = <<<YAML
2353
2352
? "1"
2354
2353
:
2355
2354
name: végétalien
2356
2355
YAML ;
2357
2356
2357
+ $ this ->expectException (ParseException::class);
2358
+ $ this ->expectExceptionMessage ('Complex mappings are not supported at line 1 (near "? "1""). ' );
2359
+
2358
2360
$ this ->parser ->parse ($ yaml );
2359
2361
}
2360
2362
2361
2363
public function testComplexMappingNestedInMappingThrowsParseException ()
2362
2364
{
2363
- $ this ->expectException (ParseException::class);
2364
- $ this ->expectExceptionMessage ('Complex mappings are not supported at line 2 (near "? "1""). ' );
2365
2365
$ yaml = <<<YAML
2366
2366
diet:
2367
2367
? "1"
2368
2368
:
2369
2369
name: végétalien
2370
2370
YAML ;
2371
2371
2372
+ $ this ->expectException (ParseException::class);
2373
+ $ this ->expectExceptionMessage ('Complex mappings are not supported at line 2 (near "? "1""). ' );
2374
+
2372
2375
$ this ->parser ->parse ($ yaml );
2373
2376
}
2374
2377
2375
2378
public function testComplexMappingNestedInSequenceThrowsParseException ()
2376
2379
{
2377
- $ this ->expectException (ParseException::class);
2378
- $ this ->expectExceptionMessage ('Complex mappings are not supported at line 1 (near "- ? "1""). ' );
2379
2380
$ yaml = <<<YAML
2380
2381
- ? "1"
2381
2382
:
2382
2383
name: végétalien
2383
2384
YAML ;
2384
2385
2386
+ $ this ->expectException (ParseException::class);
2387
+ $ this ->expectExceptionMessage ('Complex mappings are not supported at line 1 (near "- ? "1""). ' );
2388
+
2385
2389
$ this ->parser ->parse ($ yaml );
2386
2390
}
2387
2391
2388
2392
public function testParsingIniThrowsException ()
2389
2393
{
2390
- $ this ->expectException (ParseException::class);
2391
- $ this ->expectExceptionMessage ('Unable to parse at line 2 (near " foo = bar"). ' );
2392
2394
$ ini = <<<INI
2393
2395
[parameters]
2394
2396
foo = bar
2395
2397
bar = %foo%
2396
2398
INI ;
2397
2399
2400
+ $ this ->expectException (ParseException::class);
2401
+ $ this ->expectExceptionMessage ('Unable to parse at line 2 (near " foo = bar"). ' );
2402
+
2398
2403
$ this ->parser ->parse ($ ini );
2399
2404
}
2400
2405
@@ -2440,8 +2445,6 @@ public function testCanParseVeryLongValue()
2440
2445
2441
2446
public function testParserCleansUpReferencesBetweenRuns ()
2442
2447
{
2443
- $ this ->expectException (ParseException::class);
2444
- $ this ->expectExceptionMessage ('Reference "foo" does not exist at line 2 ' );
2445
2448
$ yaml = <<<YAML
2446
2449
foo: &foo
2447
2450
baz: foobar
@@ -2454,6 +2457,10 @@ public function testParserCleansUpReferencesBetweenRuns()
2454
2457
bar:
2455
2458
<<: *foo
2456
2459
YAML ;
2460
+
2461
+ $ this ->expectException (ParseException::class);
2462
+ $ this ->expectExceptionMessage ('Reference "foo" does not exist at line 2 ' );
2463
+
2457
2464
$ this ->parser ->parse ($ yaml );
2458
2465
}
2459
2466
@@ -2574,8 +2581,6 @@ public function testParsingNonExistentFilesThrowsException()
2574
2581
2575
2582
public function testParsingNotReadableFilesThrowsException ()
2576
2583
{
2577
- $ this ->expectException (ParseException::class);
2578
- $ this ->expectExceptionMessageMatches ('#^File ".+/Fixtures/not_readable.yml" cannot be read\.$# ' );
2579
2584
if ('\\' === \DIRECTORY_SEPARATOR ) {
2580
2585
$ this ->markTestSkipped ('chmod is not supported on Windows ' );
2581
2586
}
@@ -2587,6 +2592,9 @@ public function testParsingNotReadableFilesThrowsException()
2587
2592
$ file = __DIR__ .'/Fixtures/not_readable.yml ' ;
2588
2593
chmod ($ file , 0200 );
2589
2594
2595
+ $ this ->expectException (ParseException::class);
2596
+ $ this ->expectExceptionMessageMatches ('#^File ".+/Fixtures/not_readable.yml" cannot be read\.$# ' );
2597
+
2590
2598
$ this ->parser ->parseFile ($ file );
2591
2599
}
2592
2600
@@ -2648,11 +2656,13 @@ public function testParseReferencesOnMergeKeysWithMappingsParsedAsObjects()
2648
2656
2649
2657
public function testEvalRefException ()
2650
2658
{
2651
- $ this ->expectException (ParseException::class);
2652
- $ this ->expectExceptionMessage ('Reference "foo" does not exist ' );
2653
2659
$ yaml = <<<EOE
2654
2660
foo: { &foo { a: Steve, <<: *foo} }
2655
2661
EOE ;
2662
+
2663
+ $ this ->expectException (ParseException::class);
2664
+ $ this ->expectExceptionMessage ('Reference "foo" does not exist ' );
2665
+
2656
2666
$ this ->parser ->parse ($ yaml );
2657
2667
}
2658
2668
0 commit comments