Skip to content
This repository was archived by the owner on Nov 25, 2020. It is now read-only.

Commit 640df8f

Browse files
author
Sam Partington
authored
Merge pull request #82 from balazslevi/master
Adding Symfony4 support
2 parents db24185 + ae7c361 commit 640df8f

File tree

7 files changed

+174
-1
lines changed

7 files changed

+174
-1
lines changed

.travis.yml

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
language: php
2+
3+
dist: trusty
4+
5+
php:
6+
- 7.0
7+
- 7.1
8+
- 7.2
9+
- master
10+
11+
matrix:
12+
include:
13+
- php: 7.1
14+
env: SYMFONY_VERSION=2.3.*
15+
- php: 7.1
16+
env: SYMFONY_VERSION=2.7.*
17+
- php: 7.1
18+
env: SYMFONY_VERSION=2.8.*
19+
- php: 7.1
20+
env: SYMFONY_VERSION=3.0.*
21+
- php: 7.1
22+
env: SYMFONY_VERSION="4.0.*"
23+
24+
sudo: false
25+
26+
cache:
27+
directories:
28+
- $HOME/.composer/cache/files
29+
30+
before_install:
31+
- composer self-update
32+
- if [ "$SYMFONY_VERSION" != "" ]; then composer require --dev --no-update symfony/symfony=$SYMFONY_VERSION; fi
33+
- INI_FILE=~/.phpenv/versions/$(phpenv version-name)/etc/conf.d/travis.ini;
34+
- echo memory_limit = -1 >> $INI_FILE
35+
36+
install:
37+
- composer install

Test/AppKernel.php

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
<?php
2+
namespace WhiteOctober\BreadcrumbsBundle\Test;
3+
4+
use Symfony\Bundle\FrameworkBundle\FrameworkBundle;
5+
use Symfony\Component\Config\Loader\LoaderInterface;
6+
use Symfony\Component\DependencyInjection\ContainerBuilder;
7+
use Symfony\Component\HttpKernel\Kernel;
8+
9+
/**
10+
* Class AppKernel
11+
* It is needed to simulate an application to make some functional tests
12+
*/
13+
class AppKernel extends Kernel
14+
{
15+
/**
16+
* @var string[]
17+
*/
18+
private $bundlesToRegister = [];
19+
20+
/**
21+
* @var array
22+
*/
23+
private $configFiles = [];
24+
25+
/**
26+
* @var string
27+
*/
28+
private $cachePrefix = '';
29+
30+
public function __construct($cachePrefix)
31+
{
32+
parent::__construct($cachePrefix, true);
33+
$this->cachePrefix = $cachePrefix;
34+
$this->addBundle(FrameworkBundle::class);
35+
$this->addConfigFile(__DIR__.'/config.xml');
36+
$this->addConfigFile(__DIR__.'/../Resources/config/breadcrumbs.xml');
37+
}
38+
39+
public function addBundle($bundleClassName)
40+
{
41+
$this->bundlesToRegister[] = $bundleClassName;
42+
}
43+
44+
public function registerBundles()
45+
{
46+
$this->bundlesToRegister = array_unique($this->bundlesToRegister);
47+
$bundles = [];
48+
foreach ($this->bundlesToRegister as $bundle) {
49+
$bundles[] = new $bundle();
50+
}
51+
52+
return $bundles;
53+
}
54+
/**
55+
* {@inheritdoc}
56+
*/
57+
public function registerContainerConfiguration(LoaderInterface $loader)
58+
{
59+
$loader->load(function (ContainerBuilder $container) use ($loader) {
60+
$this->configFiles = array_unique($this->configFiles);
61+
foreach ($this->configFiles as $path) {
62+
$loader->load($path);
63+
}
64+
65+
$container->addObjectResource($this);
66+
$container->setParameter('white_october_breadcrumbs.options', []);
67+
});
68+
}
69+
/**
70+
* @param string $configFile path to config file
71+
*/
72+
public function addConfigFile($configFile)
73+
{
74+
$this->configFiles[] = $configFile;
75+
}
76+
}

Test/BundleTest.php

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
<?php
2+
// The condition is needed for testing the bundle against Symfony versions 2.3.* and 3.0.*
3+
if (!class_exists('\PHPUnit_Framework_TestCase') &&
4+
class_exists('\PHPUnit\Framework\TestCase')) {
5+
class_alias('\PHPUnit\Framework\TestCase', '\PHPUnit_Framework_TestCase');
6+
}
7+
8+
class BundleTest extends \Symfony\Bundle\FrameworkBundle\Test\WebTestCase
9+
{
10+
public function testInitBundle()
11+
{
12+
$client = static::createClient();
13+
14+
$container = $client->getContainer();
15+
16+
// Test if the service exists
17+
$this->assertTrue($container->has('white_october_breadcrumbs.helper'));
18+
19+
$service = $container->get('white_october_breadcrumbs.helper');
20+
$this->assertInstanceOf(\WhiteOctober\BreadcrumbsBundle\Templating\Helper\BreadcrumbsHelper::class, $service);
21+
}
22+
23+
public static function getKernelClass()
24+
{
25+
return \WhiteOctober\BreadcrumbsBundle\Test\AppKernel::class;
26+
}
27+
}

Test/bootstrap.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
<?php
2+
$loader = require __DIR__.'/../vendor/autoload.php';

Test/config.xml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<?xml version="1.0" encoding="UTF-8" ?>
2+
<container xmlns="http://symfony.com/schema/dic/services"
3+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:framework="http://symfony.com/schema/dic/symfony"
4+
xsi:schemaLocation="http://symfony.com/schema/dic/services http://symfony.com/schema/dic/services/services-1.0.xsd">
5+
<framework:config secret="secret" test="true">
6+
<framework:templating>
7+
<framework:engine>php</framework:engine>
8+
</framework:templating>
9+
<framework:router resource=""></framework:router>
10+
</framework:config>
11+
</container>

composer.json

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,12 @@
1313
],
1414
"require": {
1515
"php": ">=5.3.2",
16-
"symfony/framework-bundle": "~2.0|~3.0"
16+
"symfony/framework-bundle": "~2.0|~3.0|^4.0"
17+
},
18+
"require-dev": {
19+
"phpunit/phpunit": "^6.4",
20+
"symfony/templating": "^3.4|^4.0",
21+
"symfony/browser-kit": "~2.7|~3.0|^4.0"
1722
},
1823
"autoload": {
1924
"psr-0": { "WhiteOctober\\BreadcrumbsBundle": "" }

phpunit.xml

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
3+
<phpunit bootstrap="Test/bootstrap.php" colors="true">
4+
<testsuites>
5+
<testsuite name="BreadcrumbsBundle Test Suite">
6+
<directory>Test/</directory>
7+
</testsuite>
8+
</testsuites>
9+
10+
<filter>
11+
<whitelist>
12+
<directory suffix=".php">/</directory>
13+
</whitelist>
14+
</filter>
15+
</phpunit>

0 commit comments

Comments
 (0)