diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 0000000..37553d0 --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,62 @@ +name: CI + +on: + push: + branches: + - master + pull_request: + +jobs: + test: + name: Test + runs-on: ubuntu-latest + strategy: + max-parallel: 10 + matrix: + php: ['7.2', '7.3', '7.4'] + + steps: + - name: Set up PHP + uses: shivammathur/setup-php@1.7.0 + with: + php-version: ${{ matrix.php }} + coverage: xdebug + ini-values: xdebug.overload_var_dump=1 + extensions: mbstring, intl + tools: prestissimo + + - name: Setup Problem Matchers for PHPUnit + run: echo "::add-matcher::${{ runner.tool_cache }}/phpunit.json" + + - name: Checkout code + uses: actions/checkout@v2 + + - name: Run tests + run: make test + + test-lowest: + name: Test Lowest + runs-on: ubuntu-latest + strategy: + max-parallel: 10 + matrix: + php: ['7.2', '7.3', '7.4'] + + steps: + - name: Set up PHP + uses: shivammathur/setup-php@1.7.0 + with: + php-version: ${{ matrix.php }} + coverage: xdebug + ini-values: xdebug.overload_var_dump=1 + extensions: mbstring, intl + tools: prestissimo + + - name: Setup Problem Matchers for PHPUnit + run: echo "::add-matcher::${{ runner.tool_cache }}/phpunit.json" + + - name: Checkout code + uses: actions/checkout@v2 + + - name: Run tests + run: make test-lowest diff --git a/CHANGELOG.md b/CHANGELOG.md index 4527a96..a07b712 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,6 @@ +#2020-06-10 + - Add PHPUnit to integration test bundle + #2015-11-10 - Allow complex expressions in breadcrumb names and route parameters @@ -27,4 +30,4 @@ - Translate titles #2011-12-17 - - Initial commit \ No newline at end of file + - Initial commit diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..255918f --- /dev/null +++ b/Makefile @@ -0,0 +1,6 @@ +test: + composer update --prefer-dist --no-interaction ${COMPOSER_PARAMS} + composer test + +test-lowest: + COMPOSER_PARAMS='--prefer-lowest' $(MAKE) test diff --git a/README.md b/README.md index c26b7ca..bc820c8 100644 --- a/README.md +++ b/README.md @@ -10,8 +10,8 @@ Please follow the steps given [here](https://github.com/Abhoryo/APYBreadcrumbTra ## Summary - - [Annotation configuration](Resources/doc/annotation_configuration.md) - - [PHP configuration](Resources/doc/php_configuration.md) - - [Twig configuration](Resources/doc/twig_configuration.md) - - [Render the breadcrumb trail](Resources/doc/rendering.md) - - [Override the template](Resources/doc/override_template.md) + - [Annotation configuration](src/Resources/doc/annotation_configuration.md) + - [PHP configuration](src/Resources/doc/php_configuration.md) + - [Twig configuration](src/Resources/doc/twig_configuration.md) + - [Render the breadcrumb trail](src/Resources/doc/rendering.md) + - [Override the template](src/Resources/doc/override_template.md) diff --git a/Resources/config/services.xml b/Resources/config/services.xml deleted file mode 100644 index 03a1e3a..0000000 --- a/Resources/config/services.xml +++ /dev/null @@ -1,35 +0,0 @@ - - - - - APY\BreadcrumbTrailBundle\BreadcrumbTrail\Trail - APY\BreadcrumbTrailBundle\Twig\BreadcrumbTrailExtension - APY\BreadcrumbTrailBundle\EventListener\BreadcrumbListener - - - - - - - - %apy_breadcrumb_trail.template% - - - - - - - - - - - - - - - - - - diff --git a/composer.json b/composer.json index ea4c13b..f7c0d79 100644 --- a/composer.json +++ b/composer.json @@ -12,15 +12,28 @@ } ], "require": { - "php": ">=5.3.3", - "symfony/framework-bundle": "^2.3|^3.0|^4.0|^5.0", + "php": ">=7.1", + "symfony/framework-bundle": "^3.4|^4.0|^5.0", "twig/twig": "^1.41|^2.0|^3.0" }, + "scripts": { + "test": "vendor/bin/simple-phpunit --testdox" + }, "suggest": { - "ext-intl": "*" + "doctrine/doctrine-bundle": "To allow adding breadcrumbs on controller actions by the use of annotations.", + "twig/twig": "To allow adding breadcrumbs via Twig templates." }, "autoload": { - "psr-4": { "APY\\BreadcrumbTrailBundle\\": "" } + "psr-4": { "APY\\BreadcrumbTrailBundle\\": "src/" } + }, + "require-dev": { + "symfony/phpunit-bridge": "^5.0", + "nyholm/symfony-bundle-test": "^1.5", + "matthiasnoback/symfony-dependency-injection-test": "^4.0", + "doctrine/doctrine-bundle": "^v1.0|^v2.0", + "symfony/twig-bundle": "^3.4|^4.0|^5.0" }, - "target-dir": "APY/BreadcrumbTrailBundle" + "autoload-dev": { + "psr-4": { "APY\\BreadcrumbTrailBundle\\": "tests/" } + } } diff --git a/phpunit.xml.dist b/phpunit.xml.dist new file mode 100644 index 0000000..b766220 --- /dev/null +++ b/phpunit.xml.dist @@ -0,0 +1,32 @@ + + + + + + + + + + + + + + + ./tests + + + + + + ./src/ + + + diff --git a/APYBreadcrumbTrailBundle.php b/src/APYBreadcrumbTrailBundle.php similarity index 100% rename from APYBreadcrumbTrailBundle.php rename to src/APYBreadcrumbTrailBundle.php diff --git a/Annotation/Breadcrumb.php b/src/Annotation/Breadcrumb.php similarity index 100% rename from Annotation/Breadcrumb.php rename to src/Annotation/Breadcrumb.php diff --git a/BreadcrumbTrail/Breadcrumb.php b/src/BreadcrumbTrail/Breadcrumb.php similarity index 100% rename from BreadcrumbTrail/Breadcrumb.php rename to src/BreadcrumbTrail/Breadcrumb.php diff --git a/BreadcrumbTrail/Trail.php b/src/BreadcrumbTrail/Trail.php similarity index 94% rename from BreadcrumbTrail/Trail.php rename to src/BreadcrumbTrail/Trail.php index 5d0540f..5b21295 100644 --- a/BreadcrumbTrail/Trail.php +++ b/src/BreadcrumbTrail/Trail.php @@ -11,7 +11,7 @@ namespace APY\BreadcrumbTrailBundle\BreadcrumbTrail; -use Symfony\Component\DependencyInjection\ContainerInterface; +use Symfony\Component\HttpFoundation\RequestStack; use Symfony\Component\Routing\Generator\UrlGeneratorInterface; class Trail implements \IteratorAggregate, \Countable @@ -27,9 +27,9 @@ class Trail implements \IteratorAggregate, \Countable private $router; /** - * @var ContainerInterface container + * @var RequestStack */ - private $container; + private $requestStack; /** * @var string Template to render the breadcrumb trail @@ -37,14 +37,12 @@ class Trail implements \IteratorAggregate, \Countable private $template; /** - * Constructor. - * * @param UrlGeneratorInterface $router URL generator class */ - public function __construct(UrlGeneratorInterface $router, ContainerInterface $container) + public function __construct(UrlGeneratorInterface $router, RequestStack $requestStack) { $this->router = $router; - $this->container = $container; + $this->requestStack = $requestStack; $this->breadcrumbs = new \SplObjectStorage(); } @@ -86,12 +84,7 @@ public function add($breadcrumb_or_title, $routeName = null, $routeParameters = throw new \InvalidArgumentException('The title of a breadcrumb must be a string.'); } - if ($this->container->has('request_stack')) { - $request = $this->container->get('request_stack')->getCurrentRequest(); - } else { - // For Symfony < 2.4 - $request = $this->container->get('request', ContainerInterface::NULL_ON_INVALID_REFERENCE); - } + $request = $this->requestStack->getCurrentRequest(); if ($request !== null) { preg_match_all('#\{(?P\w+).?(?P([\w\.])*):?(?P(\w|,| )*)\}#', $breadcrumb_or_title, $matches, PREG_OFFSET_CAPTURE | PREG_SET_ORDER); diff --git a/DependencyInjection/APYBreadcrumbTrailExtension.php b/src/DependencyInjection/APYBreadcrumbTrailExtension.php similarity index 96% rename from DependencyInjection/APYBreadcrumbTrailExtension.php rename to src/DependencyInjection/APYBreadcrumbTrailExtension.php index 0004a15..c421a39 100644 --- a/DependencyInjection/APYBreadcrumbTrailExtension.php +++ b/src/DependencyInjection/APYBreadcrumbTrailExtension.php @@ -28,7 +28,7 @@ public function load(array $configs, ContainerBuilder $container) $container->setParameter('apy_breadcrumb_trail.template', $config['template']); - $loader = new XmlFileLoader($container, new FileLocator(__DIR__.'/../Resources/config')); + $loader = new XmlFileLoader($container, new FileLocator(__DIR__ . '/../Resources/config')); $loader->load('services.xml'); } } diff --git a/DependencyInjection/Configuration.php b/src/DependencyInjection/Configuration.php similarity index 100% rename from DependencyInjection/Configuration.php rename to src/DependencyInjection/Configuration.php diff --git a/EventListener/BreadcrumbListener.php b/src/EventListener/BreadcrumbListener.php similarity index 100% rename from EventListener/BreadcrumbListener.php rename to src/EventListener/BreadcrumbListener.php diff --git a/src/Resources/config/services.xml b/src/Resources/config/services.xml new file mode 100644 index 0000000..6e39b28 --- /dev/null +++ b/src/Resources/config/services.xml @@ -0,0 +1,21 @@ + + + + + + + + + + + %apy_breadcrumb_trail.template% + + + + + + + + diff --git a/Resources/doc/annotation_configuration.md b/src/Resources/doc/annotation_configuration.md similarity index 100% rename from Resources/doc/annotation_configuration.md rename to src/Resources/doc/annotation_configuration.md diff --git a/Resources/doc/installation.md b/src/Resources/doc/installation.md similarity index 100% rename from Resources/doc/installation.md rename to src/Resources/doc/installation.md diff --git a/Resources/doc/override_template.md b/src/Resources/doc/override_template.md similarity index 100% rename from Resources/doc/override_template.md rename to src/Resources/doc/override_template.md diff --git a/Resources/doc/php_configuration.md b/src/Resources/doc/php_configuration.md similarity index 100% rename from Resources/doc/php_configuration.md rename to src/Resources/doc/php_configuration.md diff --git a/Resources/doc/rendering.md b/src/Resources/doc/rendering.md similarity index 100% rename from Resources/doc/rendering.md rename to src/Resources/doc/rendering.md diff --git a/Resources/doc/twig_configuration.md b/src/Resources/doc/twig_configuration.md similarity index 100% rename from Resources/doc/twig_configuration.md rename to src/Resources/doc/twig_configuration.md diff --git a/Resources/meta/LICENSE b/src/Resources/meta/LICENSE similarity index 100% rename from Resources/meta/LICENSE rename to src/Resources/meta/LICENSE diff --git a/Resources/views/breadcrumbtrail.html.twig b/src/Resources/views/breadcrumbtrail.html.twig similarity index 100% rename from Resources/views/breadcrumbtrail.html.twig rename to src/Resources/views/breadcrumbtrail.html.twig diff --git a/Twig/BreadcrumbTrailExtension.php b/src/Twig/BreadcrumbTrailExtension.php similarity index 100% rename from Twig/BreadcrumbTrailExtension.php rename to src/Twig/BreadcrumbTrailExtension.php diff --git a/tests/BundleInitializationTest.php b/tests/BundleInitializationTest.php new file mode 100644 index 0000000..156bdda --- /dev/null +++ b/tests/BundleInitializationTest.php @@ -0,0 +1,22 @@ +bootKernel(); + $container = $this->getContainer(); + + $this->assertTrue($container->has('apy_breadcrumb_trail')); + $this->assertTrue($container->hasParameter('apy_breadcrumb_trail.template')); + } +} diff --git a/tests/ExtensionTest.php b/tests/ExtensionTest.php new file mode 100644 index 0000000..d6281f8 --- /dev/null +++ b/tests/ExtensionTest.php @@ -0,0 +1,27 @@ +load(); + $this->assertContainerBuilderHasService(Trail::class); + $this->assertContainerBuilderHasService(BreadcrumbListener::class); + $this->assertContainerBuilderHasService(BreadcrumbTrailExtension::class); + } +} diff --git a/tests/Twig/BreadcrumbTrailExtensionTest.php b/tests/Twig/BreadcrumbTrailExtensionTest.php new file mode 100644 index 0000000..adbc680 --- /dev/null +++ b/tests/Twig/BreadcrumbTrailExtensionTest.php @@ -0,0 +1,41 @@ +addCompilerPass(new PublicServicePass('|twig|')); + + $kernel = $this->createKernel(); + $kernel->addBundle(TwigBundle::class); + $kernel->boot(); + } + + public function testTwigFunctionGetsRegistered() + { + $container = $this->getContainer(); + + /** @var Environment $twig */ + $twig = $container->get('twig'); + + self::assertNotNull( + $twig->getFunction('apy_breadcrumb_trail_render') + ); + } +}