Skip to content

Commit

Permalink
Fixed php7.2 deprecation
Browse files Browse the repository at this point in the history
  • Loading branch information
Nico Schoenmaker committed Feb 26, 2018
1 parent b2f1948 commit 868a501
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 1 deletion.
1 change: 1 addition & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
language: php
php:
- 7.2
- 7.1
- 7.0
- 5.6
Expand Down
5 changes: 4 additions & 1 deletion lib/yaml/sfYamlInline.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -99,11 +99,14 @@ static public function dump($value)
static protected function dumpArray($value)
{
// array
$fn = function ($v, $w) {
return ((int) $v) + ((int) $w);
};
$keys = array_keys($value);
if (
(1 == count($keys) && '0' == $keys[0])
||
(count($keys) > 1 && array_reduce($keys, create_function('$v,$w', 'return ((int) $v) + ((int) $w);'), 0) == count($keys) * (count($keys) - 1) / 2))
(count($keys) > 1 && array_reduce($keys, $fn, 0) == count($keys) * (count($keys) - 1) / 2))
{
$output = array();
foreach ($value as $val)
Expand Down
35 changes: 35 additions & 0 deletions test/lib/yaml/sfYamlInlineTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<?php
declare(strict_types = 1);

use PHPUnit\Framework\TestCase;

require_once(__DIR__ . '/../../../lib/yaml/sfYamlInline.class.php');

class sfYamlInlineTest extends TestCase
{
/**
* @dataProvider dumpProvider
*/
public function testDump($value, $expected)
{
self::assertSame($expected, sfYamlInline::dump($value));
}

public function dumpProvider()
{
return [
[null, 'null'],
['string', 'string'],
[true, 'true'],
[false, 'false'],
[6, 6],
["asdf\nasdf", '"asdf\nasdf"'],
['', "''"],
['1234', "'1234'"],
['true', "'true'"],
['false', "'false'"],
[['a', 'b'], '[a, b]'],
[['a' => 'b'], '{ a: b }']
];
}
}

0 comments on commit 868a501

Please sign in to comment.