Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

getUrl method return path prefixed by app_dev.php #335

Open
soullivaneuh opened this issue Oct 24, 2017 · 1 comment
Open

getUrl method return path prefixed by app_dev.php #335

soullivaneuh opened this issue Oct 24, 2017 · 1 comment

Comments

@soullivaneuh
Copy link
Contributor

soullivaneuh commented Oct 24, 2017

On a simple web test case like this one:

namespace Tests\AppBundle\Controller;

use Liip\FunctionalTestBundle\Test\WebTestCase;

final class DefaultControllerTest extends WebTestCase
{
    public function testIndex(): void
    {
        $this->assertContains(
            'This is an awesome website',
            $this->fetchContent($this->getUrl('homepage'))
        );
    }

    public function testTerms(): void
    {
        $this->assertContains(
            'Terms of Service',
            $this->fetchContent($this->getUrl('terms'))
        );
    }
}

$this->getUrl() return the path prefixed by app_dev.php, making the test failing:

sullivan@3c0fcd0ca9ed:/code$ phpunit tests/AppBundle/Controller/DefaultControllerTest.php 

 // Clearing the cache for the test environment with debug true                                                         

 [OK] Cache for the "test" environment (debug=true) was successfully cleared.                                           

PHPUnit 6.3.1 by Sebastian Bergmann and contributors.

FF                                                                  2 / 2 (100%)

Time: 3.75 seconds, Memory: 119.41MB

There were 2 failures:

1) Tests\AppBundle\Controller\DefaultControllerTest::testIndex
The Response was not successful:     No route found for "GET /app_dev.php/" (404 Not Found)

Failed asserting that false is true.

/code/vendor/liip/functional-test-bundle/Utils/HttpAssertions.php:45
/code/vendor/liip/functional-test-bundle/Test/WebTestCase.php:858
/code/vendor/liip/functional-test-bundle/Test/WebTestCase.php:880
/code/tests/AppBundle/Controller/DefaultControllerTest.php:18

2) Tests\AppBundle\Controller\DefaultControllerTest::testTerms
The Response was not successful:     No route found for "GET /app_dev.php/terms" (404 Not Found)

Failed asserting that false is true.

/code/vendor/liip/functional-test-bundle/Utils/HttpAssertions.php:45
/code/vendor/liip/functional-test-bundle/Test/WebTestCase.php:858
/code/vendor/liip/functional-test-bundle/Test/WebTestCase.php:880
/code/tests/AppBundle/Controller/DefaultControllerTest.php:26

FAILURES!
Tests: 2, Assertions: 2, Failures: 2.

Remaining vendor deprecation notices (11)

The path should be returned without app_dev.php AFAIK. Origin Symfony web test case does not use this prefix for client calls.

config_test.yml file:

imports:
  - { resource: config_dev.yml }

framework:
  test: ~
  session:
    storage_id: session.storage.mock_file
  profiler:
    collect: false

web_profiler:
  toolbar: false
  intercept_redirects: false

swiftmailer:
  disable_delivery: true

liip_functional_test: ~

phpunit.xml.dist configuration file (no override):

<?xml version="1.0" encoding="UTF-8"?>

<!-- https://phpunit.de/manual/current/en/appendixes.configuration.html -->
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:noNamespaceSchemaLocation="http://schema.phpunit.de/4.8/phpunit.xsd"
         backupGlobals="false"
         colors="true"
         bootstrap="app/tests.bootstrap.php"
>
    <php>
        <ini name="error_reporting" value="-1" />
        <env name="SYMFONY_DEPRECATIONS_HELPER" value="weak_vendors" />
        <server name="KERNEL_CLASS" value="AppKernel" />
    </php>

    <listeners>
        <listener class="\DAMA\DoctrineTestBundle\PHPUnit\PHPUnitListener" />
    </listeners>

    <testsuites>
        <testsuite name="Project Test Suite">
            <directory>tests</directory>
        </testsuite>
    </testsuites>

    <filter>
        <whitelist>
            <directory>src</directory>
        </whitelist>
    </filter>
</phpunit>

Composer state:

