Skip to content

[DomCrawler] Why should I need to send an absolute URL even If I use relative ? #28629

@MatthD

Description

@MatthD

Symfony version(s) affected: 4.1

Description
I just try to do a simple functional test (checking if my form create by simony has a specific input name). The problem is I use 'relative' path but if I do not send 'absolute path' has a second argument to crawler (even if the url is totally wrong) I go an error

How to reproduce

here is the code that working with an absolute url passed (the last one /user/create)

https://gitlab.com/mobicoop/mobicoop/blob/tryFormTest/spec/Controller/UserControllerSpec.php

here is the code that does not work

    describe('/user/create', function () {
        it('User create page should return status code 200 and contains a givenName form input', function () {
            $request = $this->request->create('/user/create', 'GET');
            $response = $this->kernel->handle($request);
            
            $status = $response->getStatusCode();
            $crawler = new Crawler($response->getContent());
            $form = $crawler->filter('form')->form(); // error here
            expect($form->has('user_form[givenName]'))->toBe(true);
        });
    });

the error returned

UserController
  /user/create
    ✖ it User create page should return status code 200 and contains a givenName form input
      an uncaught exception has been thrown in `/Users/dieudonn/Dev/Coviridev2/vendor/symfony/dom-crawler/Form.php` line 47

      message:`TypeError` Code(0) with message "Argument 2 passed to Symfony\\Component\\DomCrawler\\Form::__construct() must be of the type string, null given, called in /Users/dieudonn/Dev/Coviridev2/vendor/symfony/dom-crawler/Crawler.php on line 854"

        [NA] - /Users/dieudonn/Dev/Coviridev2/vendor/symfony/dom-crawler/Form.php, line  to 47
        Symfony\Component\DomCrawler\Form::__construct() - /Users/dieudonn/Dev/Coviridev2/vendor/symfony/dom-crawler/Crawler.php, line 854
        Symfony\Component\DomCrawler\Crawler::form() - /Users/dieudonn/Dev/Coviridev2/spec/Controller/UserControllerSpec.php, line 36
        Kahlan\Filter\Filters::run() - /Users/dieudonn/Dev/Coviridev2/vendor/kahlan/kahlan/src/Suite.php, line 244
        Kahlan\Suite::runBlock() - /Users/dieudonn/Dev/Coviridev2/vendor/kahlan/kahlan/src/Block/Specification.php, line 98
        Kahlan\Block\Specification::_execute() - /Users/dieudonn/Dev/Coviridev2/vendor/kahlan/kahlan/src/Block.php, line 381
        Kahlan\Block::_process() - /Users/dieudonn/Dev/Coviridev2/vendor/kahlan/kahlan/src/Block.php, line 208
        Kahlan\Block::process() - /Users/dieudonn/Dev/Coviridev2/vendor/kahlan/kahlan/src/Block/Group.php, line 179
        Kahlan\Block\Group::_execute() - /Users/dieudonn/Dev/Coviridev2/vendor/kahlan/kahlan/src/Block.php, line 381
        Kahlan\Block::_process() - /Users/dieudonn/Dev/Coviridev2/vendor/kahlan/kahlan/src/Block.php, line 208
        Kahlan\Block::process() - /Users/dieudonn/Dev/Coviridev2/vendor/kahlan/kahlan/src/Block/Group.php, line 179
        Kahlan\Block\Group::_execute() - /Users/dieudonn/Dev/Coviridev2/vendor/kahlan/kahlan/src/Block.php, line 381
        Kahlan\Block::_process() - /Users/dieudonn/Dev/Coviridev2/vendor/kahlan/kahlan/src/Block.php, line 208
        Kahlan\Block::process() - /Users/dieudonn/Dev/Coviridev2/vendor/kahlan/kahlan/src/Block/Group.php, line 179
        Kahlan\Block\Group::_execute() - /Users/dieudonn/Dev/Coviridev2/vendor/kahlan/kahlan/src/Block.php, line 381
        Kahlan\Block::_process() - /Users/dieudonn/Dev/Coviridev2/vendor/kahlan/kahlan/src/Block.php, line 208
        Kahlan\Block::process() - /Users/dieudonn/Dev/Coviridev2/vendor/kahlan/kahlan/src/Suite.php, line 221
        Kahlan\Suite::run() - /Users/dieudonn/Dev/Coviridev2/vendor/kahlan/kahlan/src/Cli/Kahlan.php, line 576
        Kahlan\Filter\Filters::run() - /Users/dieudonn/Dev/Coviridev2/vendor/kahlan/kahlan/src/Cli/Kahlan.php, line 578
        Kahlan\Cli\Kahlan::_run() - /Users/dieudonn/Dev/Coviridev2/vendor/kahlan/kahlan/src/Cli/Kahlan.php, line 379
        Kahlan\Filter\Filters::run() - /Users/dieudonn/Dev/Coviridev2/vendor/kahlan/kahlan/src/Cli/Kahlan.php, line 386
        Kahlan\Cli\Kahlan::run() - /Users/dieudonn/Dev/Coviridev2/vendor/kahlan/kahlan/bin/kahlan, line 69

Additional context
I use Kahlan for test

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      pFad - Phonifier reborn

      Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

      Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


      Alternative Proxies:

      Alternative Proxy

      pFad Proxy

      pFad v3 Proxy

      pFad v4 Proxy