Skip to content

Commit 87d0c4f

Browse files
authored
Merge pull request #2 from webfactory/update_symfony_fix_tests
Fix tests, cover newer Symfony versions
2 parents 13a97b6 + a92eedd commit 87d0c4f

21 files changed

Lines changed: 272 additions & 376 deletions

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
11
composer.lock
22
vendor/
33
phpunit.xml
4+
.php_cs.cache
5+
Tests/Fixtures/cache/

.php_cs.dist

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
<?php
2+
3+
return PhpCsFixer\Config::create()
4+
->setRules(array(
5+
'@Symfony' => true,
6+
'@Symfony:risky' => true,
7+
// 'array_syntax' => array('syntax' => 'long'),
8+
'no_unreachable_default_argument_value' => false,
9+
'braces' => array('allow_single_line_closure' => true),
10+
'heredoc_to_nowdoc' => false,
11+
'phpdoc_annotation_without_dot' => false,
12+
))
13+
->setRiskyAllowed(true)
14+
->setFinder(
15+
PhpCsFixer\Finder::create()
16+
->in(__DIR__)
17+
->notPath('Tests/Fixtures/cache/')
18+
->notPath('vendor/')
19+
)
20+
;

.scrutinizer.yml

Lines changed: 19 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -1,67 +1,29 @@
11
build:
22
environment:
3-
php: '5.5.9'
43
timezone: 'Europe/Berlin'
54
postgresql: false
65
node: false
76
redis: false
7+
variables:
8+
COMPOSER_MEMORY_LIMIT: -1
89

910
tests:
1011
override:
11-
-
12-
command: 'vendor/bin/phpunit --coverage-clover=clover.xml'
13-
coverage:
14-
file: 'clover.xml'
15-
format: 'clover'
12+
- command: 'vendor/bin/phpunit --coverage-clover=clover.xml'
13+
coverage:
14+
file: 'clover.xml'
15+
format: 'clover'
1616

17-
tools:
18-
php_mess_detector:
19-
config:
20-
code_size_rules: { cyclomatic_complexity: true, npath_complexity: true, excessive_method_length: true, excessive_class_length: true, excessive_parameter_list: true, excessive_public_count: true, too_many_fields: true, too_many_methods: true, excessive_class_complexity: true }
21-
design_rules: { number_of_class_children: true, depth_of_inheritance: true, coupling_between_objects: true }
22-
unused_code_rules: { unused_local_variable: true, unused_private_method: true, unused_formal_parameter: true }
23-
naming_rules: { short_variable: true, long_variable: true, short_method: true, boolean_method_name: true }
24-
controversial_rules: { camel_case_class_name: true, camel_case_property_name: true, camel_case_method_name: true, camel_case_parameter_name: true, camel_case_variable_name: true }
25-
php_cs_fixer:
26-
config:
27-
level: all
28-
fixers: { unused_use: true, phpdoc_params: true, braces: true, php_closing_tag: true }
29-
php_analyzer:
30-
config:
31-
suspicious_code: { enabled: true, overriding_parameter: true, overriding_closure_use: true, parameter_closure_use_conflict: true, parameter_multiple_times: true, non_existent_class_in_instanceof_check: true, non_existent_class_in_catch_clause: true, assignment_of_null_return: true, non_commented_switch_fallthrough: true, non_commented_empty_catch_block: true, overriding_private_members: true, use_statement_alias_conflict: true, precedence_in_condition_assignment: true }
32-
verify_php_doc_comments: { enabled: true, parameters: true, return: true, suggest_more_specific_types: true, ask_for_return_if_not_inferrable: true, ask_for_param_type_annotation: true }
33-
loops_must_use_braces: { enabled: true }
34-
simplify_boolean_return: { enabled: true }
35-
phpunit_checks: { enabled: true }
36-
reflection_fixes: { enabled: true }
37-
use_statement_fixes: { enabled: true, order_alphabetically: true, remove_unused: true, preserve_multiple: false, preserve_blanklines: false }
38-
parameter_reference_check: { enabled: false }
39-
checkstyle: { enabled: false, no_trailing_whitespace: true, naming: { enabled: true, local_variable: '^[a-z][a-zA-Z0-9]*$', abstract_class_name: ^Abstract|Factory$, utility_class_name: 'Utils?$', constant_name: '^[A-Z][A-Z0-9]*(?:_[A-Z0-9]+)*$', property_name: '^[a-z][a-zA-Z0-9]*$', method_name: '^(?:[a-z]|__)[a-zA-Z0-9]*$', parameter_name: '^[a-z][a-zA-Z0-9]*$', interface_name: '^[A-Z][a-zA-Z0-9]*Interface$', type_name: '^[A-Z][a-zA-Z0-9]*$', exception_name: '^[A-Z][a-zA-Z0-9]*Exception$', isser_method_name: '^(?:is|has|should|may|supports)' } }
40-
unreachable_code: { enabled: false }
41-
check_access_control: { enabled: false }
42-
typo_checks: { enabled: false }
43-
check_variables: { enabled: false }
44-
check_calls: { enabled: true, too_many_arguments: true, missing_argument: true, argument_type_checks: lenient }
45-
dead_assignments: { enabled: false }
46-
check_usage_context: { enabled: true, foreach: { value_as_reference: true, traversable: true } }
47-
reflection_checks: { enabled: false }
48-
precedence_checks: { enabled: true, assignment_in_condition: true, comparison_of_bit_result: true }
49-
basic_semantic_checks: { enabled: false }
50-
unused_code: { enabled: false }
51-
deprecation_checks: { enabled: false }
52-
useless_function_calls: { enabled: false }
53-
metrics_lack_of_cohesion_methods: { enabled: false }
54-
metrics_coupling: { enabled: true, stable_code: { namespace_prefixes: { }, classes: { } } }
55-
doctrine_parameter_binding: { enabled: false }
56-
doctrine_entity_manager_injection: { enabled: false }
57-
symfony_request_injection: { enabled: false }
58-
doc_comment_fixes: { enabled: false }
59-
php_code_sniffer:
60-
config:
61-
standard: PSR2
62-
sniffs: { psr2: { classes: { property_declaration_sniff: true }, methods: { method_declaration_sniff: true } } }
63-
sensiolabs_security_checker: true
64-
php_loc: true
65-
php_pdepend: true
66-
php_sim: true
67-
php_changetracking: true
17+
nodes:
18+
19+
deps_lowest:
20+
environment:
21+
php: '7.2'
22+
dependencies:
23+
before:
24+
- command: composer update --prefer-lowest
25+
idle_timeout: 600
26+
27+
php_72:
28+
environment:
29+
php: '7.2'

Controller/GuideController.php

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,7 @@
22

33
namespace Webfactory\ShortcodeBundle\Controller;
44

5-
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
65
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Template;
7-
use Symfony\Component\DependencyInjection\Container;
8-
use Symfony\Component\DependencyInjection\ContainerBuilder;
96
use Symfony\Component\HttpFoundation\Request;
107
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
118