sullivan@3c0fcd0ca9ed:/code$ composer show
amphp/amp                                      v2.0.2             A non-blocking concurrency framework for PHP applications.
amphp/byte-stream                              v1.1.6             A stream abstraction to make working with non-blocking I/O simple.
amphp/parallel                                 v0.1.8             Parallel processing component for Amp.
amphp/parser                                   v1.0.0             A generator parser to make streaming parsers simple.
amphp/process                                  v0.2.1             Asynchronous process manager
behat/transliterator                           v1.2.0             String transliterator
clue/stream-filter                             v1.4.0             A simple and modern approach to stream filtering in PHP
composer/ca-bundle                             1.0.8              Lets you find a path to the system CA bundle, and includes a fallback to the Mozilla CA bundle.
cpliakas/git-wrapper                           1.7.0              A PHP wrapper around the Git command line utility.
dama/doctrine-test-bundle                      v4.0.1             Symfony 2/3 bundle to isolate doctrine database tests and improve test performance
docker-php/docker-php                          1.24.0             A Docker PHP client
doctrine/annotations                           v1.5.0             Docblock Annotations Parser
doctrine/cache                                 v1.7.1             Caching library offering an object-oriented API for many cache backends
doctrine/collections                           v1.5.0             Collections Abstraction library
doctrine/common                                v2.8.1             Common Library for Doctrine projects
doctrine/dbal                                  v2.6.2             Database Abstraction Layer
doctrine/doctrine-bundle                       1.7.1              Symfony DoctrineBundle
doctrine/doctrine-cache-bundle                 1.3.2              Symfony Bundle for Doctrine Cache
doctrine/doctrine-migrations-bundle            v1.2.1             Symfony DoctrineMigrationsBundle
doctrine/inflector                             v1.2.0             Common String Manipulations with regard to casing and singular/plural rules.
doctrine/instantiator                          1.1.0              A small, lightweight utility to instantiate objects in PHP without invoking their constructors
doctrine/lexer                                 v1.0.1             Base library for a lexer that can be used in Top-Down, Recursive Descent Parsers.
doctrine/migrations                            v1.5.0             Database Schema migrations using Doctrine DBAL
doctrine/orm                                   v2.5.11            Object-Relational-Mapper for PHP
egulias/email-validator                        2.1.2              A library for validating emails against several RFCs
fig/link-util                                  1.0.0              Common utility implementations for HTTP links
fitbug/symfony-yaml-serializer-encoder-decoder v0.1.1             A encoder and decoder for Yaml for the Symfony Serializer Component.
friendsofsymfony/user-bundle                   v2.0.1             Symfony FOSUserBundle
greg0ire/enum                                  v3.5.2             work around the missing enum type in php
guzzlehttp/guzzle                              6.3.0              Guzzle is a PHP HTTP client library
guzzlehttp/promises                            v1.3.1             Guzzle promises library
guzzlehttp/psr7                                1.4.2              PSR-7 message implementation that also provides common utility methods
hwi/oauth-bundle                               dev-master bbf26fe Support for authenticating users using both OAuth1.0a and OAuth2 in Symfony2.
incenteev/composer-parameter-handler           v2.1.2             Composer script handling your ignored parameter file
jane/jane                                      v1.5.1             Generate a serializable / deserializable object model given a json schema
jane/open-api                                  v1.3.0             Generate a PHP Client API (PSR7 compatible) given a OpenApi (Swagger) specification
jane/openapi-runtime                           v1.0.0             Jane OpenAPI Runtime Library, dependencies and utility class for a library generated by jane/openapi
jane/runtime                                   v1.0.0             Jane runtime Library
javiereguiluz/easyadmin-bundle                 v1.17.5            Admin generator for Symfony applications
jdorn/sql-formatter                            v1.2.17            a PHP SQL highlighting library
knplabs/doctrine-behaviors                     1.5.0              Doctrine2 behavior traits
knplabs/github-api                             2.6.0              GitHub API v3 client
knplabs/knp-markdown-bundle                    1.5.1              Knplabs markdown bundle transforms markdown into html
liip/functional-test-bundle                    1.8.0              This bundles provides additional functional test-cases for Symfony2 applications
m4tthumphrey/php-gitlab-api                    9.5.0              GitLab API client
matthiasnoback/symfony-config-test             v3.0.1             Library for testing user classes related to the Symfony Config Component
michelf/php-markdown                           1.7.0              PHP Markdown
monolog/monolog                                1.23.0             Sends your logs to files, sockets, inboxes, databases and various web services
nikic/php-parser                               v2.1.1             A PHP parser written in PHP
ocramius/package-versions                      1.1.3              Composer plugin that provides efficient querying for installed package versions (no runtime IO)
ocramius/proxy-manager                         2.1.1              A library providing utilities to generate, instantiate and generally operate with Object Proxies
pagerfanta/pagerfanta                          v1.0.5             Pagination for PHP 5.3
paragonie/random_compat                        v2.0.11            PHP 5.x polyfill for random_bytes() and random_int() from PHP 7
php-amqplib/php-amqplib                        v2.7.0             Formerly videlalvaro/php-amqplib.  This library is a pure PHP implementation of the AMQP protocol. It's been tested against RabbitMQ.
php-amqplib/rabbitmq-bundle                    v1.13.0            Integrates php-amqplib with Symfony & RabbitMq. Formerly oldsound/rabbitmq-bundle.
php-http/cache-plugin                          v1.4.0             PSR-6 Cache plugin for HTTPlug
php-http/client-common                         v1.6.0             Common HTTP Client implementations and tools for HTTPlug
php-http/discovery                             1.3.0              Finds installed HTTPlug implementations and PSR-7 message factories
php-http/guzzle6-adapter                       v1.1.1             Guzzle 6 HTTP Adapter
php-http/httplug                               v1.1.0             HTTPlug, the HTTP client abstraction for PHP
php-http/httplug-bundle                        v1.7.1             Symfony integration for HTTPlug
php-http/logger-plugin                         v1.0.0             PSR-3 Logger plugin for HTTPlug
php-http/message                               1.6.0              HTTP Message related tools
php-http/message-factory                       v1.0.2             Factory interfaces for PSR-7 HTTP Message
php-http/mock-client                           v1.0.1             Mock HTTP client
php-http/multipart-stream-builder              1.0.0              A builder class that help you create a multipart stream
php-http/promise                               v1.0.0             Promise used for asynchronous HTTP requests
php-http/socket-client                         v1.3.0             Socket client for PHP-HTTP
php-http/stopwatch-plugin                      1.0.1              Symfony Stopwatch plugin for HTTPlug
phpseclib/phpseclib                            2.0.6              PHP Secure Communications Library - Pure-PHP implementations of RSA, AES, SSH2, SFTP, X.509 etc.
psr/cache                                      1.0.1              Common interface for caching libraries
psr/container                                  1.0.0              Common Container Interface (PHP FIG PSR-11)
psr/http-message                               1.0.1              Common interface for HTTP messages
psr/link                                       1.0.0              Common interfaces for HTTP links
psr/log                                        1.0.2              Common interface for logging libraries
psr/simple-cache                               1.0.0              Common interfaces for simple caching
sebastian/diff                                 2.0.1              Diff implementation
sensio/distribution-bundle                     v5.0.21            Base bundle for Symfony Distributions
sensio/framework-extra-bundle                  v5.0.1             This bundle provides a way to configure your controllers with annotations
sensio/generator-bundle                        v3.1.6             This bundle generates code for you
sensiolabs/security-checker                    v4.1.5             A security checker for your composer.lock
sllh/doctrine-dbal-utc-datetime                v1.0.0             UTC DateTime type for Doctrine DBAL
sonata-project/intl-bundle                     2.3.2              Symfony SonataIntlBundle
swiftmailer/swiftmailer                        v6.0.2             Swiftmailer, free feature-rich PHP mailer
symfony/monolog-bundle                         v3.1.1             Symfony MonologBundle
symfony/phpunit-bridge                         v3.3.10            Symfony PHPUnit Bridge
symfony/polyfill-apcu                          v1.6.0             Symfony polyfill backporting apcu_* functions to lower PHP versions
symfony/polyfill-intl-icu                      v1.6.0             Symfony polyfill for intl's ICU-related data and classes
symfony/polyfill-mbstring                      v1.6.0             Symfony polyfill for the Mbstring extension
symfony/polyfill-php56                         v1.6.0             Symfony polyfill backporting some PHP 5.6+ features to lower PHP versions
symfony/polyfill-php70                         v1.6.0             Symfony polyfill backporting some PHP 7.0+ features to lower PHP versions
symfony/polyfill-util                          v1.6.0             Symfony utilities for portability of PHP codes
symfony/swiftmailer-bundle                     v3.1.5             Symfony SwiftmailerBundle
symfony/symfony                                v3.4.0-BETA1       The Symfony PHP framework
twig/extensions                                v1.5.1             Common additional features for Twig that do not directly belong in core
twig/twig                                      v2.4.4             Twig, the flexible, fast, and secure template language for PHP
webmozart/assert                               1.2.0              Assertions to validate method input/output with nice error messages.
zendframework/zend-code                        3.3.0              provides facilities to generate arbitrary code using an object oriented interface
zendframework/zend-eventmanager                3.2.0              Trigger and listen to events within a PHP application

Tell me if you need more information.

@soullivaneuh
Copy link
Contributor Author

soullivaneuh commented Oct 24, 2017

I figured out the issue: I have some request override on parameters.yml:

parameters:
    router.request_context.host: 'localhost:8000'
    router.request_context.scheme: http
    router.request_context.base_url: /app_dev.php

This has to be overridden on config_test.yml:

parameters:
  router.request_context.base_url: ~

This are needed for offline URL generation like from commands and I don't think I'm the only one doing that.

It may be useful to add a tip to prevent people running into this issue.

I let this issue open, feel free to close it if you don't think it worth it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant