Skip to content

Commit abba4ba

Browse files
authored
Merge branch 'master' into 5.3
2 parents e60a2fe + da5ea9a commit abba4ba

File tree

8 files changed

+261
-35
lines changed

8 files changed

+261
-35
lines changed

.travis.yml

Lines changed: 138 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -9,38 +9,154 @@ cache:
99
matrix:
1010
fast_finish: true
1111
include:
12-
- php: 5.4
12+
- php: 7.0
1313
env:
14-
- SYMFONY_VERSION="2.3"
15-
- PHPUNIT=phpunit-4.8
14+
- SYMFONY_VERSION="2.3.*"
15+
- PHPUNIT=phpunit-5.7
1616
- TEST_LINT=`true`
17-
- php: 5.4
17+
- PHP_CS_FIXER=`true`
18+
- SENSIO_SECURITY=`true`
19+
- php: 7.0
1820
env:
19-
- SYMFONY_VERSION="2.7"
20-
- PHPUNIT=phpunit-4.8
21+
- SYMFONY_VERSION="2.7.*"
22+
- PHPUNIT=phpunit-5.7
2123
- TEST_LINT=`true`
22-
- php: 5.4
24+
- PHP_CS_FIXER=`true`
25+
- SENSIO_SECURITY=`true`
26+
- php: 7.0
2327
env:
2428
- SYMFONY_LTS="2"
2529
- PHPUNIT=phpunit-4.8
2630
- TEST_LINT=`true`
31+
- PHP_CS_FIXER=`true`
32+
- SENSIO_SECURITY=`true`
33+
- php: 7.0
34+
env:
35+
- SYMFONY_LTS="3"
36+
- PHPUNIT=phpunit-5.7
37+
- TEST_LINT=`true`
38+
- PHP_CS_FIXER=`true`
39+
- SENSIO_SECURITY=`true`
40+
- php: 7.1
41+
env:
42+
- SYMFONY_VERSION="2.3.*"
43+
- PHPUNIT=phpunit-5.7
44+
- TEST_LINT=`true`
45+
- PHP_CS_FIXER=`true`
46+
- SENSIO_SECURITY=`true`
47+
- php: 7.1
48+
env:
49+
- SYMFONY_VERSION="2.7.*"
50+
- PHPUNIT=phpunit-5.7
51+
- TEST_LINT=`true`
52+
- PHP_CS_FIXER=`true`
53+
- SENSIO_SECURITY=`true`
54+
- php: 7.1
55+
env:
56+
- SYMFONY_LTS="2"
57+
- PHPUNIT=phpunit-5.7
58+
- TEST_LINT=`true`
59+
- PHP_CS_FIXER=`true`
60+
- SENSIO_SECURITY=`true`
61+
- php: 7.1
62+
env:
63+
- SYMFONY_LTS="3"
64+
- PHPUNIT=phpunit-5.7
65+
- TEST_LINT=`true`
66+
- PHP_CS_FIXER=`true`
67+
- SENSIO_SECURITY=`true`
68+
- php: 7.1
69+
env:
70+
- SYMFONY_LTS="4.x-dev@dev"
71+
- PHPUNIT=phpunit-5.7
72+
- TEST_LINT=`true`
73+
- PHP_CS_FIXER=`true`
74+
- SENSIO_SECURITY=`true`
75+
- php: 7.2
76+
env:
77+
- SYMFONY_VERSION="2.3.*"
78+
- PHPUNIT=phpunit-5.7
79+
- TEST_LINT=`true`
80+
- PHP_CS_FIXER=`true`
81+
- SENSIO_SECURITY=`true`
82+
- php: 7.2
83+
env:
84+
- SYMFONY_VERSION="2.7.*"
85+
- PHPUNIT=phpunit-5.7
86+
- TEST_LINT=`true`
87+
- PHP_CS_FIXER=`true`
88+
- SENSIO_SECURITY=`true`
89+
- php: 7.2
90+
env:
91+
- SYMFONY_LTS="2"
92+
- PHPUNIT=phpunit-5.7
93+
- TEST_LINT=`true`
94+
- PHP_CS_FIXER=`true`
95+
- SENSIO_SECURITY=`true`
96+
- php: 7.2
97+
env:
98+
- SYMFONY_LTS="3"
99+
- PHPUNIT=phpunit-5.7
100+
- TEST_LINT=`true`
101+
- PHP_CS_FIXER=`true`
102+
- SENSIO_SECURITY=`true`
103+
- php: 7.2
104+
env:
105+
- SYMFONY_LTS="4.x-dev@dev"
106+
- PHPUNIT=phpunit-5.7
107+
- TEST_LINT=`true`
108+
- PHP_CS_FIXER=`true`
109+
- SENSIO_SECURITY=`true`
110+
- php: nightly
111+
env:
112+
- SYMFONY_VERSION="2.3.*"
113+
- PHPUNIT=phpunit-5.7
114+
- TEST_LINT=`true`
115+
- SENSIO_SECURITY=`true`
116+
- php: nightly
117+
env:
118+
- SYMFONY_VERSION="2.7.*"
119+
- PHPUNIT=phpunit-5.7
120+
- TEST_LINT=`true`
121+
- SENSIO_SECURITY=`true`
122+
- php: nightly
123+
env:
124+
- SYMFONY_LTS="2"
125+
- PHPUNIT=phpunit-5.7
126+
- TEST_LINT=`true`
127+
- SENSIO_SECURITY=`true`
128+
- php: nightly
129+
env:
130+
- SYMFONY_LTS="3"
131+
- PHPUNIT=phpunit-5.7
132+
- TEST_LINT=`true`
133+
- SENSIO_SECURITY=`true`
134+
- php: nightly
135+
env:
136+
- SYMFONY_LTS="4.x-dev@dev"
137+
- PHPUNIT=phpunit-5.7
138+
- TEST_LINT=`true`
139+
- SENSIO_SECURITY=`true`
140+
allow_failures:
141+
- php: nightly
27142

28143
before_install:
29-
- echo $PHPUNIT
30-
- pwd
31-
- echo $HOME
32-
- echo $TRAVIS_PHP_VERSION
33-
- which composer
34-
- ls /tmp
35-
- php --ini
36-
- xdebug=/home/travis/.phpenv/versions/$TRAVIS_PHP_VERSION/etc/conf.d/xdebug.ini
37-
- if [[ -f $xdebug ]]; then cat $xdebug; cp $xdebug /tmp; phpenv config-rm xdebug.ini; fi
38-
- xdebug_php=
39-
- if [[ -f /tmp/xdebug.ini ]]; then xdebug_php='-c /tmp/xdebug.ini'; fi
40-
- install --directory .travis/bin
41-
- if [[ -v PHP_CS_FIXER ]]; then wget http://cs.sensiolabs.org/download/php-cs-fixer-v2.phar --output-document=.travis/bin/php-cs-fixer; fi
42-
- if [[ -v PHPUNIT ]]; then wget https://phar.phpunit.de/${PHPUNIT}.phar --output-document=.travis/bin/$PHPUNIT; fi
43-
- if [[ -v SENSIO_SECURITY ]]; then wget http://get.sensiolabs.org/security-checker.phar --output-document=.travis/bin/security-checker; fi
144+
- source /etc/os-release ; echo $VERSION
145+
- echo $PHPUNIT
146+
- pwd
147+
- echo $HOME
148+
- echo $TRAVIS_PHP_VERSION
149+
- which composer
150+
- ls /tmp
151+
- php --ini
152+
- xdebug=/home/travis/.phpenv/versions/$TRAVIS_PHP_VERSION/etc/conf.d/xdebug.ini
153+
- if [[ -f $xdebug ]]; then cat $xdebug; cp $xdebug /tmp; phpenv config-rm xdebug.ini; fi
154+
- xdebug_php=
155+
- if [[ -f /tmp/xdebug.ini ]]; then xdebug_php='-c /tmp/xdebug.ini'; fi
156+
- install --directory .travis/bin
157+
- if [[ -v PHP_CS_FIXER ]]; then wget http://cs.sensiolabs.org/download/php-cs-fixer-v2.phar --output-document=.travis/bin/php-cs-fixer; fi
158+
- if [[ -v PHPUNIT ]]; then wget https://phar.phpunit.de/${PHPUNIT}.phar --output-document=.travis/bin/$PHPUNIT; fi
159+
- if [[ -v SENSIO_SECURITY ]]; then wget http://get.sensiolabs.org/security-checker.phar --output-document=.travis/bin/security-checker; fi
44160

45161
install:
46162
- composer validate

README.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,3 +64,12 @@ Icon: https://material.io/icons/#ic_wallpaper
6464
##### _string_ arguments
6565
* string arguments can officially be type-hinted from php 7.0
6666
* http://php.net/manual/en/functions.arguments.php
67+
68+
### Versions
69+
#### PHP
70+
##### 5.5 TemplatingController::class in unit tests
71+
##### 5.6 __invoke(...$arguments) in VariadicController.php
72+
##### 7.0 (master)
73+
* declare(strict_types=1);
74+
* function f(): float
75+
* function s(string $s)

TemplatingController.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
<?php
2+
declare(strict_types=1);
23

34
/*
45
* This file is part of the Symfony-Util package.
@@ -20,13 +21,13 @@ class TemplatingController
2021
protected $templating;
2122
protected $template;
2223

23-
public function __construct(EngineInterface $templating, $template = self::TEMPLATE)
24+
public function __construct(EngineInterface $templating, string $template = self::TEMPLATE)
2425
{
2526
$this->templating = $templating;
2627
$this->template = $template;
2728
}
2829

29-
public function __invoke()
30+
public function __invoke(): Response
3031
{
3132
return new Response($this->templating->render($this->template));
3233
}

VariadicController.php

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Symfony-Util package.
5+
*
6+
* (c) Jean-Bernard Addor
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
namespace SymfonyUtil\Controller;
13+
14+
use Symfony\Component\HttpFoundation\Response;
15+
use Symfony\Component\Templating\EngineInterface;
16+
17+
class VariadicController
18+
{
19+
const TEMPLATE = 'index.html.twig';
20+
protected $templating;
21+
protected $template;
22+
23+
public function __construct(EngineInterface $templating, $template = 'index.html.twig')
24+
{
25+
$this->templating = $templating;
26+
$this->template = $template;
27+
}
28+
29+
public function __invoke(...$arguments) // PHP 5.6+
30+
{
31+
// Variadic $arguments apparently not supported when empty by Symfony 3.3.6 ArgumentResolver
32+
// and viewed as a regular array by knplabs/rad-resource-resolver v2.1
33+
34+
return new Response($this->templating->render($this->template, $arguments));
35+
}
36+
}

composer.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
{"name": "Community", "homepage": "https://github.com/symfony-util/controller-using-templating-http-foundation"}
1010
],
1111
"require": {
12+
"php": "^7.0",
1213
"symfony/http-foundation": "^2.0 || ^3.0 || ^4.0",
1314
"symfony/templating": "^2.0 || ^3.0 || ^4.0"
1415
},
@@ -25,7 +26,7 @@
2526
},
2627
"extra": {
2728
"branch-alias": {
28-
"dev-master": "5.3.x-dev"
29+
"dev-master": "7.0.x-dev"
2930
}
3031
}
3132
}

tests/EngineAsArgumentControllerTest.php

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,17 +23,15 @@ final class EngineAsArgumentControllerTest extends TestCase
2323
public function testCanBeCreated()
2424
{
2525
$this->assertInstanceOf(
26-
// EngineAsArgumentController::class, // 5.4 < php
27-
'SymfonyUtil\Controller\EngineAsArgumentController',
26+
EngineAsArgumentController::class, // 5.4 < php
2827
new EngineAsArgumentController()
2928
);
3029
}
3130

3231
public function testReturnsResponse()
3332
{
3433
$this->assertInstanceOf(
35-
// Response::class, // 5.4 < php
36-
'Symfony\Component\HttpFoundation\Response',
34+
Response::class, // 5.4 < php
3735
(new EngineAsArgumentController())->__invoke(new TwigEngine(
3836
new Twig_Environment(new Twig_Loader_Array(['index.html.twig' => 'Hello World!'])),
3937
new TemplateNameParser()

tests/TemplatingControllerTest.php

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,7 @@ public function testCanBeCreated()
4040
public function testHomeCanBeCreated()
4141
{
4242
$this->assertInstanceOf(
43-
// ::class, // 5.4 < php
44-
'SymfonyUtil\Controller\TemplatingController',
43+
TemplatingController::class, // 5.4 < php
4544
new HomeTemplatingController(new TwigEngine(
4645
new Twig_Environment(new Twig_Loader_Array(['home.html.twig' => 'Hello World!'])),
4746
new TemplateNameParser()
@@ -52,8 +51,7 @@ public function testHomeCanBeCreated()
5251
public function testEmptyReturnsResponse()
5352
{
5453
$this->assertInstanceOf(
55-
// Response::class, // 5.4 < php
56-
'Symfony\Component\HttpFoundation\Response',
54+
Response::class, // 5.4 < php
5755
(new TemplatingController(new TwigEngine(
5856
new Twig_Environment(new Twig_Loader_Array(['index.html.twig' => 'Hello World!'])),
5957
new TemplateNameParser()
@@ -64,8 +62,7 @@ public function testEmptyReturnsResponse()
6462
public function testArrayReturnsResponse()
6563
{
6664
$this->assertInstanceOf(
67-
// Response::class, // 5.4 < php
68-
'Symfony\Component\HttpFoundation\Response',
65+
Response::class, // 5.4 < php
6966
(new TemplatingController(new TwigEngine(
7067
new Twig_Environment(new Twig_Loader_Array([
7168
'index.html.twig' => '<ul>{% for item in 0 %}<li>{{ item }}</li>{% endfor %}</ul>',

tests/VariadicControllerTest.php

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Symfony-Util package.
5+
*
6+
* (c) Jean-Bernard Addor
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
use PHPUnit\Framework\TestCase;
13+
use Symfony\Bridge\Twig\TwigEngine;
14+
use Symfony\Component\HttpFoundation\Response;
15+
use Symfony\Component\Templating\TemplateNameParser;
16+
use SymfonyUtil\Controller\VariadicController;
17+
18+
/**
19+
* @covers \SymfonyUtil\Controller\VariadicController
20+
* @requires PHP 5.6.0
21+
*/
22+
final class VariadicControllerTest extends TestCase
23+
{
24+
public function testCanBeCreated()
25+
{
26+
$this->assertInstanceOf(
27+
// VariadicController::class, // 5.4 < php (code is checked even if not executed!)
28+
'SymfonyUtil\Controller\VariadicController',
29+
new VariadicController(new TwigEngine(
30+
new Twig_Environment(new Twig_Loader_Array(['index.html.twig' => 'Hello World!'])),
31+
new TemplateNameParser()
32+
))
33+
);
34+
}
35+
36+
public function testEmptyReturnsResponse()
37+
{
38+
$this->assertInstanceOf(
39+
// Response::class, // 5.4 < php (code is checked even if not executed!)
40+
'Symfony\Component\HttpFoundation\Response',
41+
(new VariadicController(new TwigEngine(
42+
new Twig_Environment(new Twig_Loader_Array(['index.html.twig' => 'Hello World!'])),
43+
new TemplateNameParser()
44+
)))->__invoke()
45+
);
46+
}
47+
48+
public function testArrayReturnsResponse()
49+
{
50+
$this->assertInstanceOf(
51+
// Response::class, // 5.4 < php (code is checked even if not executed!)
52+
'Symfony\Component\HttpFoundation\Response',
53+
(new VariadicController(new TwigEngine(
54+
new Twig_Environment(new Twig_Loader_Array([
55+
'index.html.twig' => '<ul>{% for item in 0 %}<li>{{ item }}</li>{% endfor %}</ul>',
56+
])),
57+
new TemplateNameParser()
58+
)))->__invoke([
59+
'One',
60+
'Two',
61+
'Three',
62+
])
63+
);
64+
}
65+
}
66+
67+
// http://api.symfony.com/3.3/Symfony/Bridge/Twig/TwigEngine.html
68+
// http://api.symfony.com/3.3/Symfony/Bundle/TwigBundle/TwigEngine.html

0 commit comments

Comments
 (0)