Remove staticExpects to work with PHPUnit ~4.5

This commit is contained in:
Benoît Burnichon
2015-03-17 13:08:27 +01:00
parent e5fae798dc
commit cdc7f743d5
17 changed files with 107 additions and 57 deletions

View File

@@ -35,7 +35,6 @@ before_script:
- mysql -e 'SET @@global.wait_timeout= 999999;'
php:
- 5.4
- 5.5
- 5.6

View File

@@ -45,5 +45,5 @@ interface CheckerInterface
*
* @return string
*/
public static function getMessage(TranslatorInterface $translator);
public function getMessage(TranslatorInterface $translator);
}

View File

@@ -61,7 +61,7 @@ class Colorspace extends AbstractChecker
return new Response($boolean, $this);
}
public static function getMessage(TranslatorInterface $translator)
public function getMessage(TranslatorInterface $translator)
{
return $translator->trans('The file does not match available color');
}

View File

@@ -53,7 +53,7 @@ class Dimension extends AbstractChecker
return new Response($boolean, $this);
}
public static function getMessage(TranslatorInterface $translator)
public function getMessage(TranslatorInterface $translator)
{
return $translator->trans('The file does not match required dimension');
}

View File

@@ -41,7 +41,7 @@ class Extension extends AbstractChecker
return new Response($boolean, $this);
}
public static function getMessage(TranslatorInterface $translator)
public function getMessage(TranslatorInterface $translator)
{
return $translator->trans('The file does not match available extensions');
}

View File

@@ -54,7 +54,7 @@ class Filename extends AbstractChecker
/**
* {@inheritdoc}
*/
public static function getMessage(TranslatorInterface $translator)
public function getMessage(TranslatorInterface $translator)
{
return $translator->trans('A file with the same filename already exists in database');
}

View File

@@ -49,7 +49,7 @@ class MediaType extends AbstractChecker
return new Response($boolean, $this);
}
public static function getMessage(TranslatorInterface $translator)
public function getMessage(TranslatorInterface $translator)
{
return $translator->trans('The file does not match required media type');
}

View File

@@ -43,7 +43,7 @@ class Sha256 extends AbstractChecker
/**
* {@inheritdoc}
*/
public static function getMessage(TranslatorInterface $translator)
public function getMessage(TranslatorInterface $translator)
{
return $translator->trans('A file with the same checksum already exists in database');
}

View File

@@ -42,7 +42,7 @@ class UUID extends AbstractChecker
/**
* {@inheritdoc}
*/
public static function getMessage(TranslatorInterface $translator)
public function getMessage(TranslatorInterface $translator)
{
return $translator->trans('A file with the same UUID already exists in database');
}

View File

@@ -13,9 +13,8 @@ namespace Alchemy\Phrasea\SearchEngine;
use Alchemy\Phrasea\Application;
use Alchemy\Phrasea\Exception\RuntimeException;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use Doctrine\Common\Collections\ArrayCollection;
use Alchemy\Phrasea\Model\Entities\FeedEntry;
use Doctrine\Common\Collections\ArrayCollection;
interface SearchEngineInterface
{

View File

@@ -18,7 +18,9 @@ class AbstractCheckerTest extends \PhraseanetTestCase
{
parent::setUp();
$this->object = new AbstractCheckerTester(self::$DI['app']);
$this->object = $this->getMockBuilder(AbstractChecker::class)
->setConstructorArgs([self::$DI['app']])
->getMockForAbstractClass();
$this->file = $this->getMock('\\Alchemy\\Phrasea\\Border\\File', ['getCollection'], [], 'CheckerTesterMock' . mt_rand(), false);
}
@@ -199,17 +201,3 @@ class AbstractCheckerTest extends \PhraseanetTestCase
];
}
}
class AbstractCheckerTester extends AbstractChecker
{
public static function getMessage(TranslatorInterface $translator)
{
}
public function check(EntityManager $em, File $file)
{
}
}

View File

