Skip to content

Commit badb985

Browse files
committed
Merge pull request #14 from rjkip/maintenance/symfony-3-php-7-support
Test support for Symfony LTSes and 3.0, PHP 5 through 7
2 parents 00d9bcc + 31589ad commit badb985

File tree

7 files changed

+160
-30
lines changed

7 files changed

+160
-30
lines changed

.travis.yml

+43
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
sudo: false
2+
language: php
3+
4+
php:
5+
- 5.4
6+
- 5.5
7+
- nightly
8+
- hhvm
9+
10+
cache:
11+
directories:
12+
- ~/.composer/cache
13+
14+
before_script:
15+
- composer self-update
16+
- if [ "$SYMFONY_VERSION" != "" ]; then composer require --no-update symfony/config:${SYMFONY_VERSION} symfony/dependency-injection:${SYMFONY_VERSION} symfony/event-dispatcher:${SYMFONY_VERSION} symfony/http-kernel:${SYMFONY_VERSION} symfony/framework-bundle:${SYMFONY_VERSION}; fi;
17+
- if [ "$SYMFONY_EVENT_DISPATCHER_VERSION" != "" ]; then composer require --no-update symfony/event-dispatcher:${SYMFONY_EVENT_DISPATCHER_VERSION}; fi;
18+
- composer install --no-interaction --prefer-source --dev
19+
20+
script: phpunit --verbose
21+
22+
matrix:
23+
include:
24+
- php: 5.6
25+
env: [SYMFONY_VERSION="2.3.*", SYMFONY_EVENT_DISPATCHER_VERSION="2.4.*"]
26+
- php: 5.6
27+
env: [SYMFONY_VERSION="2.7.*"]
28+
- php: 5.6
29+
env: [SYMFONY_VERSION="2.8.*"]
30+
- php: 5.6
31+
env: [SYMFONY_VERSION="3.0.*"]
32+
- php: 7.0
33+
env: [SYMFONY_VERSION="2.3.*", SYMFONY_EVENT_DISPATCHER_VERSION="2.4.*"]
34+
- php: 7.0
35+
env: [SYMFONY_VERSION="2.7.*"]
36+
- php: 7.0
37+
env: [SYMFONY_VERSION="2.8.*"]
38+
- php: 7.0
39+
env: [SYMFONY_VERSION="3.0.*"]
40+
allow_failures:
41+
- php: nightly
42+
- php: hhvm
43+
fast_finish: true
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
<?php
2+
3+
namespace Tmdb\SymfonyBundle\Tests\DependencyInjection;
4+
5+
use PHPUnit_Framework_TestCase as TestCase;
6+
use Symfony\Component\DependencyInjection\Container;
7+
use Tmdb\SymfonyBundle\Tests\TestKernel;
8+
9+
final class TmdbSymfonyExtensionTest extends TestCase
10+
{
11+
/**
12+
* @test
13+
* @group DependencyInjection
14+
*/
15+
public function all_tmdb_services_can_be_loaded()
16+
{
17+
$kernel = new TestKernel('test', true);
18+
$kernel->boot();
19+
20+
/** @var Container $container */
21+
$container = $kernel->getContainer();
22+
$tmdbServiceIds = array_filter($container->getServiceIds(), function ($id) {
23+
return strpos($id, 'tmdb') === 0;
24+
});
25+
26+
foreach ($tmdbServiceIds as $serviceId) {
27+
$container->get($serviceId);
28+
}
29+
}
30+
}

Tests/TestKernel.php

+39
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
<?php
2+
3+
namespace Tmdb\SymfonyBundle\Tests;
4+
5+
use Symfony\Bundle\FrameworkBundle\FrameworkBundle;
6+
use Symfony\Component\Config\Loader\LoaderInterface;
7+
use Symfony\Component\HttpKernel\Kernel;
8+
use Tmdb\SymfonyBundle\TmdbSymfonyBundle;
9+
10+
final class TestKernel extends Kernel
11+
{
12+
public function registerBundles()
13+
{
14+
return [
15+
new FrameworkBundle(),
16+
new TmdbSymfonyBundle()
17+
];
18+
}
19+
20+
public function registerContainerConfiguration(LoaderInterface $loader)
21+
{
22+
$loader->load(__DIR__ . '/config.yml');
23+
}
24+
25+
public function getRootDir()
26+
{
27+
return sys_get_temp_dir() . '/php-tmdb-symfony-test';
28+
}
29+
30+
public function getCacheDir()
31+
{
32+
return $this->getRootDir() . '/cache';
33+
}
34+
35+
public function getLogDir()
36+
{
37+
return $this->getRootDir() . '/logs';
38+
}
39+
}

