From ddab76d8294d25d8e5f101131e8bf20cfb80d418 Mon Sep 17 00:00:00 2001 From: Richard van Laak Date: Wed, 10 Jun 2020 15:31:08 +0200 Subject: [PATCH 1/3] restructure folders --- README.md | 10 +++--- Resources/config/services.xml | 35 ------------------- composer.json | 2 +- .../APYBreadcrumbTrailBundle.php | 0 {Annotation => src/Annotation}/Breadcrumb.php | 0 .../BreadcrumbTrail}/Breadcrumb.php | 0 .../BreadcrumbTrail}/Trail.php | 19 ++++------ .../APYBreadcrumbTrailExtension.php | 2 +- .../DependencyInjection}/Configuration.php | 0 .../EventListener}/BreadcrumbListener.php | 0 src/Resources/config/services.xml | 21 +++++++++++ .../doc/annotation_configuration.md | 0 .../Resources}/doc/installation.md | 0 .../Resources}/doc/override_template.md | 0 .../Resources}/doc/php_configuration.md | 0 {Resources => src/Resources}/doc/rendering.md | 0 .../Resources}/doc/twig_configuration.md | 0 {Resources => src/Resources}/meta/LICENSE | 0 .../views/breadcrumbtrail.html.twig | 0 .../Twig}/BreadcrumbTrailExtension.php | 0 20 files changed, 34 insertions(+), 55 deletions(-) delete mode 100644 Resources/config/services.xml rename APYBreadcrumbTrailBundle.php => src/APYBreadcrumbTrailBundle.php (100%) rename {Annotation => src/Annotation}/Breadcrumb.php (100%) rename {BreadcrumbTrail => src/BreadcrumbTrail}/Breadcrumb.php (100%) rename {BreadcrumbTrail => src/BreadcrumbTrail}/Trail.php (94%) rename {DependencyInjection => src/DependencyInjection}/APYBreadcrumbTrailExtension.php (96%) rename {DependencyInjection => src/DependencyInjection}/Configuration.php (100%) rename {EventListener => src/EventListener}/BreadcrumbListener.php (100%) create mode 100644 src/Resources/config/services.xml rename {Resources => src/Resources}/doc/annotation_configuration.md (100%) rename {Resources => src/Resources}/doc/installation.md (100%) rename {Resources => src/Resources}/doc/override_template.md (100%) rename {Resources => src/Resources}/doc/php_configuration.md (100%) rename {Resources => src/Resources}/doc/rendering.md (100%) rename {Resources => src/Resources}/doc/twig_configuration.md (100%) rename {Resources => src/Resources}/meta/LICENSE (100%) rename {Resources => src/Resources}/views/breadcrumbtrail.html.twig (100%) rename {Twig => src/Twig}/BreadcrumbTrailExtension.php (100%) 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..2bc66cf 100644 --- a/composer.json +++ b/composer.json @@ -20,7 +20,7 @@ "ext-intl": "*" }, "autoload": { - "psr-4": { "APY\\BreadcrumbTrailBundle\\": "" } + "psr-4": { "APY\\BreadcrumbTrailBundle\\": "src/" } }, "target-dir": "APY/BreadcrumbTrailBundle" } 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 From 4a5b3b9755adfce0d092d02eb16c56e6a1b54f89 Mon Sep 17 00:00:00 2001 From: Richard van Laak Date: Wed, 10 Jun 2020 15:34:32 +0200 Subject: [PATCH 2/3] add integration test suite --- CHANGELOG.md | 5 ++- Makefile | 6 +++ composer.json | 21 +++++++++-- phpunit.xml.dist | 32 ++++++++++++++++ tests/BundleInitializationTest.php | 22 +++++++++++ tests/ExtensionTest.php | 27 ++++++++++++++ tests/Twig/BreadcrumbTrailExtensionTest.php | 41 +++++++++++++++++++++ 7 files changed, 149 insertions(+), 5 deletions(-) create mode 100644 Makefile create mode 100644 phpunit.xml.dist create mode 100644 tests/BundleInitializationTest.php create mode 100644 tests/ExtensionTest.php create mode 100644 tests/Twig/BreadcrumbTrailExtensionTest.php 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/composer.json b/composer.json index 2bc66cf..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\\": "src/" } }, - "target-dir": "APY/BreadcrumbTrailBundle" + "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" + }, + "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/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') + ); + } +} From 3388c3ae5834e2f9445b395c4720c8424457d6e1 Mon Sep 17 00:00:00 2001 From: Richard van Laak Date: Wed, 10 Jun 2020 15:45:41 +0200 Subject: [PATCH 3/3] Run CI via Github Actions --- .github/workflows/ci.yml | 62 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 62 insertions(+) create mode 100644 .github/workflows/ci.yml 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