Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Upgrading to Symfony5 #1256

Merged
merged 14 commits into from
Jan 6, 2020
Merged
Show file tree
Hide file tree
Changes from 8 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 0 additions & 3 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,6 @@ matrix:
- php: '7.1'
env:
- SYMFONY_VERSION=3.4.*
- php: '7.1'
env:
- SYMFONY_VERSION=4.2.*
- php: '7.1'
env:
- SYMFONY_VERSION=4.3.*
Expand Down
18 changes: 14 additions & 4 deletions Imagine/Filter/Loader/PasteFilterLoader.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,12 @@ class PasteFilterLoader implements LoaderInterface
/**
* @var string
*/
protected $rootPath;
protected $projectDir;

public function __construct(ImagineInterface $imagine, $rootPath)
public function __construct(ImagineInterface $imagine, $projectDir)
{
$this->imagine = $imagine;
$this->rootPath = $rootPath;
$this->projectDir = $projectDir;
}

/**
Expand All @@ -46,7 +46,17 @@ public function load(ImageInterface $image, array $options = [])
$x = isset($options['start'][0]) ? $options['start'][0] : null;
$y = isset($options['start'][1]) ? $options['start'][1] : null;

$destImage = $this->imagine->open($this->rootPath.'/'.$options['image']);
$file = $this->projectDir . '/' . $options['image'];

if (!file_exists($file)) {
@trigger_error(
'The ' . $file . ' does not exists, change the path based on kernel.project_dir parameter',
E_USER_DEPRECATED
);
$file = $this->projectDir . '/app/' . $options['image'];
}

$destImage = $this->imagine->open($file);

return $image->paste($destImage, new Point($x, $y));
}
Expand Down
18 changes: 14 additions & 4 deletions Imagine/Filter/Loader/WatermarkFilterLoader.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,12 @@ class WatermarkFilterLoader implements LoaderInterface
/**
* @var string
*/
protected $rootPath;
protected $projectDir;

public function __construct(ImagineInterface $imagine, $rootPath)
public function __construct(ImagineInterface $imagine, $projectDir)
{
$this->imagine = $imagine;
$this->rootPath = $rootPath;
$this->projectDir = $projectDir;
}

/**
Expand All @@ -53,7 +53,17 @@ public function load(ImageInterface $image, array $options = [])
$options['size'] = mb_substr($options['size'], 0, -1) / 100;
}

$watermark = $this->imagine->open($this->rootPath.'/'.$options['image']);
$file = $this->projectDir . '/' . $options['image'];

if (!file_exists($file)) {
@trigger_error(
'The ' . $file . ' does not exists, change the path based on kernel.project_dir parameter',
E_USER_DEPRECATED
);
$file = $this->projectDir . '/app/' . $options['image'];
}

$watermark = $this->imagine->open($file);

$size = $image->getSize();
$watermarkSize = $watermark->getSize();
Expand Down
4 changes: 2 additions & 2 deletions Resources/config/imagine.xml
Original file line number Diff line number Diff line change
Expand Up @@ -212,13 +212,13 @@
<service id="liip_imagine.filter.loader.paste" class="Liip\ImagineBundle\Imagine\Filter\Loader\PasteFilterLoader">
<tag name="liip_imagine.filter.loader" loader="paste" />
<argument type="service" id="liip_imagine" />
<argument>%kernel.root_dir%</argument>
<argument>%kernel.project_dir%</argument>
</service>

<service id="liip_imagine.filter.loader.watermark" class="Liip\ImagineBundle\Imagine\Filter\Loader\WatermarkFilterLoader">
<tag name="liip_imagine.filter.loader" loader="watermark" />
<argument type="service" id="liip_imagine" />
<argument>%kernel.root_dir%</argument>
<argument>%kernel.project_dir%</argument>
</service>

<service id="liip_imagine.filter.loader.background" class="Liip\ImagineBundle\Imagine\Filter\Loader\BackgroundFilterLoader">
Expand Down
4 changes: 2 additions & 2 deletions Resources/doc/filters/general.rst
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ Example configuration:
# use and setup the "watermark" filter
watermark:

# path to the watermark file (prepended with "%kernel.root_dir%")
# path to the watermark file (prepended with "%kernel.project_dir%")
image: Resources/data/watermark.png

# size of the water mark relative to the input image
Expand All @@ -199,7 +199,7 @@ Watermark Options

:strong:`image:` ``string``
Sets the location of the watermark image. The value of this option is prepended
with the resolved value of the ``%kernel.root_dir%`` parameter.
with the resolved value of the ``%kernel.project_dir%`` parameter.

:strong:`size:` ``float``
Sets the size of the watermark as a relative ration, relative to the original
Expand Down
4 changes: 2 additions & 2 deletions Tests/AbstractTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ abstract class AbstractTest extends TestCase
*/
protected $temporaryPath;

