Skip to content
This repository has been archived by the owner on Jul 28, 2022. It is now read-only.

PHPUnit with Forms #12

Open
jaimesuez opened this issue Feb 11, 2012 · 1 comment
Open

PHPUnit with Forms #12

jaimesuez opened this issue Feb 11, 2012 · 1 comment

Comments

@jaimesuez
Copy link
Contributor

I get the following error:

There was 1 error:

1) Blogger\BlogBundle\Tests\Controller\PageControllerTest::testContact
InvalidArgumentException: The form field "blogger_blogbundle_enquirytype[name]" does not exist

/Users/jaimesuez/Sites/symblog/vendor/symfony/src/Symfony/Component/DomCrawler/Form.php:358
/Users/jaimesuez/Sites/symblog/src/Blogger/BlogBundle/Tests/Controller/PageControllerTest.php:48

Issue related with this code:

<?php

public function testContact()
{
    $client = static::createClient();

    $crawler = $client->request('GET', '/contact');

    $this->assertEquals(1, $crawler->filter('h1:contains("Contact symblog")')->count());

    // Select based on button value, or id or name for buttons
    $form = $crawler->selectButton('Submit')->form();

    $form['blogger_blogbundle_enquirytype[name]']       = 'name';
    $form['blogger_blogbundle_enquirytype[email]']      = 'email@email.com';
    $form['blogger_blogbundle_enquirytype[subject]']    = 'Subject';
    $form['blogger_blogbundle_enquirytype[body]']       = 'The comment body must be at least 50 characters long as there is a validation constrain on the Enquiry entity';

    $crawler = $client->submit($form);

    $this->assertEquals(1, $crawler->filter('.blogger-notice:contains("Your contact enquiry was successfully sent. Thank you!")')->count());
}
@makusu
Copy link

makusu commented Feb 15, 2012

@jaimesuez I faced the same issue a few minutes ago and I kept wondering why.

It seems like we can just change it into this.

    $form['contact[name]']       = 'name';
    $form['contact[email]']      = 'email@email.com';
    $form['contact[subject]']    = 'Subject';
    $form['contact[body]']       = 'The comment body must be at least 50 characters long as there is a validation constrain on the Enquiry entity';

In my case, it works just fine after I changed it. I'm not sure if there's something that we should do (or missing) to make the original code working.

@dsyph3r any idea?

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

No branches or pull requests

2 participants