@@ -15,7 +12,9 @@
1512
final class GuideController
1613
{
1714
/**
18-
* @var array [
15+
* @var array
16+
*
17+
* Example structure: [
1918
* [
2019
* 'shortcode' => 'img'
2120
* 'example' (optional key) => '[img src="https://upload.wikimedia.org/wikipedia/en/f/f7/RickRoll.png"]'
@@ -32,17 +31,19 @@ public function __construct(array $shortcodeTags)
3231

3332
/**
3433
* @Template()
34+
*
3535
* @return array
3636
*/
3737
public function listAction()
3838
{
3939
return [
40-
'shortcodeTags' => $this->shortcodeTags
40+
'shortcodeTags' => $this->shortcodeTags,
4141
];
4242
}
4343

4444
/**
4545
* @Template()
46+
*
4647
* @return array
4748
*/
4849
public function detailAction($shortcode, Request $request)
@@ -52,7 +53,7 @@ public function detailAction($shortcode, Request $request)
5253
// if custom parameters are provided, replace the example
5354
$customParameters = $request->get('customParameters');
5455
if ($customParameters) {
55-
$shortcodeTag['example'] = $shortcode . ' ' . $customParameters;
56+
$shortcodeTag['example'] = $shortcode.' '.$customParameters;
5657
}
5758

5859
return [

DependencyInjection/WebfactoryShortcodeExtension.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ final class WebfactoryShortcodeExtension extends Extension
1414
{
1515
public function load(array $configs, ContainerBuilder $container)
1616
{
17-
$loader = new XmlFileLoader($container, new FileLocator(__DIR__ . '/../Resources/config'));
17+
$loader = new XmlFileLoader($container, new FileLocator(__DIR__.'/../Resources/config'));
1818
$loader->load('shortcodes.xml');
1919
}
2020
}

Handler/EmbeddedShortcodeHandler.php

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -33,28 +33,29 @@ class EmbeddedShortcodeHandler
3333

3434
/**
3535
* @param FragmentHandler $fragmentHandler
36-
* @param string $controllerName
37-
* @param string $renderer
36+
* @param string $controllerName
37+
* @param string $renderer
3838
* @param LoggerInterface $logger
39-
* @param RequestStack $requestStack
39+
* @param RequestStack $requestStack
4040
*/
4141
public function __construct(
4242
FragmentHandler $fragmentHandler,
4343
$controllerName,
4444
$renderer,
45-
LoggerInterface $logger = null,
46-
RequestStack $requestStack
45+
RequestStack $requestStack,
46+
LoggerInterface $logger = null
4747
) {
4848
$this->fragmentHandler = $fragmentHandler;
4949
$this->controllerName = $controllerName;
5050
$this->renderer = $renderer;
51-
$this->logger = $logger ?: new NullLogger();
5251
$this->requestStack = $requestStack;
52+
$this->logger = $logger ?: new NullLogger();
5353
}
5454

5555
/**
5656
* @param ShortcodeInterface $shortcode
57-
* @return null|string
57+
*
58+
* @return string|null
5859
*/
5960
public function __invoke(ShortcodeInterface $shortcode)
6061
{

Handler/RemoveWrappingParagraphElementsEventHandler.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ function ($state, ReplacedShortcode $r) {
5050
);
5151
}
5252

53-
return $sourceTextBeforeShortcode . $r->getReplacement() . $sourceTextAfterShortcode;
53+
return $sourceTextBeforeShortcode.$r->getReplacement().$sourceTextAfterShortcode;
5454
},
5555
$text
5656
);

Resources/config/shortcodes.xml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,21 +21,21 @@
2121
<argument type="service" id="fragment.handler"/>
2222
<argument><!-- Controller name placeholder argument --></argument>
2323
<argument>esi</argument>
24-
<argument type="service" id="logger" on-invalid="null" />
2524
<argument type="service" id="request_stack" />
25+
<argument type="service" id="logger" on-invalid="null" />
2626
</service>
2727

2828
<!-- Base definition for the EmbedForShortcodeHandler with inline renderer. -->
2929
<service abstract="true" id="webfactory.shortcode.embed_inline_for_shortcode_handler" class="Webfactory\ShortcodeBundle\Handler\EmbeddedShortcodeHandler" lazy="true">
3030
<argument type="service" id="fragment.handler"/>
3131
<argument><!-- Controller name placeholder argument --></argument>
3232
<argument>inline</argument>
33-
<argument type="service" id="logger" on-invalid="null" />
3433
<argument type="service" id="request_stack" />
34+
<argument type="service" id="logger" on-invalid="null" />
3535
</service>
3636

3737
<!-- Twig extension providing the |shortcodes filter. The content will be passed to the ShortcodeFacade. -->
38-
<service class="Webfactory\ShortcodeBundle\Twig\ShortcodeExtension">
38+
<service id="Webfactory\ShortcodeBundle\Twig\ShortcodeExtension" class="Webfactory\ShortcodeBundle\Twig\ShortcodeExtension">
3939
<argument type="service" id="webfactory.shortcode.facade"/>
4040
<tag name="twig.extension"/>
4141
</service>

Tests/DependencyInjection/Compiler/ShortcodeCompilerPassTest.php

Lines changed: 18 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,13 @@
22

33
namespace Webfactory\ShortcodeBundle\Tests\DependencyInjection\Compiler;
44

5+
use PHPUnit\Framework\TestCase;
56
use Symfony\Component\DependencyInjection\ContainerBuilder;
67
use Symfony\Component\DependencyInjection\Definition;
78
use Symfony\Component\DependencyInjection\Reference;
89
use Webfactory\ShortcodeBundle\DependencyInjection\Compiler\ShortcodeCompilerPass;
910

