Skip to content

Commit

Permalink
Merge pull request #1040 from sebastianblum/php-cs-fixer
Browse files Browse the repository at this point in the history
[CS] Implement new php-cs-fixer rules and related code cleanup
  • Loading branch information
robfrawley committed Feb 18, 2018
2 parents 2eafbe8 + 2c62b7f commit ef42b7a
Show file tree
Hide file tree
Showing 5 changed files with 98 additions and 34 deletions.
9 changes: 5 additions & 4 deletions .gitignore
@@ -1,9 +1,10 @@
/.idea/
/.php_cs.cache
/bin/
/phpunit.xml
/composer.lock
/composer.phar
/vendor/
/Tests/Functional/app/web/media/cache
/phpunit.xml
/Tests/Functional/app/public/media/cache
/.idea/
/Tests/Functional/app/web/media/cache
/var/
/vendor/
80 changes: 67 additions & 13 deletions .php_cs.dist
Expand Up @@ -9,24 +9,78 @@
* file that was distributed with this source code.
*/

use SLLH\StyleCIBridge\ConfigBridge;
use PhpCsFixer\Config;
use PhpCsFixer\Finder;

require_once __DIR__.'/vendor/sllh/php-cs-fixer-styleci-bridge/autoload.php';

$header = <<<EOF
$header = <<<HEADER
This file is part of the `liip/LiipImagineBundle` project.
(c) https://github.com/liip/LiipImagineBundle/graphs/contributors
For the full copyright and license information, please view the LICENSE.md
file that was distributed with this source code.
EOF;

$config = ConfigBridge::create();
$config
->setRules(array_merge($config->getRules(), [
'header_comment' => ['header' => $header],
]))
->setUsingCache(false);
HEADER;

return $config;
return Config::create()
->setUsingCache(true)
->setRiskyAllowed(true)
->setFinder((new Finder())->in(__DIR__))
->setRules([
'@Symfony' => true,
'@Symfony:risky' => true,
'@PHPUnit57Migration:risky' => true,
'array_syntax' => [
'syntax' => 'short'
],
'combine_consecutive_issets' => true,
'combine_consecutive_unsets' => true,
'escape_implicit_backslashes' => true,
'explicit_indirect_variable' => true,
'final_internal_class' => true,
'header_comment' => [
'header' => $header,
'separate' => 'both'
],
'heredoc_to_nowdoc' => true,
'linebreak_after_opening_tag' => true,
'list_syntax' => [
'syntax' => 'short',
],
'mb_str_functions' => true,
'multiline_whitespace_before_semicolons' => [
'strategy' => 'no_multi_line',
],
'no_php4_constructor' => true,
'no_short_echo_tag' => true,
'no_unreachable_default_argument_value' => true,
'no_useless_else' => true,
'no_useless_return' => true,
'ordered_class_elements' => [
'order' => [
'use_trait',
'constant_public',
'constant_protected',
'constant_private',
'property_public',
'property_protected',
'property_private',
'construct',
'destruct',
'magic',
'phpunit',
'method_public',
'method_protected',
'method_private'
],
],
'ordered_imports' => true,
'php_unit_strict' => true,
'php_unit_no_expectation_annotation' => true,
'php_unit_test_class_requires_covers' => true,
'phpdoc_order' => true,
'phpdoc_summary' => false,
'psr4' => true,
'semicolon_after_instruction' => true,
'strict_comparison' => true,
'strict_param' => true,
]);
8 changes: 4 additions & 4 deletions Tests/Async/ResolveCacheProcessorTest.php
Expand Up @@ -172,7 +172,7 @@ public function testShouldCreateFilteredImage()

$result = $processor->process($message, new NullContext());

$this->assertEquals(Result::ACK, $result);
$this->assertEquals(Result::ACK, (string) $result);
}

public function testShouldCreateOneImagePerFilter()
Expand Down Expand Up @@ -211,7 +211,7 @@ public function testShouldCreateOneImagePerFilter()

$result = $processor->process($message, new NullContext());

$this->assertEquals(Result::ACK, $result);
$this->assertEquals(Result::ACK, (string) $result);
}

public function testShouldOnlyCreateImageForRequestedFilter()
Expand Down Expand Up @@ -241,7 +241,7 @@ public function testShouldOnlyCreateImageForRequestedFilter()

$result = $processor->process($message, new NullContext());

$this->assertEquals(Result::ACK, $result);
$this->assertEquals(Result::ACK, (string) $result);
}

public function testShouldCreateOneImagePerRequestedFilter()
Expand Down Expand Up @@ -275,7 +275,7 @@ public function testShouldCreateOneImagePerRequestedFilter()

$result = $processor->process($message, new NullContext());

$this->assertEquals(Result::ACK, $result);
$this->assertEquals(Result::ACK, (string) $result);
}

public function testShouldBurstCacheWhenResolvingForced()
Expand Down
Expand Up @@ -69,7 +69,7 @@ public function testCreateResolverDefinitionOnCreate()
$this->assertEquals('liip_imagine.cache.resolver.prototype.aws_s3', $resolverDefinition->getParent());

$this->assertInstanceOf(Reference::class, $resolverDefinition->getArgument(0));
$this->assertEquals('liip_imagine.cache.resolver.the_resolver_name.client', $resolverDefinition->getArgument(0));
$this->assertEquals('liip_imagine.cache.resolver.the_resolver_name.client', (string) $resolverDefinition->getArgument(0));

$this->assertEquals('theBucket', $resolverDefinition->getArgument(1));
$this->assertEquals('theAcl', $resolverDefinition->getArgument(2));
Expand Down Expand Up @@ -149,7 +149,7 @@ public function testWrapResolverWithProxyOnCreateWithoutCache()
$this->assertEquals('liip_imagine.cache.resolver.prototype.proxy', $resolverDefinition->getParent());

$this->assertInstanceOf(Reference::class, $resolverDefinition->getArgument(0));
$this->assertEquals('liip_imagine.cache.resolver.the_resolver_name.proxied', $resolverDefinition->getArgument(0));
$this->assertEquals('liip_imagine.cache.resolver.the_resolver_name.proxied', (string) $resolverDefinition->getArgument(0));

$this->assertEquals(array('foo'), $resolverDefinition->getArgument(1));
}
Expand Down Expand Up @@ -183,10 +183,10 @@ public function testWrapResolverWithCacheOnCreateWithoutProxy()
$this->assertEquals('liip_imagine.cache.resolver.prototype.cache', $resolverDefinition->getParent());

$this->assertInstanceOf(Reference::class, $resolverDefinition->getArgument(0));
$this->assertEquals('the_cache_service_id', $resolverDefinition->getArgument(0));
$this->assertEquals('the_cache_service_id', (string) $resolverDefinition->getArgument(0));

$this->assertInstanceOf(Reference::class, $resolverDefinition->getArgument(1));
$this->assertEquals('liip_imagine.cache.resolver.the_resolver_name.cached', $resolverDefinition->getArgument(1));
$this->assertEquals('liip_imagine.cache.resolver.the_resolver_name.cached', (string) $resolverDefinition->getArgument(1));
}

public function testWrapResolverWithProxyAndCacheOnCreate()
Expand Down Expand Up @@ -216,7 +216,7 @@ public function testWrapResolverWithProxyAndCacheOnCreate()
$this->assertEquals('liip_imagine.cache.resolver.prototype.proxy', $cachedResolverDefinition->getParent());

$this->assertInstanceOf(Reference::class, $cachedResolverDefinition->getArgument(0));
$this->assertEquals('liip_imagine.cache.resolver.the_resolver_name.proxied', $cachedResolverDefinition->getArgument(0));
$this->assertEquals('liip_imagine.cache.resolver.the_resolver_name.proxied', (string) $cachedResolverDefinition->getArgument(0));

$this->assertEquals(array('foo'), $cachedResolverDefinition->getArgument(1));

Expand All @@ -226,10 +226,10 @@ public function testWrapResolverWithProxyAndCacheOnCreate()
$this->assertEquals('liip_imagine.cache.resolver.prototype.cache', $resolverDefinition->getParent());

$this->assertInstanceOf(Reference::class, $resolverDefinition->getArgument(0));
$this->assertEquals('the_cache_service_id', $resolverDefinition->getArgument(0));
$this->assertEquals('the_cache_service_id', (string) $resolverDefinition->getArgument(0));

$this->assertInstanceOf(Reference::class, $resolverDefinition->getArgument(1));
$this->assertEquals('liip_imagine.cache.resolver.the_resolver_name.cached', $resolverDefinition->getArgument(1));
$this->assertEquals('liip_imagine.cache.resolver.the_resolver_name.cached', (string) $resolverDefinition->getArgument(1));
}

public function testWrapResolverWithProxyMatchReplaceStrategyOnCreate()
Expand Down Expand Up @@ -259,7 +259,7 @@ public function testWrapResolverWithProxyMatchReplaceStrategyOnCreate()
$this->assertEquals('liip_imagine.cache.resolver.prototype.proxy', $cachedResolverDefinition->getParent());

$this->assertInstanceOf(Reference::class, $cachedResolverDefinition->getArgument(0));
$this->assertEquals('liip_imagine.cache.resolver.the_resolver_name.proxied', $cachedResolverDefinition->getArgument(0));
$this->assertEquals('liip_imagine.cache.resolver.the_resolver_name.proxied', (string) $cachedResolverDefinition->getArgument(0));

$this->assertEquals(array('foo' => 'bar'), $cachedResolverDefinition->getArgument(1));
}
Expand Down
19 changes: 14 additions & 5 deletions Tests/DependencyInjection/LiipImagineExtensionTest.php
Expand Up @@ -197,11 +197,20 @@ private function assertHasDefinition($id)
*/
private function assertDICConstructorArguments(Definition $definition, array $arguments)
{
$this->assertEquals($arguments, $definition->getArguments(), "Expected and actual DIC Service constructor arguments of definition '".$definition->getClass()."' don't match.");
}
$castArrayElementsToString = function (array $a): array {
return array_map(function ($v) { return (string) $v; }, $a);
};

protected function tearDown()
{
unset($this->containerBuilder);
$implodeArrayElements = function (array $a): string {
return sprintf('[%s]:%d', implode(',', $a), count($a));
};

$expectedArguments = $castArrayElementsToString($arguments);
$providedArguments = $castArrayElementsToString($definition->getArguments());

$this->assertSame($expectedArguments, $providedArguments, vsprintf('Definition arguments (%s) do not match expected arguments (%s).', [
$implodeArrayElements($providedArguments),
$implodeArrayElements($expectedArguments),
]));
}
}

0 comments on commit ef42b7a

Please sign in to comment.