Skip to content

Commit 4301479

Browse files
committed
Merge pull request #8 from patkar/enhancement/forward-compatibility-ftw
Forward compatibility FTW (PHP 7, Symfony 3)
2 parents 05b3fa4 + 0989c72 commit 4301479

13 files changed

Lines changed: 253 additions & 527 deletions

File tree

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
vendor
22
composer.phar
3+
composer.lock
34
.DS_Store

.travis.yml

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
language: php
2+
3+
php:
4+
- 5.3
5+
- 5.4
6+
- 5.5
7+
- 5.6
8+
- 7.0
9+
- hhvm
10+
11+
sudo: false
12+
13+
cache:
14+
directories:
15+
- $HOME/.composer
16+
17+
env:
18+
- SYMFONY_VERSION=2.8.*
19+
20+
matrix:
21+
include:
22+
- php: 5.6
23+
env: SYMFONY_VERSION=2.3.*
24+
- php: 5.6
25+
env: SYMFONY_VERSION=2.7.*
26+
- php: 7.0
27+
env: SYMFONY_VERSION=2.8.*@dev
28+
- php: 7.0
29+
env: SYMFONY_VERSION=^3.0
30+
- php: 7.0
31+
env: SYMFONY_VERSION=^3.0@dev
32+
- php: 5.3
33+
env: COMPOSER_FLAGS="--prefer-lowest"
34+
35+
before_install:
36+
- composer self-update
37+
- if [ "$COMPOSER_FLAGS" == "--prefer-lowest" ]; then composer require "roave/security-advisories" dev-master --no-update; fi;
38+
- if [ "$SYMFONY_VERSION" != "" ]; then composer require "symfony/symfony:${SYMFONY_VERSION}" --no-update; fi;
39+
40+
install: composer update --prefer-source $COMPOSER_FLAGS
41+
42+
script:
43+
- vendor/bin/phpunit

DependencyInjection/DubtureFFmpegExtension.php

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,14 @@ public function load(array $configs, ContainerBuilder $container)
2323
$config = $this->processConfiguration($configuration, $configs);
2424

2525
$loader = new Loader\XmlFileLoader($container, new FileLocator(__DIR__.'/../Resources/config'));
26-
$loader->load('services.xml');
26+
27+
// Depending on the dependency injection version load the corresponding factories
28+
// The new setFactory method was introduced in 2.6 and the old way removed in 3.0
29+
if (method_exists('Symfony\\Component\\DependencyInjection\\Definition', 'setFactory')) {
30+
$loader->load('factories.xml');
31+
} else {
32+
$loader->load('factories-2.3.xml');
33+
}
2734

2835
$container->setParameter('dubture_ffmpeg.binary', $config['ffmpeg_binary']);
2936
$container->setParameter('dubture_ffprobe.binary', $config['ffprobe_binary']);
Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,8 @@
44
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
55
xsi:schemaLocation="http://symfony.com/schema/dic/services http://symfony.com/schema/dic/services/services-1.0.xsd">
66

7-
<parameters>
8-
<parameter key="dubture_ffmpeg.ffmpeg.class">FFMpeg\FFMpeg</parameter>
9-
<parameter key="dubture_ffmpeg.ffprobe.class">FFMpeg\FFProbe</parameter>
10-
</parameters>
11-
127
<services>
13-
<service id="dubture_ffmpeg.ffmpeg" class="%dubture_ffmpeg.ffmpeg.class%" factory-class="%dubture_ffmpeg.ffmpeg.class%" factory-method="create" lazy="true">
8+
<service id="dubture_ffmpeg.ffmpeg" class="FFMpeg\FFMpeg" factory-class="FFMpeg\FFMpeg" factory-method="create" lazy="true">
149
<argument type="collection">
1510
<argument key="ffmpeg.binaries">%dubture_ffmpeg.binary%</argument>
1611
<argument key="ffprobe.binaries">%dubture_ffprobe.binary%</argument>
@@ -20,13 +15,12 @@
2015
<argument id="logger" type="service"/>
2116
</service>
2217

23-
<service id="dubture_ffmpeg.ffprobe" class="%dubture_ffmpeg.ffprobe.class%" factory-class="%dubture_ffmpeg.ffprobe.class%" factory-method="create" lazy="true">
18+
<service id="dubture_ffmpeg.ffprobe" class="FFMpeg\FFProbe" factory-class="FFMpeg\FFProbe" factory-method="create" lazy="true">
2419
<argument type="collection">
2520
<argument key="ffmpeg.binaries">%dubture_ffmpeg.binary%</argument>
2621
<argument key="ffprobe.binaries">%dubture_ffprobe.binary%</argument>
2722
</argument>
2823
<argument id="logger" type="service"/>
2924
</service>
30-
3125
</services>
3226
</container>

Resources/config/factories.xml

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
<?xml version="1.0" ?>
2+
3+
<container xmlns="http://symfony.com/schema/dic/services"
4+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
5+
xsi:schemaLocation="http://symfony.com/schema/dic/services http://symfony.com/schema/dic/services/services-1.0.xsd">
6+
7+
<services>
8+
<service id="dubture_ffmpeg.ffmpeg" class="FFMpeg\FFMpeg" lazy="true">
9+
<factory class="FFMpeg\FFMpeg" method="create"/>
10+
<argument type="collection">
11+
<argument key="ffmpeg.binaries">%dubture_ffmpeg.binary%</argument>
12+
<argument key="ffprobe.binaries">%dubture_ffprobe.binary%</argument>
13+
<argument key="timeout">%dubture_ffmpeg.binary_timeout%</argument>
14+
<argument key="ffmpeg.threads">%dubture_ffmpeg.threads_count%</argument>
15+
</argument>
16+
<argument id="logger" type="service"/>
17+
</service>
18+
19+
<service id="dubture_ffmpeg.ffprobe" class="FFMpeg\FFProbe" lazy="true">
20+
<factory class="FFMpeg\FFProbe" method="create"/>
21+
<argument type="collection">
22+
<argument key="ffmpeg.binaries">%dubture_ffmpeg.binary%</argument>
23+
<argument key="ffprobe.binaries">%dubture_ffprobe.binary%</argument>
24+
</argument>
25+
<argument id="logger" type="service"/>
26+
</service>
27+
</services>
28+
</container>

Tests/Fixtures/all.yml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
dubture_f_fmpeg:
2+
ffmpeg_binary: /usr/local/bin/ffmpeg
3+
ffprobe_binary: /usr/local/bin/ffprobe
4+
binary_timeout: 300
5+
threads_count: 2

