Skip to content
Permalink
Browse files

2.x Major (#210)

* Drop sf 2.*, update to phpunit 7, add symfony/yaml as dev dependency

* Rewrite tests to be compatible with phpunit 7

* Removed deprecated code parts

* Array short syntax

* Internally use DateTimeImmutable but allow DateTimeInterface everywhere

* Updated travis testing matrix
  • Loading branch information...
yann-eugone committed Sep 30, 2019
1 parent 691e45c commit cc446c9976cf6cd1984acf290e5719ded823bd72
Showing with 329 additions and 356 deletions.
  1. +3 −7 .travis.yml
  2. +3 −3 Command/DumpSitemapsCommand.php
  3. +0 −52 DependencyInjection/Compiler/AddSitemapListenersPass.php
  4. +0 −24 Event/SitemapPopulateEvent.php
  5. +4 −4 EventListener/RouteAnnotationEventListener.php
  6. +0 −10 PrestaSitemapBundle.php
  7. +5 −5 Service/AbstractGenerator.php
  8. +7 −7 Service/Dumper.php
  9. +1 −1 Service/DumperInterface.php
  10. +1 −1 Service/Generator.php
  11. +0 −35 Service/SitemapListenerInterface.php
  12. +14 −13 Sitemap/Url/GoogleNewsUrlDecorator.php
  13. +17 −17 Sitemap/Url/GoogleVideoUrlDecorator.php
  14. +11 −11 Sitemap/Url/UrlConcrete.php
  15. +1 −1 Sitemap/Url/UrlDecorator.php
  16. +7 −7 Sitemap/Urlset.php
  17. +15 −15 Tests/Command/DumpSitemapsCommandTest.php
  18. +2 −2 Tests/Controller/SitemapControllerTest.php
  19. +4 −3 Tests/DependencyInjection/PrestaSitemapExtensionTest.php
  20. +21 −21 Tests/EventListener/RouteAnnotationEventListenerTest.php
  21. +20 −20 Tests/Service/GeneratorTest.php
  22. +7 −4 Tests/Sitemap/SitemapindexTest.php
  23. +23 −9 Tests/Sitemap/Url/GoogleImageTest.php
  24. +8 −4 Tests/Sitemap/Url/GoogleImageUrlDecoratorTest.php
  25. +3 −2 Tests/Sitemap/Url/GoogleMobileUrlDecoratorTest.php
  26. +3 −2 Tests/Sitemap/Url/GoogleMultilangUrlDecoratorTest.php
  27. +26 −25 Tests/Sitemap/Url/GoogleNewsUrlDecoratorTest.php
  28. +10 −9 Tests/Sitemap/Url/GoogleVideoUrlDecoratorTest.php
  29. +86 −22 Tests/Sitemap/Url/UrlConcreteTest.php
  30. +7 −3 Tests/Sitemap/UrlsetTest.php
  31. +5 −4 Tests/Sitemap/UtilsTest.php
  32. +2 −2 Tests/app/AppKernel.php
  33. +13 −11 composer.json
@@ -2,18 +2,14 @@ language: php

matrix:
include:
- php: 5.6
env: SYMFONY_VERSION=2.7.*
- php: 5.6
env: SYMFONY_VERSION=2.8.*
- php: 7.1
env: SYMFONY_VERSION=3.4.*
- php: 7.2
env: SYMFONY_VERSION=3.4.*
- php: 7.3
env: SYMFONY_VERSION=3.4.*
- php: 7.3
env: SYMFONY_VERSION=4.2.*
env: SYMFONY_VERSION=4.3.*

env:
global:
@@ -30,9 +26,9 @@ before_install:
- if [ "$PHPCS" = "yes" ]; then phpenv rehash; fi
- if [ "$PHPCS" != "yes"]; then composer selfupdate; fi
- if [ "$SYMFONY_VERSION" != "" ]; then composer require --no-update symfony/symfony:${SYMFONY_VERSION}; fi
- if [ "$SYMFONY_VERSION" = "3.4.*" ] || [ "$SYMFONY_VERSION" = "4.2.*" ]; then rm -f phpunit.xml; cp phpunit.sf4.xml.dist phpunit.xml; fi
- if [ "$SYMFONY_VERSION" = "3.4.*" ] || [ "$SYMFONY_VERSION" = "4.3.*" ]; then rm -f phpunit.xml; cp phpunit.sf4.xml.dist phpunit.xml; fi

install: php -d memory_limit=-1 $(phpenv which composer) update --no-suggest --prefer-dist
install: COMPOSER_MEMORY_LIMIT=-1 travis_retry composer install --prefer-dist --no-interaction

script:
- if [ "$PHPCS" != "yes" ]; then vendor/bin/phpunit --coverage-text; fi
@@ -47,7 +47,7 @@ public function __construct(RouterInterface $router, DumperInterface $dumper, $d
$this->router = $router;
$this->dumper = $dumper;
$this->defaultTarget = $defaultTarget;
parent::__construct(null);
}
@@ -126,9 +126,9 @@ protected function execute(InputInterface $input, OutputInterface $output)
)
);
}
$options = array(
$options = [
'gzip' => (Boolean)$input->getOption('gzip'),
);
];
$filenames = $this->dumper->dump($targetDir, $baseUrl, $input->getOption('section'), $options);
if ($filenames === false) {

This file was deleted.

@@ -49,18 +49,6 @@ public function __construct(UrlContainerInterface $urlContainer, $section = null
$this->section = $section;
}
/**
* @deprecated in favor of `Presta\SitemapBundle\Event\SitemapPopulateEvent::getUrlContainer()`
*
* @return UrlContainerInterface
*/
public function getGenerator()
{
@trigger_error('getGenerator is deprecated since 1.5. Use getUrlContainer instead', E_USER_DEPRECATED);
return $this->urlContainer;
}
/**
* @return UrlContainerInterface
*/
@@ -113,18 +101,6 @@ public function __construct(UrlContainerInterface $urlContainer, $section = null
$this->section = $section;
}
/**
* @deprecated in favor of `Presta\SitemapBundle\Event\SitemapPopulateEvent::getUrlContainer()`
*
* @return UrlContainerInterface
*/
public function getGenerator()
{
@trigger_error('getGenerator is deprecated since 1.5. Use getUrlContainer instead', E_USER_DEPRECATED);
return $this->urlContainer;
}
/**
* @return UrlContainerInterface
*/
@@ -62,9 +62,9 @@ public function __construct(RouterInterface $router, $defaultSection)
*/
public static function getSubscribedEvents()
{
return array(
return [
SitemapPopulateEvent::ON_SITEMAP_POPULATE => ['registerRouteAnnotation', 0],
);
];
}
/**
@@ -168,7 +168,7 @@ public function getOptions($name, Route $route)
if (is_string($options['lastmod'])) {
try {
$options['lastmod'] = new \DateTime($options['lastmod']);
$options['lastmod'] = new \DateTimeImmutable($options['lastmod']);
} catch (\Exception $e) {
throw new \InvalidArgumentException(
sprintf(
@@ -221,7 +221,7 @@ protected function getUrlConcrete($name, $options)
* @return string
* @throws \InvalidArgumentException
*/
protected function getRouteUri($name, $params = array())
protected function getRouteUri($name, $params = [])
{
// If the route needs additional parameters, we can't add it
try {
@@ -12,9 +12,6 @@
namespace Presta\SitemapBundle;
use Symfony\Component\HttpKernel\Bundle\Bundle;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Compiler\PassConfig;
use Presta\SitemapBundle\DependencyInjection\Compiler\AddSitemapListenersPass;
/**
* Bundle that provides tools to render application sitemap according to
@@ -25,11 +22,4 @@
*/
class PrestaSitemapBundle extends Bundle
{
/**
* @inheritdoc
*/
public function build(ContainerBuilder $container)
{
$container->addCompilerPass(new AddSitemapListenersPass(), PassConfig::TYPE_OPTIMIZE);
}
}
@@ -39,7 +39,7 @@ abstract class AbstractGenerator implements UrlContainerInterface
/**
* @var Urlset[]
*/
protected $urlsets = array();
protected $urlsets = [];
/**
* The maximum number of item generated in a sitemap
@@ -98,7 +98,7 @@ public function addUrl(Url $url, $section)
if ($url instanceof UrlConcrete) {
if (null === $url->getLastmod() && null !== $this->defaults['lastmod']) {
$url->setLastmod(new \DateTime($this->defaults['lastmod']));
$url->setLastmod(new \DateTimeImmutable($this->defaults['lastmod']));
}
if (null === $url->getChangefreq()) {
$url->setChangefreq($this->defaults['changefreq']);
@@ -130,12 +130,12 @@ public function getUrlset($name)
/**
* Factory method for create Urlsets
*
* @param string $name
* @param \DateTime|null $lastmod
* @param string $name
* @param \DateTimeInterface|null $lastmod
*
* @return Urlset
*/
abstract protected function newUrlset($name, \DateTime $lastmod = null);
abstract protected function newUrlset($name, \DateTimeInterface $lastmod = null);
/**
* Dispatches SitemapPopulate Event - the listeners should use it to add their URLs to the sitemap
@@ -69,7 +69,7 @@ public function __construct(
/**
* @inheritdoc
*/
public function dump($targetDir, $host, $section = null, array $options = array())
public function dump($targetDir, $host, $section = null, array $options = [])
{
$options = array_merge(['gzip' => false], $options);
@@ -140,7 +140,7 @@ protected function cleanup()
{
$this->filesystem->remove($this->tmpFolder);
$this->root = null;
$this->urlsets = array();
$this->urlsets = [];
}
/**
@@ -154,10 +154,10 @@ protected function cleanup()
protected function loadCurrentSitemapIndex($filename)
{
if (!file_exists($filename)) {
return array();
return [];
}
$urlsets = array();
$urlsets = [];
$index = simplexml_load_file($filename);
foreach ($index->children() as $child) {
/** @var $child \SimpleXMLElement */
@@ -178,7 +178,7 @@ protected function loadCurrentSitemapIndex($filename)
"One of referenced sitemaps in $filename doesn't contain 'lastmod' attribute"
);
}
$lastmod = new \DateTime($child->lastmod);
$lastmod = new \DateTimeImmutable($child->lastmod);
$urlsets[$basename] = $this->newUrlset($basename, $lastmod);
}
}
@@ -208,7 +208,7 @@ protected function activate($targetDir)
$this->deleteExistingSitemaps($targetDir);
// no need to delete the root file as it always exists, it will be overwritten
$this->filesystem->mirror($this->tmpFolder, $targetDir, null, array('override' => true));
$this->filesystem->mirror($this->tmpFolder, $targetDir, null, ['override' => true]);
$this->cleanup();
}
@@ -236,7 +236,7 @@ protected function deleteExistingSitemaps($targetDir)
/**
* @inheritdoc
*/
protected function newUrlset($name, \DateTime $lastmod = null)
protected function newUrlset($name, \DateTimeInterface $lastmod = null)
{
return new DumpingUrlset($this->baseUrl . $this->sitemapFilePrefix . '.' . $name . '.xml', $lastmod);
}
@@ -28,5 +28,5 @@ interface DumperInterface extends UrlContainerInterface
*
* @return array|bool
*/
public function dump($targetDir, $host, $section = null, array $options = array());
public function dump($targetDir, $host, $section = null, array $options = []);
}
@@ -113,7 +113,7 @@ public function fetch($name)
/**
* @inheritdoc
*/
protected function newUrlset($name, \DateTime $lastmod = null)
protected function newUrlset($name, \DateTimeInterface $lastmod = null)
{
return new Urlset(
$this->router->generate(

This file was deleted.

0 comments on commit cc446c9

Please sign in to comment.
You can’t perform that action at this time.