Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WIP: Add functional tests, update dependencies, drop PHP5 support. #30

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,7 @@ app/config/parameters.yml

# Composer
composer.phar
composer.lock
composer.lock

# Code coverage
coverage/
33 changes: 8 additions & 25 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,16 @@ language: php

sudo: false

dist: trusty

cache:
directories:
- $HOME/.composer/cache/files

php:
- 5.5
- 7.0
- 7.1
- 7.2
- 7.3

env:
- SYMFONY_VERSION=2.3.*
Expand All @@ -25,32 +26,14 @@ env:
- SYMFONY_VERSION=4.0.*
- SYMFONY_VERSION=4.1.*
- SYMFONY_VERSION=4.2.*
- SYMFONY_VERSION=4.3.*
- SYMFONY_VERSION=4.3.*
- SYMFONY_VERSION=4.4.*
- SYMFONY_VERSION=5.0.*
- SYMFONY_VERSION=5.1.*

matrix:
fast_finish: true
exclude:
- php: 5.5
env: SYMFONY_VERSION=4.0.*
- php: 7.0
env: SYMFONY_VERSION=4.0.*
- php: 5.5
env: SYMFONY_VERSION=4.1.*
- php: 7.0
env: SYMFONY_VERSION=4.1.*
- php: 5.5
env: SYMFONY_VERSION=4.2.*
- php: 7.0
env: SYMFONY_VERSION=4.2.*
include:
- php: 7.1
env: SYMFONY_VERSION=4.3.* STABILITY=dev
- php: 7.2
env: SYMFONY_VERSION=4.3.* STABILITY=dev
allow_failures:
- php: 7.1
env: SYMFONY_VERSION=4.3.* STABILITY=dev
- php: 7.2
env: SYMFONY_VERSION=4.3.* STABILITY=dev

before_install:
- composer self-update
Expand Down
3 changes: 2 additions & 1 deletion DependencyInjection/Configuration.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ public function getConfigTreeBuilder()
{
$treeBuilder = new TreeBuilder('thormeier_breadcrumb');
$rootNode = method_exists(TreeBuilder::class, 'getRootNode')
? $treeBuilder->getRootNode() : $treeBuilder->root('thormeier_breadcrumb');
? $treeBuilder->getRootNode()
: $treeBuilder->root('thormeier_breadcrumb');

$rootNode
->children()
Expand Down
10 changes: 8 additions & 2 deletions DependencyInjection/RoutingLoaderCompilerPass.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,14 @@ public function process(ContainerBuilder $container)
{
$routingLoaderDefinition = $container->getDefinition('routing.loader');

$container->setDefinition('thormeier_breadcrumb.routing.attach_breadcrumb_loader.inner', $routingLoaderDefinition);
$container->setDefinition(
'thormeier_breadcrumb.routing.attach_breadcrumb_loader.inner',
$routingLoaderDefinition
);

$container->setAlias('routing.loader', 'thormeier_breadcrumb.routing.attach_breadcrumb_loader')->setPublic(true);
$container->setAlias(
'routing.loader',
'thormeier_breadcrumb.routing.attach_breadcrumb_loader'
)->setPublic(true);
}
}
2 changes: 1 addition & 1 deletion DependencyInjection/ThormeierBreadcrumbExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
use Symfony\Component\DependencyInjection\Loader;

/**
* Symfony2 DI extension
* Symfony DI extension
*
* @codeCoverageIgnore
*/
Expand Down
18 changes: 15 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ BreadcrumbBundle
## Introduction

