Skip to content
Merged
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
76 changes: 40 additions & 36 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -43,16 +43,17 @@ jobs:
coverage: none
php-version: ${{ matrix.php-version }}

- name: "symfony/flex is required to install the correct symfony version"
run: |
composer global config --no-plugins allow-plugins.symfony/flex true
composer global require symfony/flex

- name: "Configure Symfony version for symfony/flex"
run: composer config extra.symfony.require "${{ matrix.symfony-version }}"

- name: "Install dependencies with composer"
run: composer update --no-interaction --no-progress
run: |
composer require --no-interaction --no-update \
symfony/console:${{ matrix.symfony-version }} \
symfony/framework-bundle:${{ matrix.symfony-version }} \
symfony/http-kernel:${{ matrix.symfony-version }} \
symfony/routing:${{ matrix.symfony-version }} \
symfony/messenger:${{ matrix.symfony-version }} --dev \
symfony/browser-kit:${{ matrix.symfony-version }} --dev \
symfony/yaml:${{ matrix.symfony-version }} --dev
composer update --no-interaction --no-progress

- name: "Run tests with phpunit/phpunit"
run: vendor/bin/phpunit
Expand All @@ -77,16 +78,17 @@ jobs:
coverage: xdebug
php-version: ${{ matrix.php-version }}

- name: "symfony/flex is required to install the correct symfony version"
run: |
composer global config --no-plugins allow-plugins.symfony/flex true
composer global require symfony/flex

- name: "Configure Symfony version for symfony/flex"
run: composer config extra.symfony.require "${{ matrix.symfony-version }}"

- name: "Install dependencies with composer"
run: composer update --no-interaction --no-progress
run: |
composer require --no-interaction --no-update \
symfony/console:${{ matrix.symfony-version }} \
symfony/framework-bundle:${{ matrix.symfony-version }} \
symfony/http-kernel:${{ matrix.symfony-version }} \
symfony/routing:${{ matrix.symfony-version }} \
symfony/messenger:${{ matrix.symfony-version }} --dev \
symfony/browser-kit:${{ matrix.symfony-version }} --dev \
symfony/yaml:${{ matrix.symfony-version }} --dev
composer update --no-interaction --no-progress

- name: "Run tests with phpunit/phpunit"
env:
Expand Down Expand Up @@ -117,16 +119,17 @@ jobs:
coverage: none
php-version: ${{ matrix.php-version }}

- name: "symfony/flex is required to install the correct symfony version"
run: |
composer global config --no-plugins allow-plugins.symfony/flex true
composer global require symfony/flex

- name: "Configure Symfony version for symfony/flex"
run: composer config extra.symfony.require "${{ matrix.symfony-version }}"

- name: "Install dependencies with composer"
run: composer update --no-interaction --no-progress
run: |
composer require --no-interaction --no-update \
symfony/console:${{ matrix.symfony-version }} \
symfony/framework-bundle:${{ matrix.symfony-version }} \
symfony/http-kernel:${{ matrix.symfony-version }} \
symfony/routing:${{ matrix.symfony-version }} \
symfony/messenger:${{ matrix.symfony-version }} --dev \
symfony/browser-kit:${{ matrix.symfony-version }} --dev \
symfony/yaml:${{ matrix.symfony-version }} --dev
composer update --no-interaction --no-progress

- name: "Run static analysis with phpstan/phpstan"
run: vendor/bin/phpstan analyze
Expand All @@ -151,16 +154,17 @@ jobs:
coverage: none
php-version: ${{ matrix.php-version }}

- name: "symfony/flex is required to install the correct symfony version"
run: |
composer global config --no-plugins allow-plugins.symfony/flex true
composer global require symfony/flex

- name: "Configure Symfony version for symfony/flex"
run: composer config extra.symfony.require "${{ matrix.symfony-version }}"

- name: "Install dependencies with composer"
run: composer update --no-interaction --no-progress
run: |
composer require --no-interaction --no-update \
symfony/console:${{ matrix.symfony-version }} \
symfony/framework-bundle:${{ matrix.symfony-version }} \
symfony/http-kernel:${{ matrix.symfony-version }} \
symfony/routing:${{ matrix.symfony-version }} \
symfony/messenger:${{ matrix.symfony-version }} --dev \
symfony/browser-kit:${{ matrix.symfony-version }} --dev \
symfony/yaml:${{ matrix.symfony-version }} --dev
composer update --no-interaction --no-progress

- name: "Run checkstyle with squizlabs/php_codesniffer"
run: vendor/bin/phpcs
6 changes: 5 additions & 1 deletion phpcs.xml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,11 @@

<rule ref="Generic.PHP.ForbiddenFunctions">
<properties>
<property name="forbiddenFunctions" type="array" value="dump=>null,var_dump=>null,die=>null"/>
<property name="forbiddenFunctions" type="array">
<element key="dump" value="null"/>
<element key="var_dump" value="null"/>
<element key="die" value="null"/>
</property>
</properties>
</rule>

