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

cleanup phpunit tests now that we don't need ancient legacy support anymore #1558

Merged
merged 1 commit into from
Jan 6, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
2 changes: 1 addition & 1 deletion .github/workflows/php-cs-fixer.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ jobs:
- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: 8.0
php-version: 8.3
coverage: none
tools: php-cs-fixer

Expand Down
10 changes: 1 addition & 9 deletions src/DependencyInjection/Compiler/AssetsVersionCompilerPass.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,20 +54,12 @@ public function process(ContainerBuilder $container): void
$version = $versionStrategyDefinition->getArgument(0);
$format = $versionStrategyDefinition->getArgument(1);
$format = $container->resolveEnvPlaceholders($format);
if ($format && !$this->str_ends_with($format, '?%%s')) {
if ($format && !str_ends_with($format, '?%%s')) {
$this->log($container, 'Can not handle assets versioning with custom format "'.$format.'". asset twig function can likely not be used with the imagine_filter');

return;
}

$runtimeDefinition->setArgument(1, $version);
}

/**
* Can be replaced with the built-in method when dropping support for PHP < 8.0
*/
private function str_ends_with(string $haystack, string $needle): bool
{
return mb_substr($haystack, -mb_strlen($needle)) === $needle;
}
}
230 changes: 1 addition & 229 deletions tests/AbstractTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,27 +11,8 @@

namespace Liip\ImagineBundle\Tests;

use Imagine\Image\ImageInterface;
use Imagine\Image\ImagineInterface;
use Imagine\Image\Metadata\MetadataBag;
use Liip\ImagineBundle\Binary\Loader\LoaderInterface;
use Liip\ImagineBundle\Binary\MimeTypeGuesserInterface;
use Liip\ImagineBundle\Config\Controller\ControllerConfig;
use Liip\ImagineBundle\Imagine\Cache\CacheManager;
use Liip\ImagineBundle\Imagine\Cache\Resolver\ResolverInterface;
use Liip\ImagineBundle\Imagine\Cache\SignerInterface;
use Liip\ImagineBundle\Imagine\Data\DataManager;
use Liip\ImagineBundle\Imagine\Filter\FilterConfiguration;
use Liip\ImagineBundle\Imagine\Filter\FilterManager;
use Liip\ImagineBundle\Imagine\Filter\PostProcessor\PostProcessorInterface;
use Liip\ImagineBundle\Service\FilterService;
use PHPUnit\Framework\MockObject\MockObject;
use PHPUnit\Framework\TestCase;
use Psr\Log\LoggerInterface;
use Symfony\Component\Filesystem\Filesystem;
use Symfony\Component\Mime\MimeTypesInterface;
use Symfony\Component\Routing\RouterInterface;
use Symfony\Contracts\EventDispatcher\EventDispatcherInterface;

abstract class AbstractTest extends TestCase
{
Expand Down Expand Up @@ -65,216 +46,7 @@ protected function tearDown(): void
}
}

/**
* @return string[]
*/
public function invalidPathProvider(): array
{
return [
[$this->fixturesPath.'/assets/../../foobar.png'],
[$this->fixturesPath.'/assets/some_folder/../foobar.png'],
['../../outside/foobar.jpg'],
];
}

public function expectExceptionMessageMatchesBC(string $regularExpression): void
{
if (method_exists($this, 'expectExceptionMessageMatches')) {
$this->expectExceptionMessageMatches($regularExpression);
} else {
$this->expectExceptionMessageRegExp($regularExpression);
}
}

protected function createFilterConfiguration(): FilterConfiguration
{
$config = new FilterConfiguration();
$config->set('thumbnail', [
'size' => [180, 180],
'mode' => 'outbound',
]);

return $config;
}

/**
* @return MockObject&CacheManager
*/
protected function createCacheManagerMock()
{
return $this
->getMockBuilder(CacheManager::class)
->setConstructorArgs([
$this->createFilterConfiguration(),
$this->createRouterInterfaceMock(),
$this->createSignerInterfaceMock(),
$this->createEventDispatcherInterfaceMock(),
])
->getMock();
}

/**
* @return MockObject&FilterConfiguration
*/
protected function createFilterConfigurationMock()
{
return $this->createObjectMock(FilterConfiguration::class);
}

/**
* @return MockObject&SignerInterface
*/
protected function createSignerInterfaceMock()
{
return $this->createObjectMock(SignerInterface::class);
}

/**
* @return MockObject&RouterInterface
*/
protected function createRouterInterfaceMock()
{
return $this->createObjectMock(RouterInterface::class);
}

/**
* @return MockObject&ResolverInterface
*/
protected function createCacheResolverInterfaceMock()
{
return $this->createObjectMock(ResolverInterface::class);
}

/**
* @return MockObject&EventDispatcherInterface
*/
protected function createEventDispatcherInterfaceMock()
{
return $this->createObjectMock(EventDispatcherInterface::class);
}

/**
* @return MockObject&ImageInterface
*/
protected function getImageInterfaceMock()
{
return $this->createObjectMock(ImageInterface::class);
}

/**
* @return MockObject&MetadataBag
*/
protected function getMetadataBagMock()
{
return $this->createObjectMock(MetadataBag::class);
}

/**
* @return MockObject&ImagineInterface
*/
protected function createImagineInterfaceMock()
{
return $this->createObjectMock(ImagineInterface::class);
}