This Symfony bundle provides integration of breadcrumbs via route config and rendering in your Twig templates.
This bundle is heavily inspired by the inactive https://github.com/xi-project/xi-bundle-breadcrumbs
This bundle is heavily inspired by the inactive [https://github.com/xi-project/xi-bundle-breadcrumbs](https://github.com/xi-project/xi-bundle-breadcrumbs)

## Installation
## Installation / Getting started

### Step 1: Composer require

Expand All @@ -35,7 +35,7 @@ Enable the bundle in your config.yml:
# config.yml
thormeier_breadcrumb: ~

The template defaults to a very basic one, providing a `<ul>` with `<li>` and `<a>` for every breadcrumb.
The template defaults to a basic one, providing a `<ul>` with `<li>` and `<a>` for every breadcrumb.

## Usage

Expand Down Expand Up @@ -259,3 +259,15 @@ a `BreadcrumbCollection` on demand.

A slideshow presenting the bundle and explaining some concepts a little further is available on slideshare:
[http://www.slideshare.net/Thormeier/thormeierbreadcrumbbundle](http://www.slideshare.net/Thormeier/thormeierbreadcrumbbundle)

## Development

To execute tests locally, execute the following command:

```
./vendor/bin/phpunit
```

The folder `coverage/` is ignored by git, it can therefore be used for generating coverage reports with `phpunit --coverage-html ./coverage/`.

If you want to contribute to this project, please feel free to open up issues and/or pull requests!
55 changes: 55 additions & 0 deletions Tests/Functional/AbstractBreadcrumbRenderTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
<?php

namespace Thormeier\BreadcrumbBundle\Tests\Functional;

use Symfony\Component\Config\Loader\LoaderResolver;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Loader\PhpFileLoader;
use Thormeier\BreadcrumbBundle\Tests\Functional\App\AppKernel;
use Twig\Environment;
use Twig\Loader\FilesystemLoader;

abstract class AbstractBreadcrumbRenderTest extends \PHPUnit_Framework_TestCase
{
/**
* @var AppKernel Kernel with all necessary services to test the bundle.
*/
protected $kernel;

/**
* Sets up the AppKernel and a console application
*/
protected function setUp()
{
$kernel = new AppKernel('test', false);
$kernel->boot();

/** @var Environment $twigEnv */
$twigEnv = $kernel->getContainer()->get('twig');

/** @var FilesystemLoader $twigLoader */
$twigLoader = $twigEnv->getLoader();
$twigLoader->addPath(realpath('./Tests/Functional/Resources/views'));

$this->kernel = $kernel;

/** @var LoaderResolver $loaderResolver */
$this->kernel->getContainer()->get('routing.loader')->load(realpath('./Tests/Functional/App/routes.yml'));
}

/**
* @param $url
* @return string
* @throws \Exception
*/
public function doRequest($url)
{
$request = Request::create($url);

/** @var Response $response */
$response = $this->kernel->handle($request);

return $response->getContent();
}
}
41 changes: 41 additions & 0 deletions Tests/Functional/App/AppKernel.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
<?php

namespace Thormeier\BreadcrumbBundle\Tests\Functional\App;

use Symfony\Bundle\TwigBundle\TwigBundle;
use Symfony\Component\HttpKernel\Kernel;
use Symfony\Component\Config\Loader\LoaderInterface;
use Symfony\Bundle\FrameworkBundle\FrameworkBundle;
use Thormeier\BreadcrumbBundle\ThormeierBreadcrumbBundle;

/**
* Simple AppKernel for tests
*/
class AppKernel extends Kernel
{
/**
* Registers the TwigBundle, the BreadcrumbBundle and the FrameworkBundle
*
* @return array
*/
public function registerBundles()
{
return array(
new TwigBundle(),
new FrameworkBundle(),
new ThormeierBreadcrumbBundle(),
);
}

/**
* Load mocked config
*
* @param LoaderInterface $loader
*
* @throws \Exception
*/
public function registerContainerConfiguration(LoaderInterface $loader)
{
$loader->load(__DIR__ . '/config.php');
}
}
4 changes: 4 additions & 0 deletions Tests/Functional/App/autoload.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<?php
// Simple autoloader
$loader = require_once __DIR__.'/../../../vendor/autoload.php';
require_once __DIR__ . '/AppKernel.php';
14 changes: 14 additions & 0 deletions Tests/Functional/App/config.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?php

/** @var \Symfony\Component\DependencyInjection\ContainerBuilder $container */
$container->loadFromExtension('thormeier_breadcrumb', null);

$container->loadFromExtension('framework', array(
'secret' => 'foobar',
'session' => array(
'storage_id' => 'session.storage.mock_file'
),
'router' => array(
'resource' => realpath('./Tests/Functional/App/routes.yml'),
),
));
30 changes: 30 additions & 0 deletions Tests/Functional/App/routes.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
acme_demo_home:
path: /
controller: Thormeier\BreadcrumbBundle\Tests\Functional\Controller\BreadcrumbController::breadcrumbAction
options:
breadcrumb:
label: Home

acme_demo_contact:
path: /contact
controller: Thormeier\BreadcrumbBundle\Tests\Functional\Controller\BreadcrumbController::breadcrumbAction
options:
breadcrumb:
label: Contact
parent_route: acme_demo_home

acme_demo_catalogue:
path: /catalogue
controller: Thormeier\BreadcrumbBundle\Tests\Functional\Controller\BreadcrumbController::breadcrumbAction
options:
breadcrumb:
label: 'Our Catalogue'
parent_route: acme_demo_home

acme_demo_catalogue_categories:
path: /catalogue/categories
controller: Thormeier\BreadcrumbBundle\Tests\Functional\Controller\BreadcrumbController::breadcrumbAction
options:
breadcrumb:
label: 'All categories'
parent_route: acme_demo_catalogue
25 changes: 25 additions & 0 deletions Tests/Functional/BreadcrumbRenderTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<?php

namespace Thormeier\BreadcrumbBundle\Tests\Functional;

class BreadcrumbRenderTest extends AbstractBreadcrumbRenderTest
{
/**
* @throws \Exception
*/
public function testSingleBreadcrumb()
{
$response = $this->doRequest('/');
$this->assertContains('<a title="Home">Home</a>', $response);
}

/**
* @throws \Exception
*/
public function testDoubleBreadcrumb()
{
$response = $this->doRequest('/catalogue');
$this->assertContains('<a href="/" title="Home">Home</a>', $response);
$this->assertContains('<a title="Our Catalogue">Our Catalogue</a>', $response);
}
}
16 changes: 16 additions & 0 deletions Tests/Functional/Controller/BreadcrumbController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?php

namespace Thormeier\BreadcrumbBundle\Tests\Functional\Controller;

use Symfony\Bundle\FrameworkBundle\Controller\Controller;

class BreadcrumbController extends Controller
{
/**
* @return \Symfony\Component\HttpFoundation\Response
*/
public function breadcrumbAction()
{
return $this->render('breadcrumbs.twig');
}
}
1 change: 1 addition & 0 deletions Tests/Functional/Resources/views/breadcrumbs.twig
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{{ breadcrumbs() }}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

namespace Thormeier\BreadcrumbBundle\Tests\Model;
namespace Thormeier\BreadcrumbBundle\Tests\Unit\Model;

use Thormeier\BreadcrumbBundle\Model\Breadcrumb;
use Thormeier\BreadcrumbBundle\Model\BreadcrumbCollection;
Expand Down Expand Up @@ -99,6 +99,8 @@ public function testGetBreadcrumbByRoute()

$this->assertEquals($breadcrumbB, $collection->getBreadcrumbByRoute('baz'));
$this->assertEquals($breadcrumbA, $collection->getBreadcrumbByRoute('bar'));
$this->assertEquals($breadcrumbC, $collection->getBreadcrumbByRoute('qux'));
$this->assertEquals(null, $collection->getBreadcrumbByRoute('xyzzy'));
}

/**
Expand All @@ -115,4 +117,19 @@ public function testAddAfterBreadcrumbExceptionException()

$collection->addBreadcrumbAfterCrumb($breadcrumbA, $breadcrumbB);
}

/**
* Test throwing of exception if a breadcrumb doesn't exist
*/
public function testAddBeforeBreadcrumbExceptionException()
{
$breadcrumbA = new Breadcrumb('foo', 'bar');
$breadcrumbB = new Breadcrumb('bar', 'baz');

$collection = new BreadcrumbCollection();

$this->setExpectedException('\InvalidArgumentException');

$collection->addBreadcrumbBeforeCrumb($breadcrumbA, $breadcrumbB);
}
}
Loading