10-
final class ShortcodeCompilerPassTest extends \PHPUnit_Framework_TestCase
11+
final class ShortcodeCompilerPassTest extends TestCase
1112
{
1213
/**
1314
* System under test.
@@ -34,24 +35,24 @@ public function tagged_services_are_added_as_handlers_to_facade()
3435
->method('findTaggedServiceIds')
3536
->willReturn([
3637
'service_id1' => [
37-
['shortcode' => 'shortcode1']
38+
['shortcode' => 'shortcode1'],
3839
],
3940
'service_id2' => [
40-
['shortcode' => 'shortcode2']
41-
]
41+
['shortcode' => 'shortcode2'],
42+
],
4243
]);
4344

44-
$mockedShortcodeFacade = $this->getMock(Definition::class);
45+
$mockedShortcodeFacade = $this->createMock(Definition::class);
4546
$mockedShortcodeFacade->expects($this->at(0))
4647
->method('addMethodCall')
4748
->with('addHandler', $this->callback(function (array $argument) {
48-
return $argument[0] === 'shortcode1'
49+
return 'shortcode1' === $argument[0]
4950
&& $argument[1] instanceof Reference;
5051
}));
5152
$mockedShortcodeFacade->expects($this->at(1))
5253
->method('addMethodCall')
5354
->with('addHandler', $this->callback(function ($argument) {
54-
return $argument[0] === 'shortcode2'
55+
return 'shortcode2' === $argument[0]
5556
&& $argument[1] instanceof Reference;
5657
}));
5758

@@ -70,9 +71,9 @@ public function no_tagged_services_do_no_harm()
7071
->method('findTaggedServiceIds')
7172
->willReturn([]);
7273

73-
$this->setExpectedException(null);
74-
7574
$this->compilerPass->process($this->containerBuilder);
75+
76+
$this->assertTrue(true);
7677
}
7778

7879
/** @test */
@@ -82,31 +83,31 @@ public function shortcode_guide_service_gets_configured_if_set()
8283
->method('findTaggedServiceIds')
8384
->willReturn([
8485
'service_id1' => [
85-
['shortcode' => 'shortcode1']
86+
['shortcode' => 'shortcode1'],
8687
],
8788
'service_id2' => [
88-
['shortcode' => 'shortcode2']
89-
]
89+
['shortcode' => 'shortcode2'],
90+
],
9091
]);
9192

9293
$this->containerBuilder->expects($this->once())
9394
->method('findDefinition')
9495
->with('webfactory.shortcode.facade')
95-
->willReturn($this->getMock(Definition::class));
96+
->willReturn($this->createMock(Definition::class));
9697

9798
$this->containerBuilder->expects($this->once())
9899
->method('has')
99100
->with('webfactory.shortcode.guide.controller')
100101
->willReturn(true);
101102

102-
$mockedShortcodeGuideServiceDefinition = $this->getMock(Definition::class);
103+
$mockedShortcodeGuideServiceDefinition = $this->createMock(Definition::class);
103104
$mockedShortcodeGuideServiceDefinition->expects($this->once())
104105
->method('setArgument')
105106
->with(
106107
0,
107108
[
108109
['shortcode' => 'shortcode1'],
109-
['shortcode' => 'shortcode2']
110+
['shortcode' => 'shortcode2'],
110111
]
111112
);
112113

@@ -130,8 +131,8 @@ public function missing_shortcode_guide_service_does_no_harm()
130131
->with('webfactory.shortcode.guide.controller')
131132
->willReturn(false);
132133

133-
$this->setExpectedException(null);
134-
135134
$this->compilerPass->process($this->containerBuilder);
135+
136+
$this->assertTrue(true);
136137
}
137138
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<?php
2+
3+
namespace Webfactory\ShortcodeBundle\Tests\Fixtures;
4+
5+
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
6+
use Symfony\Component\DependencyInjection\ContainerBuilder;
7+
8+
/**
9+
* Make fragement.handler public so it can be mocked in tests.
10+
*/
11+
class PublicFragmentHandlerClass implements CompilerPassInterface
12+
{
13+
public function process(ContainerBuilder $container)
14+
{
15+
$container->getDefinition('fragment.handler')->setPublic(true);
16+
}
17+
}

0 commit comments

Comments
 (0)