IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

Symfony PHP Discussion :

[Tests] Problème de baseUrl


Sujet :

Symfony PHP

  1. #1
    Membre du Club
    Homme Profil pro
    Directeur adjoint en restauration
    Inscrit en
    Mai 2005
    Messages
    51
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 53
    Localisation : France, Morbihan (Bretagne)

    Informations professionnelles :
    Activité : Directeur adjoint en restauration
    Secteur : Tourisme - Loisirs

    Informations forums :
    Inscription : Mai 2005
    Messages : 51
    Points : 57
    Points
    57
    Par défaut [Tests] Problème de baseUrl
    Bonsoir le Forum,

    J'ai générez certains Controller via PUGXGeneratorBundle, et souhaite profiter des tests intégrés pour le suivi de mon développement.

    Le problème, c'est que lorsque je lance les tests, j'ai plein d'erreurs (InvalidArgumentException: The current node list is empty.).

    A force de recherche, je constate que le code :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
     
    <?php
    namespace AppBundle\Controller;
     
    use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;
     
    class ArticleControllerTest extends WebTestCase
    {
        public function testCreate()
        {
            $client = static::createClient();
            $crawler = $client->request('GET', '/article');
            var_dump($client->getRequest()->getBasePath());
            .../...
        }
    }
    le var_dump() renvoit
    string(0) ""
    Alors que lorsque je le passe le var_dump() dans ArticleController,
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
     
        public function indexAction(Request $request)
        {
            var_dump($request->getBasePath());
            .../...
        }
    j'ai
    string '/Symfony-2/web' (length=14)
    .

    Je ne vois pas où peut-être mon erreur.

  2. #2
    Membre éprouvé
    Homme Profil pro
    Développeur Web
    Inscrit en
    Novembre 2013
    Messages
    739
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Tunisie

    Informations professionnelles :
    Activité : Développeur Web

    Informations forums :
    Inscription : Novembre 2013
    Messages : 739
    Points : 1 022
    Points
    1 022
    Par défaut
    J'imagine que request dans le code de test est null ou inconnu.
    Je propose ces modifications :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
     
    use Symfony\Component\HttpFoundation\Request;
    //
    public function testCreate(Request $request)
    //
    $request = $this->get('request_stack')->getCurrentRequest();

  3. #3
    Membre du Club
    Homme Profil pro
    Directeur adjoint en restauration
    Inscrit en
    Mai 2005
    Messages
    51
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 53
    Localisation : France, Morbihan (Bretagne)

    Informations professionnelles :
    Activité : Directeur adjoint en restauration
    Secteur : Tourisme - Loisirs

    Informations forums :
    Inscription : Mai 2005
    Messages : 51
    Points : 57
    Points
    57
    Par défaut
    Encore raté...

    Retour de ta proposition :
    There were 2 errors:

    1) AppBundle\Controller\ArticleControllerTest::testCreate
    Argument 1 passed to AppBundle\Controller\ArticleControllerTest::testCreate() must be an instance of Symfony\Component\HttpFoundation\Request, none given
    Pour info, le retour du var_dump($client) :
    G:\wamp\www\Symfony-2\src\AppBundle\Tests\Controller\ArticleControllerTest.php:14:
    class Symfony\Bundle\FrameworkBundle\Client#802 (18) {
    private $hasPerformedRequest =>
    bool(true)
    private $profiler =>
    bool(false)
    private $reboot =>
    bool(true)
    protected $kernel =>
    class AppKernel#33 (10) {
    protected $bundles =>
    array(26) {
    ...
    }
    protected $bundleMap =>
    array(26) {
    ...
    }
    protected $container =>
    class appTestDebugProjectContainer#805 (12) {
    private $parameters =>
    array(699) {
    ...
    }
    private $targetDirs =>
    array(4) {
    ...
    }
    protected $parameterBag =>
    NULL
    protected $services =>
    array(92) {
    ...
    }
    protected $methodMap =>
    array(317) {
    ...
    }
    protected $aliases =>
    array(17) {
    ...
    }
    protected $scopes =>
    array(1) {
    ...
    }
    protected $scopeChildren =>
    array(1) {
    ...
    }
    protected $scopedServices =>
    array(0) {
    ...
    }
    protected $scopeStacks =>
    array(0) {
    ...
    }
    protected $loading =>
    array(0) {
    ...
    }
    private $underscoreMap =>
    array(3) {
    ...
    }
    }
    protected $rootDir =>
    string(25) "G:\wamp\www\Symfony-2\app"
    protected $environment =>
    string(4) "test"
    protected $debug =>
    bool(true)
    protected $booted =>
    bool(true)
    protected $name =>
    string(3) "app"
    protected $startTime =>
    double(1465328014.7323)
    protected $loadClassCache =>
    NULL
    }
    protected $history =>
    class Symfony\Component\BrowserKit\History#801 (2) {
    protected $stack =>
    array(1) {
    [0] =>
    class Symfony\Component\BrowserKit\Request#790 (7) {
    ...
    }
    }
    protected $position =>
    int(0)
    }
    protected $cookieJar =>
    class Symfony\Component\BrowserKit\CookieJar#800 (1) {
    protected $cookieJar =>
    array(0) {
    }
    }
    protected $server =>
    array(1) {
    'HTTP_USER_AGENT' =>
    string(19) "Symfony2 BrowserKit"
    }
    protected $internalRequest =>
    class Symfony\Component\BrowserKit\Request#799 (7) {
    protected $uri =>
    string(24) "http://localhost/article"
    protected $method =>
    string(3) "GET"
    protected $parameters =>
    array(0) {
    }
    protected $files =>
    array(0) {
    }
    protected $cookies =>
    array(0) {
    }
    protected $server =>
    array(3) {
    'HTTP_USER_AGENT' =>
    string(19) "Symfony2 BrowserKit"
    'HTTP_HOST' =>
    string(9) "localhost"
    'HTTPS' =>
    bool(false)
    }
    protected $content =>
    NULL
    }
    protected $request =>
    class Symfony\Component\HttpFoundation\Request#798 (21) {
    public $attributes =>
    class Symfony\Component\HttpFoundation\ParameterBag#795 (1) {
    protected $parameters =>
    array(8) {
    ...
    }
    }
    public $request =>
    class Symfony\Component\HttpFoundation\ParameterBag#797 (1) {
    protected $parameters =>
    array(0) {
    ...
    }
    }
    public $query =>
    class Symfony\Component\HttpFoundation\ParameterBag#796 (1) {
    protected $parameters =>
    array(0) {
    ...
    }
    }
    public $server =>
    class Symfony\Component\HttpFoundation\ServerBag#792 (1) {
    protected $parameters =>
    array(16) {
    ...
    }
    }
    public $files =>
    class Symfony\Component\HttpFoundation\FileBag#793 (1) {
    protected $parameters =>
    array(0) {
    ...
    }
    }
    public $cookies =>
    class Symfony\Component\HttpFoundation\ParameterBag#794 (1) {
    protected $parameters =>
    array(0) {
    ...
    }
    }
    public $headers =>
    class Symfony\Component\HttpFoundation\HeaderBag#791 (2) {
    protected $headers =>
    array(6) {
    ...
    }
    protected $cacheControl =>
    array(0) {
    ...
    }
    }
    protected $content =>
    NULL
    protected $languages =>
    NULL
    protected $charsets =>
    NULL
    protected $encodings =>
    NULL
    protected $acceptableContentTypes =>
    NULL
    protected $pathInfo =>
    string(8) "/article"
    protected $requestUri =>
    string(8) "/article"
    protected $baseUrl =>
    string(0) ""
    protected $basePath =>
    NULL
    protected $method =>
    string(3) "GET"
    protected $format =>
    string(4) "html"
    protected $session =>
    class Symfony\Component\HttpFoundation\Session\Session#691 (3) {
    protected $storage =>
    class Symfony\Component\HttpFoundation\Session\Storage\MockFileSessionStorage#690 (8) {
    ...
    }
    private $flashName =>
    string(7) "flashes"
    private $attributeName =>
    string(10) "attributes"
    }
    protected $locale =>
    NULL
    protected $defaultLocale =>
    string(2) "fr"
    }
    protected $internalResponse =>
    class Symfony\Component\BrowserKit\Response#447 (3) {
    protected $content =>
    string(344) "<!DOCTYPE html>
    <html>
    <head>
    <meta charset="UTF-8" />
    <meta http-equiv="refresh" content="1;url=http://localhost/article/" />

    <title>Redirecting to http://localhost/article/</title>
    </head>
    <body>
    Redirecting to <a href="http://localhost/article/">http://localhost/article/</a>.
    </body>
    </html>"
    protected $status =>
    int(301)
    protected $headers =>
    array(4) {
    'cache-control' =>
    array(1) {
    ...
    }
    'date' =>
    array(1) {
    ...
    }
    'location' =>
    array(1) {
    ...
    }
    'content-type' =>
    array(1) {
    ...
    }
    }
    }
    protected $response =>
    class Symfony\Component\HttpFoundation\RedirectResponse#380 (7) {
    protected $targetUrl =>
    string(25) "http://localhost/article/"
    public $headers =>
    class Symfony\Component\HttpFoundation\ResponseHeaderBag#381 (5) {
    protected $computedCacheControl =>
    array(1) {
    ...
    }
    protected $cookies =>
    array(0) {
    ...
    }
    protected $headerNames =>
    array(4) {
    ...
    }
    protected $headers =>
    array(4) {
    ...
    }
    protected $cacheControl =>
    array(0) {
    ...
    }
    }
    protected $content =>
    string(344) "<!DOCTYPE html>
    <html>
    <head>
    <meta charset="UTF-8" />
    <meta http-equiv="refresh" content="1;url=http://localhost/article/" />

    <title>Redirecting to http://localhost/article/</title>
    </head>
    <body>
    Redirecting to <a href="http://localhost/article/">http://localhost/article/</a>.
    </body>
    </html>"
    protected $version =>
    string(3) "1.1"
    protected $statusCode =>
    int(301)
    protected $statusText =>
    string(17) "Moved Permanently"
    protected $charset =>
    string(5) "UTF-8"
    }
    protected $crawler =>
    class Symfony\Component\DomCrawler\Crawler#312 (5) {
    protected $uri =>
    string(24) "http://localhost/article"
    private $defaultNamespacePrefix =>
    string(7) "default"
    private $namespaces =>
    array(0) {
    }
    private $baseHref =>
    string(24) "http://localhost/article"
    private $storage =>
    array(1) {
    '000000000b17635d0000000001e0de64' =>
    array(2) {
    ...
    }
    }
    }
    protected $insulated =>
    bool(false)
    protected $redirect =>
    string(25) "http://localhost/article/"
    protected $followRedirects =>
    bool(false)
    private $maxRedirects =>
    int(-1)
    private $redirectCount =>
    int(0)
    private $isMainRequest =>
    bool(true)
    }
    Si cela peut donner des pistes...

Discussions similaires

  1. Premier code de test, problème de console
    Par Frank1010 dans le forum x86 16-bits
    Réponses: 1
    Dernier message: 26/07/2011, 18h41
  2. Réponses: 3
    Dernier message: 09/04/2008, 12h18
  3. Problème font / depth test .
    Par Clad3 dans le forum OpenGL
    Réponses: 1
    Dernier message: 25/06/2005, 16h02
  4. Réponses: 4
    Dernier message: 16/06/2005, 15h37
  5. Problème avec un test
    Par nebule dans le forum Général JavaScript
    Réponses: 5
    Dernier message: 25/10/2004, 11h54

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo