Skip to content

Commit 7290f02

Browse files
authored
Added functional tests to make sure the bundle work on different sf versions (#40)
* Added functional tests to make sure the bundle work on different symfony versions * Applied fixes from StyleCI (#41) * Updated comment * Do not run travis on Style CI branches
1 parent cfe2514 commit 7290f02

14 files changed

+157
-17
lines changed

.travis.yml

+4
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,10 @@ env:
1717
- SYMFONY_VERSION=2.8.*
1818
- SYMFONY_VERSION=3.0.*
1919

20+
branches:
21+
except:
22+
- /^analysis-.*$/
23+
2024
matrix:
2125
fast_finish: true
2226
include:

composer.json

+7-6
Original file line numberDiff line numberDiff line change
@@ -18,14 +18,15 @@
1818
}
1919
],
2020
"require": {
21-
"php": "^5.5|^7",
22-
"symfony/framework-bundle": "^2.7|^3.0",
23-
"symfony/options-resolver": "^2.7|^3.0",
24-
"psr/cache": "1.0.0"
21+
"php": "^5.5 || ^7.0",
22+
"symfony/framework-bundle": "^2.7 || ^3.0",
23+
"symfony/options-resolver": "^2.7 || ^3.0",
24+
"psr/cache": "^1.0"
2525
},
2626
"require-dev": {
27-
"phpunit/phpunit": "5.0.*|^4.0",
28-
"matthiasnoback/symfony-dependency-injection-test": "0.7.*",
27+
"phpunit/phpunit": "5.0.* || ^4.0",
28+
"symfony/symfony": "^2.7 || ^3.0",
29+
"matthiasnoback/symfony-dependency-injection-test": "^1.0",
2930
"cache/array-adapter": "@stable"
3031
},
3132
"suggest": {

phpunit.xml.dist

+1-5
Original file line numberDiff line numberDiff line change
@@ -12,15 +12,11 @@
1212
bootstrap="vendor/autoload.php"
1313
>
1414
<testsuites>
15-
<testsuite name="CacheBundle for the Symfony2 Framework">
15+
<testsuite name="Main testsuite for AdapterBundle">
1616
<directory>./tests/</directory>
1717
</testsuite>
1818
</testsuites>
1919

20-
<logging>
21-
<log type="coverage-text" target="php://stdout"/>
22-
</logging>
23-
2420
<groups>
2521
<exclude>
2622
<group>benchmark</group>

src/DSN.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -229,7 +229,7 @@ private function parseHosts($hostString)
229229

230230
$hosts = [];
231231
foreach ($matches['host'] as $index => $match) {
232-
$port = !empty($matches['port'][$index])
232+
$port = !empty($matches['port'][$index])
233233
? (int) $matches['port'][$index]
234234
: self::$PORTS[$this->protocol];
235235
$hosts[] = ['host' => $match, 'port' => $port];

src/Factory/DoctrineRedisFactory.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ class DoctrineRedisFactory extends AbstractDoctrineAdapterFactory
2525
*/
2626
public function getAdapter(array $config)
2727
{
28-
$redis = new \Redis();
28+
$redis = new \Redis();
2929
$redis->connect($config['host'], $config['port']);
3030

3131
$client = new RedisCache();

src/Factory/MemcacheFactory.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,8 @@ public function getAdapter(array $config)
4141
protected static function configureOptionResolver(OptionsResolver $resolver)
4242
{
4343
$resolver->setDefaults([
44-
'host' => '127.0.0.1',
45-
'port' => 11211,
44+
'host' => '127.0.0.1',
45+
'port' => 11211,
4646
]);
4747

4848
$resolver->setAllowedTypes('host', ['string']);

tests/Functional/BaseTestCase.php

+33
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
<?php
2+
3+
/*
4+
* This file is part of php-cache organization.
5+
*
6+
* (c) 2015-2015 Aaron Scherer <[email protected]>, Tobias Nyholm <[email protected]>
7+
*
8+
* This source file is subject to the MIT license that is bundled
9+
* with this source code in the file LICENSE.
10+
*/
11+
12+
namespace Cache\AdapterBundle\Tests\Functional;
13+
14+
use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;
15+
16+
class BaseTestCase extends WebTestCase
17+
{
18+
protected static function getKernelClass()
19+
{
20+
require_once __DIR__.'/app/AppKernel.php';
21+
22+
return 'Cache\AdapterBundle\Tests\Functional\app\AppKernel';
23+
}
24+
25+
protected static function createKernel(array $options = [])
26+
{
27+
$class = self::getKernelClass();
28+
29+
return new $class(
30+
isset($options['config']) ? $options['config'] : 'default.yml'
31+
);
32+
}
33+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
<?php
2+
3+
/*
4+
* This file is part of php-cache organization.
5+
*
6+
* (c) 2015-2015 Aaron Scherer <[email protected]>, Tobias Nyholm <[email protected]>
7+
*
8+
* This source file is subject to the MIT license that is bundled
9+
* with this source code in the file LICENSE.
10+
*/
11+
12+
namespace Cache\AdapterBundle\Tests\Functional;
13+
14+
class BundleInitializationTest extends BaseTestCase
15+
{
16+
public function testRegisterBundle()
17+
{
18+
static::createClient();
19+
}
20+
}

tests/Functional/app/AppKernel.php

+66
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
<?php
2+
3+
/*
4+
* This file is part of php-cache organization.
5+
*
6+
* (c) 2015-2015 Aaron Scherer <[email protected]>, Tobias Nyholm <[email protected]>
7+
*
8+
* This source file is subject to the MIT license that is bundled
9+
* with this source code in the file LICENSE.
10+
*/
11+
12+
namespace Cache\AdapterBundle\Tests\Functional\app;
13+
14+
use Symfony\Component\Config\Loader\LoaderInterface;
15+
use Symfony\Component\Filesystem\Filesystem;
16+
use Symfony\Component\HttpKernel\Kernel;
17+
18+
class AppKernel extends Kernel
19+
{
20+
private $config;
21+
22+
public function __construct($config)
23+
{
24+
parent::__construct('test', true);
25+
26+
$fs = new Filesystem();
27+
28+
if (!$fs->isAbsolutePath($config)) {
29+
$config = __DIR__.'/config/'.$config;
30+
}
31+
32+
if (!file_exists($config)) {
33+
throw new \RuntimeException(sprintf('The config file "%s" does not exist', $config));
34+
}
35+
36+
$this->config = $config;
37+
}
38+
39+
public function registerBundles()
40+
{
41+
return [
42+
new \Symfony\Bundle\FrameworkBundle\FrameworkBundle(),
43+
new \Cache\AdapterBundle\CacheAdapterBundle(),
44+
];
45+
}
46+
47+
public function registerContainerConfiguration(LoaderInterface $loader)
48+
{
49+
$loader->load($this->config);
50+
}
51+
52+
public function getCacheDir()
53+
{
54+
return sys_get_temp_dir().'/TestBundle';
55+
}
56+
57+
public function serialize()
58+
{
59+
return $this->config;
60+
}
61+
62+
public function unserialize($config)
63+
{
64+
$this->__construct($config);
65+
}
66+
}
+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
imports:
2+
- { resource: framework.yml }
3+
4+
cache_adapter:
5+
providers:
6+
my_adapter:
7+
factory: 'cache.factory.array'
8+
options: []
9+
aliases: ['alias.my_adapter']
+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
framework:
2+
secret: test
3+
test: ~
4+
session:
5+
storage_id: session.storage.mock_file
6+
form: false
7+
csrf_protection: false
8+
validation:
9+
enabled: false
10+
router:
11+
resource: "%kernel.root_dir%/config/routing.yml"

tests/Functional/app/config/routing.yml

Whitespace-only changes.

tests/DependencyInjection/DoctrineCacheExtensionTest.php tests/Unit/DependencyInjection/DoctrineCacheExtensionTest.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
* with this source code in the file LICENSE.
1010
*/
1111

12-
namespace Cache\Adapter\DoctrineAdapterBundle\Tests\DependencyInjection;
12+
namespace Cache\AdapterBundle\Tests\Unit\DependencyInjection;
1313

1414
use Cache\AdapterBundle\DependencyInjection\CacheAdapterExtension;
1515
use Cache\AdapterBundle\DummyAdapter;

tests/DsnTest.php tests/Unit/DsnTest.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
* with this source code in the file LICENSE.
1010
*/
1111

12-
namespace Cache\Adapter\DoctrineAdapterBundle\Tests;
12+
namespace Cache\AdapterBundle\Tests\Unit;
1313

1414
use Cache\AdapterBundle\DSN;
1515

0 commit comments

Comments
 (0)