/**
* @return MockObject&LoggerInterface
*/
protected function createLoggerInterfaceMock()
{
return $this->createObjectMock(LoggerInterface::class);
}

/**
* @return MockObject&LoaderInterface
*/
protected function createBinaryLoaderInterfaceMock()
{
return $this->createObjectMock(LoaderInterface::class);
}

/**
* @return MockObject&MimeTypeGuesserInterface
*/
protected function createMimeTypeGuesserInterfaceMock()
{
return $this->createObjectMock(MimeTypeGuesserInterface::class);
}

/**
* @return MockObject&MimeTypesInterface
*/
protected function createExtensionGuesserInterfaceMock()
{
return $this->createObjectMock(MimeTypesInterface::class);
}

/**
* @return MockObject&PostProcessorInterface
*/
protected function createPostProcessorInterfaceMock()
{
return $this->createObjectMock(PostProcessorInterface::class);
}

/**
* @return MockObject&FilterManager
*/
protected function createFilterManagerMock()
{
return $this->createObjectMock(FilterManager::class, [], false);
}

/**
* @return MockObject&FilterService
*/
protected function createFilterServiceMock()
{
return $this->createObjectMock(FilterService::class);
}

/**
* @return MockObject&DataManager
*/
protected function createDataManagerMock()
{
return $this->createObjectMock(DataManager::class, [], false);
}

protected function createControllerConfigInstance(int $redirectResponseCode = null): ControllerConfig
{
return new ControllerConfig($redirectResponseCode ?? 301);
}

/**
* @param string[] $methods
* @param mixed[] $constructorParams
*/
protected function createObjectMock(string $object, array $methods = [], bool $constructorInvoke = false, array $constructorParams = []): MockObject
{
$builder = $this->getMockBuilder($object);

if (\count($methods) > 0) {
$builder->setMethods($methods);
}

if ($constructorInvoke) {
$builder->enableOriginalConstructor();
} else {
$builder->disableOriginalConstructor();
}

if (\count($constructorParams) > 0) {
$builder->setConstructorArgs($constructorParams);
}

return $builder->getMock();
}

/**
* @param object $object
*/
protected function getVisibilityRestrictedMethod($object, string $name): \ReflectionMethod
protected function getVisibilityRestrictedMethod(object $object, string $name): \ReflectionMethod
{
$r = new \ReflectionObject($object);

Expand Down
4 changes: 1 addition & 3 deletions tests/Binary/Loader/AbstractDoctrineLoaderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,7 @@ class AbstractDoctrineLoaderTest extends TestCase

protected function setUp(): void
{
$this->om = $this
->getMockBuilder(ObjectManager::class)
->getMock();
$this->om = $this->createMock(ObjectManager::class);

$this->loader = $this
->getMockBuilder(AbstractDoctrineLoader::class)
Expand Down
4 changes: 2 additions & 2 deletions tests/Binary/Loader/ChainLoaderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ public function provideInvalidPathsData(): array
public function testThrowsIfFileDoesNotExist(string $path): void
{
$this->expectException(NotLoadableException::class);
$this->expectExceptionMessageMatchesBC('{Source image not resolvable "[^"]+" using "FileSystemLoader=\[foo\]" 1 loaders}');
$this->expectExceptionMessageMatches('{Source image not resolvable "[^"]+" using "FileSystemLoader=\[foo\]" 1 loaders}');

$this->getChainLoader()->find($path);
}
Expand All @@ -102,7 +102,7 @@ public function testThrowsIfFileDoesNotExist(string $path): void
public function testThrowsIfFileDoesNotExistWithMultipleLoaders(string $path): void
{
$this->expectException(NotLoadableException::class);
$this->expectExceptionMessageMatchesBC('{Source image not resolvable "[^"]+" using "FileSystemLoader=\[foo\], FileSystemLoader=\[bar\]" 2 loaders \(internal exceptions: FileSystemLoader=\[.+\], FileSystemLoader=\[.+\]\)\.}');
$this->expectExceptionMessageMatches('{Source image not resolvable "[^"]+" using "FileSystemLoader=\[foo\], FileSystemLoader=\[bar\]" 2 loaders \(internal exceptions: FileSystemLoader=\[.+\], FileSystemLoader=\[.+\]\)\.}');

$this->getChainLoader([], [
'foo' => $this->createFileSystemLoader(
Expand Down
70 changes: 0 additions & 70 deletions tests/Binary/Loader/FlysystemLoaderTest.php

This file was deleted.

6 changes: 1 addition & 5 deletions tests/Binary/Loader/FlysystemV2LoaderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,6 @@ protected function setUp(): void
{
parent::setUp();

if (!interface_exists(FilesystemOperator::class)) {
$this->markTestSkipped('Requires the league/flysystem:^2.0 package.');
}

$this->flyFilesystem = new Filesystem(new LocalFilesystemAdapter($this->fixturesPath));
}

Expand All @@ -57,7 +53,7 @@ public function testReturnImageContentOnFind(): void
public function testThrowsIfInvalidPathGivenOnFind(): void
{
$this->expectException(NotLoadableException::class);
$this->expectExceptionMessageMatchesBC('{Source image .+ not found}');
$this->expectExceptionMessageMatches('{Source image .+ not found}');

$loader = $this->getFlysystemLoader();

Expand Down
Loading
Loading