Expand Down
7 changes: 4 additions & 3 deletions tests/Integration/src/Controller/ArchivesController.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,15 @@
namespace Presta\SitemapBundle\Tests\Integration\Controller;

use Symfony\Component\HttpFoundation\Response;
use Presta\SitemapBundle\Route;
use Symfony\Component\Routing\Annotation\Route as RouteAnnotation;
use Symfony\Component\Routing\Attribute\Route as RouteAttribute;

final class ArchivesController
{
/**
* @Route("/archive", name="archive")
* @RouteAnnotation("/archive", name="archive")
*/
#[Route(path: '/archive', name: 'archive')]
#[RouteAttribute(path: '/archive', name: 'archive')]
public function archive(): Response
{
return new Response(__FUNCTION__);
Expand Down
11 changes: 6 additions & 5 deletions tests/Integration/src/Controller/BlogController.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,23 +12,24 @@
namespace Presta\SitemapBundle\Tests\Integration\Controller;

use Symfony\Component\HttpFoundation\Response;
use Presta\SitemapBundle\Route;
use Symfony\Component\Routing\Annotation\Route as RouteAnnotation;
use Symfony\Component\Routing\Attribute\Route as RouteAttribute;

final class BlogController
{
/**
* @Route("/blog", name="blog_read", options={"sitemap"={"section"="blog"}})
* @RouteAnnotation("/blog", name="blog_read", options={"sitemap"={"section"="blog"}})
*/
#[Route(path: '/blog', name: 'blog_read', options: ['sitemap' => ['section' => 'blog']])]
#[RouteAttribute(path: '/blog', name: 'blog_read', options: ['sitemap' => ['section' => 'blog']])]
public function read(): Response
{
return new Response(__FUNCTION__);
}

/**
* @Route("/blog/{slug}", name="blog_post")
* @RouteAnnotation("/blog/{slug}", name="blog_post")
*/
#[Route(path: '/blog/{slug}', name: 'blog_post')]
#[RouteAttribute(path: '/blog/{slug}', name: 'blog_post')]
public function post(string $slug): Response
{
return new Response(__FUNCTION__ . ':' . $slug);
Expand Down
7 changes: 4 additions & 3 deletions tests/Integration/src/Controller/MessengerController.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,15 @@
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Messenger\MessageBusInterface;
use Presta\SitemapBundle\Route;
use Symfony\Component\Routing\Annotation\Route as RouteAnnotation;
use Symfony\Component\Routing\Attribute\Route as RouteAttribute;

final class MessengerController
{
/**
* @Route("/dispatch-message", name="dispatch_message")
* @RouteAnnotation("/dispatch-message", name="dispatch_message")
*/
#[Route(path: '/dispatch-message', name: 'dispatch_message')]
#[RouteAttribute(path: '/dispatch-message', name: 'dispatch_message')]
public function dispatch(Request $request, MessageBusInterface $bus): Response
{
$bus->dispatch(new DumpSitemapMessage(null, null, null, ['gzip' => $request->query->getBoolean('gzip')]));
Expand Down
7 changes: 4 additions & 3 deletions tests/Integration/src/Controller/StaticController.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,15 @@
namespace Presta\SitemapBundle\Tests\Integration\Controller;

use Symfony\Component\HttpFoundation\Response;
use Presta\SitemapBundle\Route;
use Symfony\Component\Routing\Annotation\Route as RouteAnnotation;
use Symfony\Component\Routing\Attribute\Route as RouteAttribute;

final class StaticController
{
/**
* @Route("", name="home", options={"sitemap"={"section"="static"}})
* @RouteAnnotation("", name="home", options={"sitemap"={"section"="static"}})
*/
#[Route(path: '', name: 'home', options: ['sitemap' => ['section' => 'static']])]
#[RouteAttribute(path: '', name: 'home', options: ['sitemap' => ['section' => 'static']])]
public function home(): Response
{
return new Response(__FUNCTION__);
Expand Down
17 changes: 0 additions & 17 deletions tests/Integration/src/Kernel.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,23 +23,6 @@ class Kernel extends BaseKernel
{
use MicroKernelTrait;

public function __construct(string $environment, bool $debug)
{
$this->setupRouteAlias();

parent::__construct($environment, $debug);
}

// TODO: Remove after dropping support for Symfony 7.x
private function setupRouteAlias(): void
{
if (class_exists('Symfony\Component\Routing\Annotation\Route')) {
class_alias('Symfony\Component\Routing\Annotation\Route', 'Presta\SitemapBundle\Route');
} elseif (class_exists('Symfony\Component\Routing\Attribute\Route')) {
class_alias('Symfony\Component\Routing\Attribute\Route', 'Presta\SitemapBundle\Route');
}
}

public function getCacheDir(): string
{
return $this->getProjectDir() . '/var/cache/' . $this->environment;
Expand Down
7 changes: 3 additions & 4 deletions tests/Integration/tests/CliTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

namespace Presta\SitemapBundle\Tests\Integration\Tests;

use PHPUnit\Framework\Attributes\DataProvider;
use Symfony\Bundle\FrameworkBundle\Console\Application;
use Symfony\Component\Console\Tester\CommandTester;

Expand Down Expand Up @@ -62,17 +63,15 @@ private function fileContent(string $file, bool $gzip = false): string
return $data;
}

public function gzip(): array
public static function gzip(): array
{
return [
[false],
[true],
];
}

/**
* @dataProvider gzip
*/
#[DataProvider('gzip')]
public function testDumpSitemapUsingCLI(bool $gzip): void
{
$index = $this->index();
Expand Down
7 changes: 3 additions & 4 deletions tests/Integration/tests/MessengerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

namespace Presta\SitemapBundle\Tests\Integration\Tests;

use PHPUnit\Framework\Attributes\DataProvider;
use Psr\Log\LoggerInterface;
use Symfony\Bundle\FrameworkBundle\KernelBrowser;
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
Expand Down Expand Up @@ -40,9 +41,7 @@ protected function setUp(): void
}
}

/**
* @dataProvider gzip
*/
#[DataProvider('gzip')]
public function testDumpSitemapUsingMessenger(bool $gzip): void
{
$kernel = self::bootKernel();
Expand Down Expand Up @@ -102,7 +101,7 @@ public function testDumpSitemapUsingMessenger(bool $gzip): void
self::assertArchivesSection($this->fileContent($archives0, $gzip));
}

public function gzip(): array
public static function gzip(): array
{
return [
[false],
Expand Down
17 changes: 6 additions & 11 deletions tests/Unit/Command/DumpSitemapsCommandTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

namespace Presta\SitemapBundle\Tests\Unit\Command;

use PHPUnit\Framework\Attributes\DataProvider;
use PHPUnit\Framework\MockObject\MockObject;
use PHPUnit\Framework\TestCase;
use Presta\SitemapBundle\Command\DumpSitemapsCommand;
Expand Down Expand Up @@ -43,9 +44,7 @@ protected function setUp(): void
$this->dumper = $this->createMock(DumperInterface::class);
}

/**
* @dataProvider dump
*/
#[DataProvider('dump')]
public function testDumpSitemapSuccessful(?string $section, bool $gzip): void
{
if ($section === null) {
Expand All @@ -66,9 +65,7 @@ public function testDumpSitemapSuccessful(?string $section, bool $gzip): void
}
}

/**
* @dataProvider dump
*/
#[DataProvider('dump')]
public function testDumpSitemapFailed(?string $section, bool $gzip): void
{
$this->dumper->method('dump')
Expand All @@ -80,9 +77,7 @@ public function testDumpSitemapFailed(?string $section, bool $gzip): void
self::assertSame(1, $status, 'Command returned an error code');
}

/**
* @dataProvider baseUrls
*/
#[DataProvider('baseUrls')]
public function testRouterHost(string $inUrl, string $expectedUrl): void
{
$this->router->getContext()->fromRequest(Request::create($inUrl));
Expand Down Expand Up @@ -131,15 +126,15 @@ public function testInvalidBaseUrlOption(): void
$this->executeCommand(null, false, 'not an url');
}

public function dump(): \Generator
public static function dump(): \Generator
{
yield 'Entire sitemap' => [null, false];
yield 'Entire sitemap with gzip' => [null, true];
yield '"audio" sitemap section' => ['audio', false];
yield '"audio" sitemap with gzip' => ['audio', true];
}

public function baseUrls(): \Generator
public static function baseUrls(): \Generator
{
yield 'Standard http' => ['http://host.org', 'http://host.org/'];
yield 'Standard http with port' => ['http://host.org:80', 'http://host.org/'];
Expand Down
11 changes: 4 additions & 7 deletions tests/Unit/EventListener/RouteAnnotationEventListenerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

namespace Presta\SitemapBundle\Tests\Unit\EventListener;

use PHPUnit\Framework\Attributes\DataProvider;
use PHPUnit\Framework\TestCase;
use Presta\SitemapBundle\Event\SitemapAddUrlEvent;
use Presta\SitemapBundle\Event\SitemapPopulateEvent;
Expand All @@ -27,9 +28,7 @@

class RouteAnnotationEventListenerTest extends TestCase
{
/**
* @dataProvider routes
*/
#[DataProvider('routes')]
public function testPopulateSitemap(?string $section, array $routes, array $urls): void
{
$urlContainer = $this->dispatch($section, $routes);
Expand All @@ -55,9 +54,7 @@ public function testPopulateSitemap(?string $section, array $routes, array $urls
}
}

/**
* @dataProvider routes
*/
#[DataProvider('routes')]
public function testEventListenerCanPreventUrlFromBeingAddedToSitemap(?string $section, array $routes): void
{
$urlContainer = $this->dispatch($section, $routes, function (SitemapAddUrlEvent $event): void {
Expand All @@ -80,7 +77,7 @@ public function testEventListenerCanSetUrl(): void
self::assertNotNull($this->findUrl($urlset, 'http://localhost/redirect'));
}

public function routes(): \Generator
public static function routes(): \Generator
{
// *Route vars : [name, path, sitemap option]
// *Sitemap vars : [loc, changefreq, lastmod, priority]
Expand Down
Loading