Skip to content

Commit

Permalink
Merge pull request #15 from nicoschoenmaker/feature/less-deprecations
Browse files Browse the repository at this point in the history
Do not use the deprecated create_function function
  • Loading branch information
yannickl88 authored Jun 22, 2017
2 parents f32e323 + 53ab743 commit cd3dd23
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 2 deletions.
4 changes: 2 additions & 2 deletions lib/config/sfConfigHandler.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ static public function replaceConstants($value)
{
if (is_array($value))
{
array_walk_recursive($value, create_function('&$value', '$value = sfToolkit::replaceConstants($value);'));
array_walk_recursive($value, function (&$value) { $value = sfToolkit::replaceConstants($value); });
}
else
{
Expand All @@ -96,7 +96,7 @@ static public function replacePath($path)
{
if (is_array($path))
{
array_walk_recursive($path, create_function('&$path', '$path = sfConfigHandler::replacePath($path);'));
array_walk_recursive($path, function (&$path) { $path = sfConfigHandler::replacePath($path); });
}
else
{
Expand Down
56 changes: 56 additions & 0 deletions test/lib/config/sfConfigHandlerTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
<?php
declare(strict_types = 1);

use PHPUnit\Framework\TestCase;

require_once(__DIR__ . '/../../../lib/config/sfConfigHandler.class.php');
require_once(__DIR__ . '/../../../lib/util/sfToolkit.class.php');

/**
* @covers sfConfigHandler
*/
class sfConfigHandlerTest extends TestCase
{
/**
* @dataProvider replaceConstantsProvider
*/
public function testReplaceConstants($input, $output)
{
sfConfig::clear();
sfConfig::set('foo', 'bar');
self::assertSame($output, sfConfigHandler::replaceConstants($input));
}

public function replaceConstantsProvider()
{
return [
['a', 'a'],
[[], []],
[[[['a']]], [[['a']]]],
['%foo%', 'bar'],
['%foo% foo %foo%', 'bar foo bar'],
['%unknown%', '%unknown%'],
[['%foo%'], ['bar']],
];
}

/**
* @dataProvider replacePathProvider
*/
public function testReplacePath($input, $output)
{
sfConfig::clear();
sfConfig::set('sf_app_dir', '/the/app/dir');
self::assertSame($output, sfConfigHandler::replacePath($input));
}

public function replacePathProvider()
{
return [
['a', '/the/app/dir/a'],
['/a', '/a'],
[['a'], ['/the/app/dir/a']],
[['/a'], ['/a']],
];
}
}

0 comments on commit cd3dd23

Please sign in to comment.