@@ -111,7 +111,8 @@ class DimensionTest extends \PhraseanetTestCase
*/
public function testGetMessage()
{
$this->assertInternalType('string', Dimension::getMessage($this->createTranslatorMock()));
$checker = new Dimension(self::$DI['app'], ['width' => 800]);
$this->assertInternalType('string', $checker->getMessage($this->createTranslatorMock()));
}
/**

View File

@@ -2,6 +2,7 @@
namespace Alchemy\Tests\Phrasea\Border\Checker;
use Alchemy\Phrasea\Border\Checker\CheckerInterface;
use Alchemy\Phrasea\Border\Checker\Response;
use Alchemy\Tests\Tools\TranslatorMockTrait;
@@ -9,7 +10,9 @@ class ResponseTest extends \PhraseanetTestCase
{
use TranslatorMockTrait;
/** @var \PHPUnit_Framework_MockObject_MockObject */
protected $mock;
/** @var Response */
protected $object;
/**
@@ -18,7 +21,7 @@ class ResponseTest extends \PhraseanetTestCase
public function setUp()
{
parent::setUp();
$this->mock = $this->getMock('\\Alchemy\\Phrasea\\Border\\Checker\\CheckerInterface', ['getMessage', 'check', 'isApplicable']);
$this->mock = $this->getMock(CheckerInterface::class);
$this->object = new Response(true, $this->mock);
}
@@ -58,7 +61,7 @@ class ResponseTest extends \PhraseanetTestCase
public function testGetMessage()
{
$this->mock
->staticExpects($this->any())
->expects($this->any())
->method('getMessage')
->will($this->returnValue('Hello World'));

View File

@@ -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()

View File

@@ -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);
}
}

View File

@@ -0,0 +1,19 @@
<?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.
*/
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
class PhraseanetSeTestSubscriber implements EventSubscriberInterface
{
public static function getSubscribedEvents()
{
return [];
}
}

View File

@@ -1,22 +1,22 @@
<?php
use Alchemy\Phrasea\CLI;
use Alchemy\Phrasea\Application;
use Alchemy\Phrasea\Authentication\ACLProvider;
use Alchemy\Phrasea\Border\File;
use Alchemy\Phrasea\CLI;
use Alchemy\Phrasea\Model\Entities\Session;
use Alchemy\Phrasea\Model\Entities\User;
use Monolog\Logger;
use Alchemy\Phrasea\SearchEngine\SearchEngineInterface;
use Alchemy\Phrasea\TaskManager\Notifier;
use Alchemy\Tests\Tools\TranslatorMockTrait;
use Guzzle\Http\Client as Guzzle;
use Monolog\Handler\NullHandler;
use Monolog\Logger;
use Silex\WebTestCase;
use Symfony\Component\DomCrawler\Crawler;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpKernel\Client;
use Symfony\Component\DomCrawler\Crawler;
use Symfony\Component\Routing\RequestContext;
use Alchemy\Tests\Tools\TranslatorMockTrait;
use Alchemy\Phrasea\Authentication\ACLProvider;
use Alchemy\Phrasea\TaskManager\Notifier;
use Guzzle\Http\Client as Guzzle;
use Symfony\Component\Filesystem\Filesystem;
abstract class PhraseanetTestCase extends WebTestCase
{
@@ -342,10 +342,7 @@ abstract class PhraseanetTestCase extends WebTestCase
$app['translator'] = $this->createTranslatorMock();
$app['phraseanet.SE.subscriber'] = $this->getMock('Symfony\Component\EventDispatcher\EventSubscriberInterface');
$app['phraseanet.SE.subscriber']::staticExpects($this->any())
->method('getSubscribedEvents')
->will($this->returnValue([]));
$app['phraseanet.SE.subscriber'] = new PhraseanetSeTestSubscriber();
$app['orm.em'] = $app->extend('orm.em', function($em, $app) {
@@ -710,7 +707,7 @@ abstract class PhraseanetTestCase extends WebTestCase
protected function createSearchEngineMock()
{
$mock = $this->getMock('Alchemy\Phrasea\SearchEngine\SearchEngineInterface');
$mock = $this->getMock(SearchEngineInterface::class);
$mock->expects($this->any())
->method('createSubscriber')
->will($this->returnValue($this->getMock('Symfony\Component\EventDispatcher\EventSubscriberInterface')));
@@ -720,9 +717,6 @@ abstract class PhraseanetTestCase extends WebTestCase
$mock->expects($this->any())
->method('getStatus')
->will($this->returnValue([]));
$mock->staticExpects($this->any())
->method('createSubscriber')
->will($this->returnValue($this->getMock('Symfony\Component\EventDispatcher\EventSubscriberInterface')));
return $mock;
}