protected function setUp()
protected function setUp(): void
{
$this->fixturesPath = realpath(__DIR__.DIRECTORY_SEPARATOR.'Fixtures');
$this->temporaryPath = sys_get_temp_dir().DIRECTORY_SEPARATOR.'liip_imagine_test';
Expand All @@ -64,7 +64,7 @@ protected function setUp()
$this->filesystem->mkdir($this->temporaryPath);
}

protected function tearDown()
protected function tearDown(): void
{
if (!$this->filesystem) {
return;
Expand Down
2 changes: 1 addition & 1 deletion Tests/Async/CacheResolvedTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
*/
class CacheResolvedTest extends TestCase
{
public static function setUpBeforeClass()
public static function setUpBeforeClass(): void
{
if (!class_exists(EnqueueBundle::class)) {
self::markTestSkipped('The tests are run without enqueue integration. Skip them');
Expand Down
2 changes: 1 addition & 1 deletion Tests/Async/ResolveCacheProcessorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
*/
class ResolveCacheProcessorTest extends AbstractTest
{
public static function setUpBeforeClass()
public static function setUpBeforeClass(): void
{
if (!class_exists(EnqueueBundle::class)) {
self::markTestSkipped('The tests are run without enqueue integration. Skip them');
Expand Down
2 changes: 1 addition & 1 deletion Tests/Async/ResolveCacheTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
*/
class ResolveCacheTest extends TestCase
{
public static function setUpBeforeClass()
public static function setUpBeforeClass(): void
{
if (!class_exists(EnqueueBundle::class)) {
self::markTestSkipped('The tests are run without enqueue integration. Skip them');
Expand Down
2 changes: 1 addition & 1 deletion Tests/Binary/Loader/AbstractDoctrineLoaderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ class AbstractDoctrineLoaderTest extends TestCase
*/
private $loader;

public function setUp()
public function setUp(): void
{
if (!interface_exists(ObjectManager::class)) {
$this->markTestSkipped('Requires the doctrine/orm package.');
Expand Down
2 changes: 1 addition & 1 deletion Tests/Binary/Loader/FlysystemLoaderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ class FlysystemLoaderTest extends AbstractTest
{
private $flyFilesystem;

public function setUp()
public function setUp(): void
{
parent::setUp();

Expand Down
2 changes: 1 addition & 1 deletion Tests/Config/FilterSetBuilderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ class FilterSetBuilderTest extends TestCase
*/
private $model;

protected function setUp()
protected function setUp(): void
{
$this->filterSetFactoryMock = $this->createMock(StackFactoryInterface::class);
$this->filterFactoryCollectionMock = $this->createMock(FilterFactoryCollection::class);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
*/
class FlysystemLoaderFactoryTest extends TestCase
{
public function setUp()
public function setUp(): void
{
parent::setUp();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
*/
class FlysystemResolverFactoryTest extends TestCase
{
public function setUp()
public function setUp(): void
{
parent::setUp();

Expand Down
4 changes: 0 additions & 4 deletions Tests/Events/CacheResolveEventTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,6 @@
*/
class CacheResolveEventTest extends TestCase
{
protected function setUp()
{
}

public function testShouldAllowSetPathInConstruct(): void
{
$event = new CacheResolveEvent('default_path', 'default_filter');
Expand Down
2 changes: 1 addition & 1 deletion Tests/Form/Type/ImageTypeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
*/
class ImageTypeTest extends AbstractTest
{
protected function setUp()
protected function setUp(): void
{
if (!class_exists(AbstractType::class)) {
$this->markTestSkipped('Requires the symfony/form package.');
Expand Down
2 changes: 1 addition & 1 deletion Tests/Functional/AbstractSetupWebTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ class AbstractSetupWebTestCase extends AbstractWebTestCase
*/
protected $cacheRoot;

public function setUp()
public function setUp(): void
{
parent::setUp();

Expand Down
2 changes: 2 additions & 0 deletions Tests/Imagine/Cache/CacheManagerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -731,6 +731,8 @@ private function getDispatcherCallbackWithBC(EventDispatcherInterface $dispatche
} else {
$callable($name, $event);
}

return $event;
};
}

Expand Down
9 changes: 7 additions & 2 deletions Tests/Imagine/Cache/Resolver/CacheResolverTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ class CacheResolverTest extends AbstractTest
protected $path = 'MadCat2.jpeg';
protected $webPath = '/media/cache/thumbnail/MadCat2.jpeg';

protected function setUp()
protected function setUp(): void
{
if (!class_exists(ArrayCache::class)) {
$this->markTestSkipped('Requires the doctrine/cache package.');
Expand Down Expand Up @@ -194,7 +194,12 @@ public function testRemoveAllFilterCacheOnRemove(): void
*/
private function getCacheEntries(ArrayCache $cache): array
{
$cacheEntries = $this->readAttribute($cache, 'data');
$reflector = new \ReflectionObject($cache);
$attribute = $reflector->getProperty('data');
$attribute->setAccessible(true);
$cacheEntries = $attribute->getValue($cache);
$attribute->setAccessible(false);

unset($cacheEntries['DoctrineNamespaceCacheKey[]']);

return $cacheEntries;
Expand Down
2 changes: 1 addition & 1 deletion Tests/Imagine/Cache/Resolver/FlysystemResolverTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
*/
class FlysystemResolverTest extends AbstractTest
{
public function setUp()
public function setUp(): void
{
parent::setUp();

Expand Down
2 changes: 1 addition & 1 deletion Tests/Imagine/Cache/Resolver/ProxyResolverTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ class ProxyResolverTest extends AbstractTest
*/
private $resolver;

public function setUp()
public function setUp(): void
{
$this->primaryResolver = $this->createObjectMock(ResolverInterface::class);
$this->resolver = new ProxyResolver($this->primaryResolver, ['http://images.example.com']);
Expand Down
18 changes: 16 additions & 2 deletions Tests/Imagine/Cache/Resolver/WebPathResolverTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ class WebPathResolverTest extends TestCase
*/
private $existingFile;

public function setUp()
public function setUp(): void
{
$this->filesystem = new Filesystem();
$this->basePath = sys_get_temp_dir().'/aWebRoot';
Expand All @@ -48,7 +48,7 @@ public function setUp()
$this->filesystem->touch($this->existingFile);
}

public function tearDown()
public function tearDown(): void
{
$this->filesystem->remove($this->basePath);
}
Expand Down Expand Up @@ -502,4 +502,18 @@ protected function createFilesystemMock()
{
return $this->getMockBuilder(Filesystem::class)->getMock();
}

/**
* Method was added because it is deprecated in PHPUnit 8
*/
public static function assertAttributeSame($expected, string $actualAttributeName, $actualClassOrObject, string $message = ''): void
{
$reflector = new \ReflectionObject($actualClassOrObject);
$attribute = $reflector->getProperty($actualAttributeName);
$attribute->setAccessible(true);
$actual = $attribute->getValue($actualClassOrObject);
$attribute->setAccessible(false);

self::assertSame($expected, $actual, $message);
}
}
32 changes: 16 additions & 16 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,33 +20,33 @@
"require": {
"php": "^7.1",
"imagine/imagine": "^0.7.1|^1.1",
"symfony/asset": "^3.4|^4.2|^5.0",
"symfony/filesystem": "^3.4|^4.2|^5.0",
"symfony/finder": "^3.4|^4.2|^5.0",
"symfony/framework-bundle": "^3.4|^4.2|^5.0",
"symfony/options-resolver": "^3.4|^4.2|^5.0",
"symfony/process": "^3.4|^4.2|^5.0",
"symfony/templating": "^3.4|^4.2|^5.0",
"symfony/translation": "^3.4|^4.2|^5.0"
"symfony/asset": "^3.4|^4.3|^5.0",
"symfony/filesystem": "^3.4|^3|^5.0",
"symfony/finder": "^3.4|^4.3|^5.0",
"symfony/framework-bundle": "^3.4|^4.3|^5.0",
"symfony/options-resolver": "^3.4|^4.3|^5.0",
"symfony/process": "^3.4|^4.3|^5.0",
"symfony/templating": "^3.4|^4.3|^5.0",
"symfony/translation": "^3.4|^4.3|^5.0"
},
"require-dev": {
"ext-gd": "*",
"amazonwebservices/aws-sdk-for-php": "^1.0",
"aws/aws-sdk-php": "^2.4",
"doctrine/cache": "^1.1",
"doctrine/orm": "^2.3",
"enqueue/enqueue-bundle": "^0.9",
"enqueue/enqueue-bundle": "^0.10",
"friendsofphp/php-cs-fixer": "^2.10",
"league/flysystem": "^1.0",
"psr/log": "^1.0",
"symfony/browser-kit": "^3.4|^4.2|^5.0",
"symfony/console": "^3.4|^4.2|^5.0",
"symfony/dependency-injection": "^3.4|^4.2|^5.0",
"symfony/form": "^3.4|^4.2|^5.0",
"symfony/browser-kit": "^3.4|^4.3|^5.0",
"symfony/console": "^3.4|^4.3|^5.0",
"symfony/dependency-injection": "^3.4|^4.3|^5.0",
"symfony/form": "^3.4|^4.3|^5.0",
"symfony/phpunit-bridge": "^4.3|^5.0",
"symfony/validator": "^3.4|^4.2|^5.0",
"symfony/yaml": "^3.4|^4.2|^5.0",
"twig/twig": "^1.34|^2.4"
"symfony/validator": "^3.4|^4.3|^5.0",
"symfony/yaml": "^3.4|^4.3|^5.0",
"twig/twig": "^1.34|^2.4|^3.0"
},
"suggest": {
"ext-exif": "required to read EXIF metadata from images",
Expand Down