mirror of
https://github.com/alchemy-fr/Phraseanet.git
synced 2025-10-23 09:53:15 +00:00
Remove staticExpects to work with PHPUnit ~4.5
This commit is contained in:
@@ -35,7 +35,6 @@ before_script:
|
|||||||
- mysql -e 'SET @@global.wait_timeout= 999999;'
|
- mysql -e 'SET @@global.wait_timeout= 999999;'
|
||||||
|
|
||||||
php:
|
php:
|
||||||
- 5.4
|
|
||||||
- 5.5
|
- 5.5
|
||||||
- 5.6
|
- 5.6
|
||||||
|
|
||||||
|
@@ -45,5 +45,5 @@ interface CheckerInterface
|
|||||||
*
|
*
|
||||||
* @return string
|
* @return string
|
||||||
*/
|
*/
|
||||||
public static function getMessage(TranslatorInterface $translator);
|
public function getMessage(TranslatorInterface $translator);
|
||||||
}
|
}
|
||||||
|
@@ -61,7 +61,7 @@ class Colorspace extends AbstractChecker
|
|||||||
return new Response($boolean, $this);
|
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');
|
return $translator->trans('The file does not match available color');
|
||||||
}
|
}
|
||||||
|
@@ -53,7 +53,7 @@ class Dimension extends AbstractChecker
|
|||||||
return new Response($boolean, $this);
|
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');
|
return $translator->trans('The file does not match required dimension');
|
||||||
}
|
}
|
||||||
|
@@ -41,7 +41,7 @@ class Extension extends AbstractChecker
|
|||||||
return new Response($boolean, $this);
|
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');
|
return $translator->trans('The file does not match available extensions');
|
||||||
}
|
}
|
||||||
|
@@ -54,7 +54,7 @@ class Filename extends AbstractChecker
|
|||||||
/**
|
/**
|
||||||
* {@inheritdoc}
|
* {@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');
|
return $translator->trans('A file with the same filename already exists in database');
|
||||||
}
|
}
|
||||||
|
@@ -49,7 +49,7 @@ class MediaType extends AbstractChecker
|
|||||||
return new Response($boolean, $this);
|
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');
|
return $translator->trans('The file does not match required media type');
|
||||||
}
|
}
|
||||||
|
@@ -43,7 +43,7 @@ class Sha256 extends AbstractChecker
|
|||||||
/**
|
/**
|
||||||
* {@inheritdoc}
|
* {@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');
|
return $translator->trans('A file with the same checksum already exists in database');
|
||||||
}
|
}
|
||||||
|
@@ -42,7 +42,7 @@ class UUID extends AbstractChecker
|
|||||||
/**
|
/**
|
||||||
* {@inheritdoc}
|
* {@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');
|
return $translator->trans('A file with the same UUID already exists in database');
|
||||||
}
|
}
|
||||||
|
@@ -13,9 +13,8 @@ namespace Alchemy\Phrasea\SearchEngine;
|
|||||||
|
|
||||||
use Alchemy\Phrasea\Application;
|
use Alchemy\Phrasea\Application;
|
||||||
use Alchemy\Phrasea\Exception\RuntimeException;
|
use Alchemy\Phrasea\Exception\RuntimeException;
|
||||||
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
|
|
||||||
use Doctrine\Common\Collections\ArrayCollection;
|
|
||||||
use Alchemy\Phrasea\Model\Entities\FeedEntry;
|
use Alchemy\Phrasea\Model\Entities\FeedEntry;
|
||||||
|
use Doctrine\Common\Collections\ArrayCollection;
|
||||||
|
|
||||||
interface SearchEngineInterface
|
interface SearchEngineInterface
|
||||||
{
|
{
|
||||||
|
@@ -18,7 +18,9 @@ class AbstractCheckerTest extends \PhraseanetTestCase
|
|||||||
{
|
{
|
||||||
parent::setUp();
|
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);
|
$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)
|
|
||||||
{
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
@@ -111,7 +111,8 @@ class DimensionTest extends \PhraseanetTestCase
|
|||||||
*/
|
*/
|
||||||
public function testGetMessage()
|
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()));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@@ -2,6 +2,7 @@
|
|||||||
|
|
||||||
namespace Alchemy\Tests\Phrasea\Border\Checker;
|
namespace Alchemy\Tests\Phrasea\Border\Checker;
|
||||||
|
|
||||||
|
use Alchemy\Phrasea\Border\Checker\CheckerInterface;
|
||||||
use Alchemy\Phrasea\Border\Checker\Response;
|
use Alchemy\Phrasea\Border\Checker\Response;
|
||||||
use Alchemy\Tests\Tools\TranslatorMockTrait;
|
use Alchemy\Tests\Tools\TranslatorMockTrait;
|
||||||
|
|
||||||
@@ -9,7 +10,9 @@ class ResponseTest extends \PhraseanetTestCase
|
|||||||
{
|
{
|
||||||
use TranslatorMockTrait;
|
use TranslatorMockTrait;
|
||||||
|
|
||||||
|
/** @var \PHPUnit_Framework_MockObject_MockObject */
|
||||||
protected $mock;
|
protected $mock;
|
||||||
|
/** @var Response */
|
||||||
protected $object;
|
protected $object;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -18,7 +21,7 @@ class ResponseTest extends \PhraseanetTestCase
|
|||||||
public function setUp()
|
public function setUp()
|
||||||
{
|
{
|
||||||
parent::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);
|
$this->object = new Response(true, $this->mock);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -58,7 +61,7 @@ class ResponseTest extends \PhraseanetTestCase
|
|||||||
public function testGetMessage()
|
public function testGetMessage()
|
||||||
{
|
{
|
||||||
$this->mock
|
$this->mock
|
||||||
->staticExpects($this->any())
|
->expects($this->any())
|
||||||
->method('getMessage')
|
->method('getMessage')
|
||||||
->will($this->returnValue('Hello World'));
|
->will($this->returnValue('Hello World'));
|
||||||
|
|
||||||
|
@@ -211,11 +211,12 @@ abstract class ConfigurationTestCase extends \PhraseanetTestCase
|
|||||||
$compiler->expects($this->never())
|
$compiler->expects($this->never())
|
||||||
->method('compile');
|
->method('compile');
|
||||||
|
|
||||||
$yaml = $this->getMockBuilder('Symfony\Component\Yaml\Yaml')
|
// This Yaml Parser throws exception when trying to parse.
|
||||||
->disableOriginalConstructor()
|
$yaml = new YamlCountingParse();
|
||||||
->getMock();
|
$yaml::reset();
|
||||||
$yaml::staticExpects($this->never())
|
$yaml::setParseBehavior(function () {
|
||||||
->method('parse');
|
throw new \RuntimeException('Should not be called');
|
||||||
|
});
|
||||||
|
|
||||||
$conf = $this->provideConfiguration($configFile, null, $compiler, $yaml);
|
$conf = $this->provideConfiguration($configFile, null, $compiler, $yaml);
|
||||||
$conf->getConfig();
|
$conf->getConfig();
|
||||||
@@ -247,13 +248,11 @@ abstract class ConfigurationTestCase extends \PhraseanetTestCase
|
|||||||
->with(['main' => 'tiptop'])
|
->with(['main' => 'tiptop'])
|
||||||
->will($this->returnValue('<?php return ["main" => "tiptop"];'));
|
->will($this->returnValue('<?php return ["main" => "tiptop"];'));
|
||||||
|
|
||||||
$yaml = $this->getMockBuilder('Symfony\Component\Yaml\Yaml')
|
$yaml = new YamlCountingParse();
|
||||||
->disableOriginalConstructor()
|
$yaml::reset();
|
||||||
->getMock();
|
$yaml::setParseBehavior(function () {
|
||||||
$yaml::staticExpects($this->once())
|
return ['main' => 'tiptop'];
|
||||||
->method('parse')
|
});
|
||||||
->will($this->returnValue(['main' => 'tiptop']));
|
|
||||||
|
|
||||||
$conf = $this->provideConfiguration($configFile, null, $compiler, $yaml, true);
|
$conf = $this->provideConfiguration($configFile, null, $compiler, $yaml, true);
|
||||||
$this->assertSame(['main' => 'tiptop'], $conf->getConfig());
|
$this->assertSame(['main' => 'tiptop'], $conf->getConfig());
|
||||||
$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->assertSame('tiptop', $conf['main']);
|
||||||
$this->assertSame('tiptop', $conf['main']);
|
$this->assertSame('tiptop', $conf['main']);
|
||||||
|
$this->assertEquals(1, $yaml::getParseCount());
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testCompileAndWrite()
|
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);
|
||||||
|
}
|
||||||
|
}
|
19
tests/classes/PhraseanetSeTestSubscriber.php
Normal file
19
tests/classes/PhraseanetSeTestSubscriber.php
Normal 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 [];
|
||||||
|
}
|
||||||
|
}
|
@@ -1,22 +1,22 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
use Alchemy\Phrasea\CLI;
|
|
||||||
use Alchemy\Phrasea\Application;
|
use Alchemy\Phrasea\Application;
|
||||||
|
use Alchemy\Phrasea\Authentication\ACLProvider;
|
||||||
use Alchemy\Phrasea\Border\File;
|
use Alchemy\Phrasea\Border\File;
|
||||||
|
use Alchemy\Phrasea\CLI;
|
||||||
use Alchemy\Phrasea\Model\Entities\Session;
|
use Alchemy\Phrasea\Model\Entities\Session;
|
||||||
use Alchemy\Phrasea\Model\Entities\User;
|
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\Handler\NullHandler;
|
||||||
|
use Monolog\Logger;
|
||||||
use Silex\WebTestCase;
|
use Silex\WebTestCase;
|
||||||
|
use Symfony\Component\DomCrawler\Crawler;
|
||||||
use Symfony\Component\HttpFoundation\Response;
|
use Symfony\Component\HttpFoundation\Response;
|
||||||
use Symfony\Component\HttpKernel\Client;
|
use Symfony\Component\HttpKernel\Client;
|
||||||
use Symfony\Component\DomCrawler\Crawler;
|
|
||||||
use Symfony\Component\Routing\RequestContext;
|
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
|
abstract class PhraseanetTestCase extends WebTestCase
|
||||||
{
|
{
|
||||||
@@ -342,10 +342,7 @@ abstract class PhraseanetTestCase extends WebTestCase
|
|||||||
|
|
||||||
$app['translator'] = $this->createTranslatorMock();
|
$app['translator'] = $this->createTranslatorMock();
|
||||||
|
|
||||||
$app['phraseanet.SE.subscriber'] = $this->getMock('Symfony\Component\EventDispatcher\EventSubscriberInterface');
|
$app['phraseanet.SE.subscriber'] = new PhraseanetSeTestSubscriber();
|
||||||
$app['phraseanet.SE.subscriber']::staticExpects($this->any())
|
|
||||||
->method('getSubscribedEvents')
|
|
||||||
->will($this->returnValue([]));
|
|
||||||
|
|
||||||
$app['orm.em'] = $app->extend('orm.em', function($em, $app) {
|
$app['orm.em'] = $app->extend('orm.em', function($em, $app) {
|
||||||
|
|
||||||
@@ -710,7 +707,7 @@ abstract class PhraseanetTestCase extends WebTestCase
|
|||||||
|
|
||||||
protected function createSearchEngineMock()
|
protected function createSearchEngineMock()
|
||||||
{
|
{
|
||||||
$mock = $this->getMock('Alchemy\Phrasea\SearchEngine\SearchEngineInterface');
|
$mock = $this->getMock(SearchEngineInterface::class);
|
||||||
$mock->expects($this->any())
|
$mock->expects($this->any())
|
||||||
->method('createSubscriber')
|
->method('createSubscriber')
|
||||||
->will($this->returnValue($this->getMock('Symfony\Component\EventDispatcher\EventSubscriberInterface')));
|
->will($this->returnValue($this->getMock('Symfony\Component\EventDispatcher\EventSubscriberInterface')));
|
||||||
@@ -720,9 +717,6 @@ abstract class PhraseanetTestCase extends WebTestCase
|
|||||||
$mock->expects($this->any())
|
$mock->expects($this->any())
|
||||||
->method('getStatus')
|
->method('getStatus')
|
||||||
->will($this->returnValue([]));
|
->will($this->returnValue([]));
|
||||||
$mock->staticExpects($this->any())
|
|
||||||
->method('createSubscriber')
|
|
||||||
->will($this->returnValue($this->getMock('Symfony\Component\EventDispatcher\EventSubscriberInterface')));
|
|
||||||
|
|
||||||
return $mock;
|
return $mock;
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user