Tests/Fixtures/minimum.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
dubture_f_fmpeg:
2+
ffmpeg_binary: /usr/local/bin/ffmpeg
3+
ffprobe_binary: /usr/local/bin/ffprobe
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
<?php
2+
3+
namespace Dubture\FFmpegBundle\Tests\Unit\DependencyInjection;
4+
5+
use Dubture\FFmpegBundle\DependencyInjection\Configuration;
6+
use Dubture\FFmpegBundle\DependencyInjection\DubtureFFmpegExtension;
7+
use Matthias\SymfonyDependencyInjectionTest\PhpUnit\AbstractExtensionConfigurationTestCase;
8+
9+
/**
10+
* Test the configuration parsed from YAML.
11+
*
12+
* @author Patrik Karisch <patrik@karisch.guru>
13+
*/
14+
class ConfigurationTest extends AbstractExtensionConfigurationTestCase
15+
{
16+
/**
17+
* {@inheritDoc}
18+
*/
19+
protected function getContainerExtension()
20+
{
21+
return new DubtureFFmpegExtension();
22+
}
23+
24+
/**
25+
* {@inheritDoc}
26+
*/
27+
protected function getConfiguration()
28+
{
29+
return new Configuration();
30+
}
31+
32+
public function testProcessedMinimumConfigurationContainsAllValues()
33+
{
34+
$expectedConfiguration = array(
35+
'ffmpeg_binary' => '/usr/local/bin/ffmpeg',
36+
'ffprobe_binary' => '/usr/local/bin/ffprobe',
37+
'binary_timeout' => 60,
38+
'threads_count' => 4,
39+
);
40+
41+
$sources = array(
42+
__DIR__.'/../../Fixtures/minimum.yml',
43+
);
44+
45+
$this->assertProcessedConfigurationEquals(
46+
$expectedConfiguration,
47+
$sources
48+
);
49+
}
50+
51+
public function testProcessedAllConfigurationContainsAllValues()
52+
{
53+
$expectedConfiguration = array(
54+
'ffmpeg_binary' => '/usr/local/bin/ffmpeg',
55+
'ffprobe_binary' => '/usr/local/bin/ffprobe',
56+
'binary_timeout' => 300,
57+
'threads_count' => 2,
58+
);
59+
60+
$sources = array(
61+
__DIR__.'/../../Fixtures/all.yml',
62+
);
63+
64+
$this->assertProcessedConfigurationEquals($expectedConfiguration, $sources);
65+
}
66+
}
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
<?php
2+
3+
namespace Dubture\FFmpegBundle\Tests\Unit\DependencyInjection;
4+
5+
use Dubture\FFmpegBundle\DependencyInjection\DubtureFFmpegExtension;
6+
use Matthias\SymfonyDependencyInjectionTest\PhpUnit\AbstractExtensionTestCase;
7+
8+
/**
9+
* Test the extensions which adds parameters and services
10+
* to the container.
11+
*
12+
* @author Patrik Karisch <patrik@karisch.guru>
13+
*/
14+
class DubtureFFmpegExtensionTest extends AbstractExtensionTestCase
15+
{
16+
/**
17+
* {@inheritDoc}
18+
*/
19+
protected function getContainerExtensions()
20+
{
21+
return array(
22+
new DubtureFFmpegExtension(),
23+
);
24+
}
25+
26+
/**
27+
* {@inheritDoc}
28+
*/
29+
protected function setUp()
30+
{
31+
parent::setUp();
32+
33+
$this->load(array(
34+
'ffmpeg_binary' => '/usr/local/bin/ffmpeg',
35+
'ffprobe_binary' => '/usr/local/bin/ffprobe',
36+
));
37+
}
38+
39+
public function testAfterLoadingTheCorrectParametersHaveBeenSet()
40+
{
41+
$this->assertContainerBuilderHasParameter('dubture_ffmpeg.binary', '/usr/local/bin/ffmpeg');
42+
$this->assertContainerBuilderHasParameter('dubture_ffprobe.binary', '/usr/local/bin/ffprobe');
43+
$this->assertContainerBuilderHasParameter('dubture_ffmpeg.binary_timeout', 60);
44+
$this->assertContainerBuilderHasParameter('dubture_ffmpeg.threads_count', 4);
45+
}
46+
47+
public function testAfterLoadingTheFFMpegServiceExists()
48+
{
49+
$this->assertContainerBuilderHasService('dubture_ffmpeg.ffmpeg', 'FFMpeg\FFMpeg');
50+
}
51+
52+
public function testAfterLoadingTheFFProbeServiceExists()
53+
{
54+
$this->assertContainerBuilderHasService('dubture_ffmpeg.ffprobe', 'FFMpeg\FFProbe');
55+
}
56+
}

Tests/bootstrap.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<?php
2+
3+
$file = __DIR__ . '/../vendor/autoload.php';
4+
if (!file_exists($file)) {
5+
throw new RuntimeException('Install dependencies to run test suite.');
6+
}
7+
8+
$autoload = require_once $file;

0 commit comments

Comments
 (0)