Tests/config.yml

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
framework:
2+
secret: NopeChuckTesta
3+
tmdb_symfony:
4+
api_key: invalidapikey

Twig/TmdbExtension.php

+17-28
Original file line numberDiff line numberDiff line change
@@ -8,20 +8,19 @@
88

99
class TmdbExtension extends \Twig_Extension
1010
{
11+
/**
12+
* @var ImageHelper|null
13+
*/
1114
private $helper;
1215

16+
/**
17+
* @var Client
18+
*/
1319
private $client;
1420

15-
private $configuration;
16-
1721
public function __construct(Client $client)
1822
{
1923
$this->client = $client;
20-
21-
$repository = new ConfigurationRepository($client);
22-
$config = $repository->load();
23-
24-
$this->helper = new ImageHelper($config);
2524
}
2625

2726
public function getFilters()
@@ -34,12 +33,12 @@ public function getFilters()
3433

3534
public function getHtml($image, $size = 'original', $width = null, $height = null)
3635
{
37-
return $this->helper->getHtml($image, $size, $width, $height);
36+
return $this->getHelper()->getHtml($image, $size, $width, $height);
3837
}
3938

4039
public function getUrl($image)
4140
{
42-
return $this->helper->getUrl($image);
41+
return $this->getHelper()->getUrl($image);
4342
}
4443

4544
public function getName()
@@ -66,25 +65,6 @@ public function getClient()
6665
return $this->client;
6766
}
6867

69-
/**
70-
* @param mixed $configuration
71-
* @return $this
72-
*/
73-
public function setConfiguration($configuration)
74-
{
75-
$this->configuration = $configuration;
76-
77-
return $this;
78-
}
79-
80-
/**
81-
* @return mixed
82-
*/
83-
public function getConfiguration()
84-
{
85-
return $this->configuration;
86-
}
87-
8868
/**
8969
* @param ImageHelper $helper
9070
* @return $this
@@ -101,6 +81,15 @@ public function setHelper($helper)
10181
*/
10282
public function getHelper()
10383
{
84+
if ($this->helper) {
85+
return $this->helper;
86+
}
87+
88+
$repository = new ConfigurationRepository($this->client);
89+
$config = $repository->load();
90+
91+
$this->helper = new ImageHelper($config);
92+
10493
return $this->helper;
10594
}
10695
}

composer.json

+11-2
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,18 @@
1313
}
1414
],
1515
"require": {
16-
"symfony/symfony": "~2.3",
16+
"php": ">=5.4.0",
17+
"symfony/config": ">=2.3,<4",
18+
"symfony/dependency-injection": ">=2.3,<4",
19+
"symfony/event-dispatcher": ">=2.3,<4",
20+
"symfony/http-kernel": ">=2.3,<4",
1721
"doctrine/doctrine-cache-bundle": "~1.0",
18-
"php-tmdb/api": "~2.0"
22+
"php-tmdb/api": "^2.0.14",
23+
"twig/twig": "~1.11|~2.0"
24+
},
25+
"require-dev": {
26+
"phpunit/phpunit": "^4.8",
27+
"symfony/framework-bundle": ">=2.3,<4"
1928
},
2029
"autoload": {
2130
"psr-4": { "Tmdb\\SymfonyBundle\\": "" }

phpunit.xml.dist

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<phpunit backupGlobals="false"
2+
backupStaticAttributes="false"
3+
colors="true"
4+
convertErrorsToExceptions="true"
5+
convertNoticesToExceptions="true"
6+
convertWarningsToExceptions="true"
7+
processIsolation="false"
8+
stopOnFailure="false"
9+
syntaxCheck="false"
10+
bootstrap="vendor/autoload.php">
11+
<testsuites>
12+
<testsuite name="php-tmdb-symfony Test Suite">
13+
<directory>./Tests/</directory>
14+
</testsuite>
15+
</testsuites>
16+
</phpunit>

0 commit comments

Comments
 (0)