From e797d33b8f69f7b40f17d2023bb38e12aab362a6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Yann=20Eugon=C3=A9?= Date: Mon, 7 Aug 2017 10:18:59 +0200 Subject: [PATCH] Updated Travis testing matrix (#145) * Updated Travis testing matrix * Fixing Travis build * Fixing Travis build * Fixed risky tests * Removed HHVM in favor of PHP 7.1 * Removed unecessary bundles in test app * Adde security config to test app to avoid deprecations * Do not get router.request_context service directly to avoid deprecations * Fixed PhpUnit and Symfony4 deprecations --- .gitignore | 1 + .travis.yml | 15 +++++++----- Command/DumpSitemapsCommand.php | 2 +- Tests/Controller/SitemapControllerTest.php | 27 ++++++++++++++-------- Tests/Service/GeneratorTest.php | 2 ++ Tests/app/AppKernel.php | 2 -- Tests/app/config.yml | 11 +++++++++ Tests/fixtures/sitemap.video.xml | 20 ++++++++-------- composer.json | 8 ++++++- phpunit.sf4.xml.dist | 22 ++++++++++++++++++ 10 files changed, 81 insertions(+), 29 deletions(-) create mode 100644 phpunit.sf4.xml.dist diff --git a/.gitignore b/.gitignore index 15c413f2..7ea72ea6 100644 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,6 @@ *~ Tests/app/cache/ composer.lock +phpunit.xml vendor/ Tests/web diff --git a/.travis.yml b/.travis.yml index 18629fb4..84983bff 100644 --- a/.travis.yml +++ b/.travis.yml @@ -3,7 +3,7 @@ language: php php: - 5.6 - 7.0 - - hhvm + - 7.1 matrix: include: @@ -15,12 +15,14 @@ matrix: env: SYMFONY_VERSION=2.8.* SYMFONY_DEPRECATIONS_HELPER=strict - php: 5.6 env: SYMFONY_VERSION=3.0.* SYMFONY_DEPRECATIONS_HELPER=strict - - php: 5.6 - env: SYMFONY_VERSION=3.2.*@dev SYMFONY_DEPRECATIONS_HELPER=strict - php: 7.0 - env: PHPCS=yes + env: SYMFONY_VERSION=3.2.* SYMFONY_DEPRECATIONS_HELPER=strict + - php: 7.1 + env: SYMFONY_VERSION=3.3.* SYMFONY_DEPRECATIONS_HELPER=strict + - php: 7.1 + env: SYMFONY_VERSION=3.4.*@dev SYMFONY_DEPRECATIONS_HELPER=strict allow_failures: - - env: SYMFONY_VERSION=3.2.*@dev + - env: SYMFONY_VERSION=3.4.*@dev env: global: @@ -36,7 +38,8 @@ before_install: - if [ "$PHPCS" = "yes" ]; then pear install pear/PHP_CodeSniffer; fi - if [ "$PHPCS" = "yes" ]; then phpenv rehash; fi - if [ "$PHPCS" != "yes"]; then composer selfupdate; fi - - if [ "$SYMFONY_VERSION" = "3.2.*@dev" ]; then composer require --no-update twig/twig:~2.0@dev; fi + - if [ "$SYMFONY_VERSION" = "3.4.*@dev" ]; then rm -f phpunit.xml; cp phpunit.sf4.xml.dist phpunit.xml; fi + - if [ "$SYMFONY_VERSION" = "3.2.*" ] || [ "$SYMFONY_VERSION" = "3.3.*" ] || [ "$SYMFONY_VERSION" = "3.4.*@dev" ]; then composer require --no-update twig/twig:~2.0; fi - if [ "$SYMFONY_VERSION" != "" ]; then composer require --no-update symfony/symfony:${SYMFONY_VERSION}; fi install: if [ "$PHPCS" != "yes" ]; then composer update --prefer-dist; fi diff --git a/Command/DumpSitemapsCommand.php b/Command/DumpSitemapsCommand.php index 48cfb403..d030124d 100644 --- a/Command/DumpSitemapsCommand.php +++ b/Command/DumpSitemapsCommand.php @@ -128,7 +128,7 @@ protected function execute(InputInterface $input, OutputInterface $output) */ private function getBaseUrl() { - $context = $this->getContainer()->get('router.request_context'); + $context = $this->getContainer()->get('router')->getContext(); if ('' === $host = $context->getHost()) { throw new \RuntimeException( diff --git a/Tests/Controller/SitemapControllerTest.php b/Tests/Controller/SitemapControllerTest.php index 153394f9..87fa2242 100644 --- a/Tests/Controller/SitemapControllerTest.php +++ b/Tests/Controller/SitemapControllerTest.php @@ -16,9 +16,20 @@ use Presta\SitemapBundle\Service\Generator; use Presta\SitemapBundle\Sitemap\Url; use Symfony\Bundle\FrameworkBundle\Test\WebTestCase; +use Symfony\Component\DependencyInjection\ContainerInterface; class SitemapControllerTest extends WebTestCase { + /** + * @var Controller\SitemapController + */ + private $controller; + + /** + * @var ContainerInterface + */ + private $container; + public function setUp() { //boot appKernel @@ -51,23 +62,21 @@ function (SitemapPopulateEvent $event) { public function testIndexAction() { - $response = $this->controller->indexAction(); - $this->isInstanceOf('Symfony\Component\HttpFoundation\Response', $response); + $response = $this->controller->indexAction(); + $this->assertInstanceOf('Symfony\Component\HttpFoundation\Response', $response); } public function testValidSectionAction() { $response = $this->controller->sectionAction('default'); - $this->isInstanceOf('Symfony\Component\HttpFoundation\Response', $response); + $this->assertInstanceOf('Symfony\Component\HttpFoundation\Response', $response); } + /** + * @expectedException \Symfony\Component\HttpKernel\Exception\NotFoundHttpException + */ public function testNotFoundSectionAction() { - try { - $this->controller->sectionAction('void'); - $this->fail('section "void" does\'nt exist'); - } catch (\Symfony\Component\HttpKernel\Exception\NotFoundHttpException $e) { - //this is ok - } + $this->controller->sectionAction('void'); } } diff --git a/Tests/Service/GeneratorTest.php b/Tests/Service/GeneratorTest.php index ee963f4d..a3e03332 100644 --- a/Tests/Service/GeneratorTest.php +++ b/Tests/Service/GeneratorTest.php @@ -34,6 +34,7 @@ public function testGenerate() { try { $this->generator->generate(); + $this->assertTrue(true, 'No exception was thrown'); } catch (\RuntimeException $e) { $this->fail('No exception must be thrown'); } @@ -49,6 +50,7 @@ public function testAddUrl() { try { $this->generator->addUrl(new Sitemap\Url\UrlConcrete('http://acme.com/'), 'default'); + $this->assertTrue(true, 'No exception was thrown'); } catch (\RuntimeException $e) { $this->fail('No exception must be thrown'); } diff --git a/Tests/app/AppKernel.php b/Tests/app/AppKernel.php index c5f451d7..3bb3e5f6 100644 --- a/Tests/app/AppKernel.php +++ b/Tests/app/AppKernel.php @@ -20,8 +20,6 @@ public function registerBundles() // Dependencies new Symfony\Bundle\FrameworkBundle\FrameworkBundle(), new Symfony\Bundle\SecurityBundle\SecurityBundle(), - //new Sensio\Bundle\FrameworkExtraBundle\SensioFrameworkExtraBundle(), - //new JMS\SerializerBundle\JMSSerializerBundle($this), new Presta\SitemapBundle\PrestaSitemapBundle(), ); diff --git a/Tests/app/config.yml b/Tests/app/config.yml index b2d85960..d90ee70e 100644 --- a/Tests/app/config.yml +++ b/Tests/app/config.yml @@ -7,3 +7,14 @@ framework: validation: { enable_annotations: true } session: storage_id: session.storage.filesystem + +security: + providers: + in_memory: + memory: ~ + firewalls: + dev: + pattern: ^/(_(profiler|wdt)|css|images|js)/ + security: false + main: + anonymous: ~ diff --git a/Tests/fixtures/sitemap.video.xml b/Tests/fixtures/sitemap.video.xml index 9240f75f..d923e55e 100644 --- a/Tests/fixtures/sitemap.video.xml +++ b/Tests/fixtures/sitemap.video.xml @@ -1,14 +1,14 @@ - - http://sitemap.php54.local/page_video1/ - - http://sitemap.php54.local/page_video1/thumbnail_loc?a=b&b=c - - - http://sitemap.php54.local/page_video1/content?format=mov&a=b - http://sitemap.php54.local/page_video1/gallery_loc/?p=1&sort=desc - - + + http://sitemap.php54.local/page_video1/ + + http://sitemap.php54.local/page_video1/thumbnail_loc?a=b&b=c + + + http://sitemap.php54.local/page_video1/content?format=mov&a=b + http://sitemap.php54.local/page_video1/gallery_loc/?p=1&sort=desc + + diff --git a/composer.json b/composer.json index a45545f0..d166db44 100644 --- a/composer.json +++ b/composer.json @@ -24,7 +24,8 @@ "symfony/symfony": "~2.2|~3.0" }, "require-dev": { - "symfony/phpunit-bridge": "~2.7|~3.0" + "symfony/phpunit-bridge": "~2.7|~3.0", + "phpunit/phpunit": "4.*" }, "suggest": { "doctrine/doctrine-cache-bundle" : "Allows to store sitemaps in cache" @@ -34,6 +35,11 @@ "Presta\\SitemapBundle\\": "" } }, + "autoload-dev": { + "files": [ + "Tests/app/AppKernel.php" + ] + }, "extra": { "branch-alias": { "dev-master": "1.5.x-dev" diff --git a/phpunit.sf4.xml.dist b/phpunit.sf4.xml.dist new file mode 100644 index 00000000..f8914b69 --- /dev/null +++ b/phpunit.sf4.xml.dist @@ -0,0 +1,22 @@ + + + + + + + + ./Tests + + + + + ./ + + ./Resources + ./Tests + ./vendor + + + + +