mirror of
https://github.com/alchemy-fr/Phraseanet.git
synced 2025-10-23 18:03:17 +00:00
Remove staticExpects to work with PHPUnit ~4.5
This commit is contained in:
@@ -211,11 +211,12 @@ abstract class ConfigurationTestCase extends \PhraseanetTestCase
|
||||
$compiler->expects($this->never())
|
||||
->method('compile');
|
||||
|
||||
$yaml = $this->getMockBuilder('Symfony\Component\Yaml\Yaml')
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
$yaml::staticExpects($this->never())
|
||||
->method('parse');
|
||||
// This Yaml Parser throws exception when trying to parse.
|
||||
$yaml = new YamlCountingParse();
|
||||
$yaml::reset();
|
||||
$yaml::setParseBehavior(function () {
|
||||
throw new \RuntimeException('Should not be called');
|
||||
});
|
||||
|
||||
$conf = $this->provideConfiguration($configFile, null, $compiler, $yaml);
|
||||
$conf->getConfig();
|
||||
@@ -247,13 +248,11 @@ abstract class ConfigurationTestCase extends \PhraseanetTestCase
|
||||
->with(['main' => 'tiptop'])
|
||||
->will($this->returnValue('<?php return ["main" => "tiptop"];'));
|
||||
|
||||
$yaml = $this->getMockBuilder('Symfony\Component\Yaml\Yaml')
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
$yaml::staticExpects($this->once())
|
||||
->method('parse')
|
||||
->will($this->returnValue(['main' => 'tiptop']));
|
||||
|
||||
$yaml = new YamlCountingParse();
|
||||
$yaml::reset();
|
||||
$yaml::setParseBehavior(function () {
|
||||
return ['main' => 'tiptop'];
|
||||
});
|
||||
$conf = $this->provideConfiguration($configFile, null, $compiler, $yaml, true);
|
||||
$this->assertSame(['main' => 'tiptop'], $conf->getConfig());
|
||||
$this->assertSame(['main' => 'tiptop'], $conf->getConfig());
|
||||
@@ -261,6 +260,7 @@ abstract class ConfigurationTestCase extends \PhraseanetTestCase
|
||||
$this->assertSame('tiptop', $conf['main']);
|
||||
$this->assertSame('tiptop', $conf['main']);
|
||||
$this->assertSame('tiptop', $conf['main']);
|
||||
$this->assertEquals(1, $yaml::getParseCount());
|
||||
}
|
||||
|
||||
public function testCompileAndWrite()
|
||||
|
@@ -0,0 +1,47 @@
|
||||
<?php
|
||||
/*
|
||||
* This file is part of Phraseanet
|
||||
*
|
||||
* (c) 2005-2015 Alchemy
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Alchemy\Tests\Phrasea\Core\Configuration;
|
||||
|
||||
use Symfony\Component\Yaml\Yaml;
|
||||
|
||||
class YamlCountingParse extends Yaml
|
||||
{
|
||||
private static $parseCount = 0;
|
||||
/** @var callable */
|
||||
private static $parseCallable;
|
||||
|
||||
public static function reset()
|
||||
{
|
||||
self::$parseCount = 0;
|
||||
self::$parseCallable = null;
|
||||
}
|
||||
|
||||
public static function getParseCount()
|
||||
{
|
||||
return self::$parseCount;
|
||||
}
|
||||
|
||||
public static function setParseBehavior(callable $callable)
|
||||
{
|
||||
self::$parseCallable = $callable;
|
||||
}
|
||||
|
||||
public static function parse($input, $exceptionOnInvalidType = false, $objectSupport = false)
|
||||
{
|
||||
self::$parseCount++;
|
||||
|
||||
if (null === self::$parseCallable) {
|
||||
return parent::parse($input, $exceptionOnInvalidType, $objectSupport);
|
||||
}
|
||||
|
||||
return call_user_func(self::$parseCallable, $input, $exceptionOnInvalidType, $objectSupport);
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user