mustangostang / spyc

A simple YAML loader/dumper class for PHP
MIT License
701 stars 206 forks source link

PHP 7.1 compatibility #62

Open esurov opened 7 years ago

esurov commented 7 years ago

Hey,

I was doing some tests of the library with php 7.1 and there are 4 tests failing:

1) DumpTest::testDump Failed asserting that two arrays are equal. --- Expected +++ Actual @@ @@ 'NewLine' => '\n'

@@ @@ 'float_test_with_quotes' => '1.0'

/Users/gene/Work/oDesk/Vena/vena/vendor/mustangostang/spyc/tests/DumpTest.php:24

2) DumpTest::testDumpWithQuotes Failed asserting that two arrays are equal. --- Expected +++ Actual @@ @@ 'SmallFloat' => 0.7

@@ @@ 'float_test_with_quotes' => '1.0'

/Users/gene/Work/oDesk/Vena/vena/vendor/mustangostang/spyc/tests/DumpTest.php:35

3) ParseTest::testMappingsHex Failed asserting that '0xf3' is identical to 243.

/Users/gene/Work/oDesk/Vena/vena/vendor/mustangostang/spyc/tests/ParseTest.php:47

4) RoundTripTest::testNewLines Failed asserting that two arrays are equal. --- Expected +++ Actual @@ @@ Array (

/Users/gene/Work/oDesk/Vena/vena/vendor/mustangostang/spyc/tests/RoundTripTest.php:38

FAILURES! Tests: 132, Assertions: 135, Failures: 4.

jackmcdade commented 7 years ago

Are you able to send a PR on any of those items that pass the tests?

esurov commented 7 years ago

Sorry, PR stands for?

jackmcdade commented 7 years ago

My apologies. Pull Request - when you fork a repo, make changes, and submit them for review.

esurov commented 7 years ago

Hmm, I know the reason of one failure:

Disallow the ASCII delete control character in identifiers The ASCII delete control character (0x7F) can no longer be used in identifiers that are not quoted.

http://php.net/manual/en/migration71.incompatible.php#migration71.incompatible.delete-control-character-in-identifiers

If you replace line 18 in spyc.yml with the following one it stops failing: Hex: '0xf3'

FossPrime commented 7 years ago

the only difference I get comparing php 7 with php 5.6 is with NewLine. I don't see control characters anywhere. screenshot from 2017-02-08 15-00-00

PHP 7.0.15

$ phpunit DumpTest.php 
PHPUnit 5.7.5 by Sebastian Bergmann and contributors.

.FF........................                                       27 / 27 (100%)

Time: 91 ms, Memory: 4.00MB

There were 2 failures:

1) DumpTest::testDump
Failed asserting that two arrays are equal.
--- Expected
+++ Actual
@@ @@
     'NewLine' => '\n'
-    'QuotedNewLine' => '
-    '
+    'QuotedNewLine' => '\n'

@@ @@
     'float_test_with_quotes' => '1.0'
-    'float_inverse_test' => 1.0
+    'float_inverse_test' => 1

PHP 5.6.29

# phpunit DumpTest.php 
PHPUnit 4.2.6 by Sebastian Bergmann.

.FF........................

Time: 58 ms, Memory: 3.25Mb

There were 2 failures:

1) DumpTest::testDump
Failed asserting that two arrays are equal.
--- Expected
+++ Actual
@@ @@
     'NewLine' => '\n'
-    'QuotedNewLine' => '
-    '
+    'QuotedNewLine' => '\n'

@@ @@
     'float_test_with_quotes' => '1.0'
-    'float_inverse_test' => 1.0
+    'float_inverse_test' => 1
     'a_really_large_number' => '11579208923731619542357098500...639936'
     'int array' => Array (...)
     'array on several lines' => Array (...)
     'morelesskey' => '<value>'
     'array_of_zero' => Array (...)
     'sophisticated_array_of_zero' => Array (...)
     'switches' => Array (...)
     'empty_sequence' => Array ()
     'empty_hash' => Array ()
     'special_characters' => '[{]]{{]]'
     'asterisks' => '*'
     'empty_key' => Array (...)
     'trailing_colon' => 'foo:'
     'multiline_items' => Array (...)
     'many_lines' => 'A quick\nfox\n\n\njumped\nover\n\n\n\n...\n\n\ndog'
     'werte' => Array (...)
     'noindent_records' => ''
     1041 => Array (...)
     1042 => Array (...)
     'a:1' => Array (...)
     'a:2' => Array (...)
     'a:3' => Array (...)
     'complex_unquoted_key' => Array (...)
     'array with commas' => Array (...)
     'invoice' => Array (...)
     'quotes' => Array (...)
     'endloop' => 'Does this line in the end ind... loop?'
 )

/root/spyc/tests/DumpTest.php:24

2) DumpTest::testDumpWithQuotes
Failed asserting that two arrays are equal.
--- Expected
+++ Actual
@@ @@
     'SmallFloat' => 0.69999999999999996
-    'NewLine' => '\n'
-    'QuotedNewLine' => '
+    'NewLine' => '
     '
+    'QuotedNewLine' => '\n'

@@ @@
     'float_test_with_quotes' => '1.0'
-    'float_inverse_test' => 1.0
+    'float_inverse_test' => 1
Gummibeer commented 7 years ago

@rayfoss it's about php7.1 not php7.0 - related to types, conversion and things like this php7.1 is much stricter than php7.0 or php5.6, we had to change all $numString * 1 cause php7.1 dropped an TypeError exception.