Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8164519
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T19:20:06+00:00 2026-06-06T19:20:06+00:00

I have a test suite for phpunit for my symfony application. In that test

  • 0

I have a test suite for phpunit for my symfony application. In that test file, I have some dependencies between different tests, and pass a DOMCrawler object between the dependent so that I don’t have to navigate to it each time.

However, in taking the approach that I did, It seems that you cannot submit forms with these passed objects, but you can click on the links on them. Is there a reason for this? Is my design just poor and if so, how should I change it? Any feedback is welcome. I’ve attached some code below.

<?php

namespace someBundle\Tests\Controller;

use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;

/**
 * blah Controller Test
 * 
 */
class BlahControllerTest extends WebTestCase
{

    private $adminUrl;

    /**
     * Constructs basic information for a audit report controller test suite
     *
     */
    public function __construct()
    {
        $this->adminUrl = '/admin/';
    }

    /**
     * Starts a test suite 
     *
     * @return Crawler
     */
    public function testAdd()
    {
        // Create a new client to browse the application
        $client = static::createClient();

        // Go to site specific admin url
        $crawler = $client->request('GET', $this->adminUrl);
        $this->assertTrue(200 === $client->getResponse()->getStatusCode());

        // do stuff here

        // goes to edit page
        $crawler = $client->request('GET', $editPage);

        return $crawler;
    }

    /**
     * Tests the edit functionality
     *
     * @param Crawler $crawler Crawler for the show view
     *
     * @depends testAdd
     */
    public function testEdit($crawler)
    {
        // Create a new client to browse the application
        $client = static::createClient();

        //Line below is included if the crawler points to the show view
        //$crawler = $client->click($crawler->selectLink('Edit')->link());

        // Fill in the form and submit it
        $form = $crawler->selectButton('Edit')->form(array(
            $foo => $bar,
        ));

        // The following line doesn't work properly if testEdit is passed the
        // edit page. However, if it is passed the show page, and the 
        // edit link above is clicked, then the form will submit fine.
        $client->submit($form);
        $crawler = $client->followRedirect();

        // more code here...
    }
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-06T19:20:08+00:00Added an answer on June 6, 2026 at 7:20 pm

    The reason is that as you can see in the WebTestCase class which you extend, a teardown is implemented:

    protected function tearDown()
    {
        if (null !== static::$kernel) {
            static::$kernel->shutdown();
        }
    }
    

    This shutdown of the kernel has many effects. One effect is what you are experiencing. I tried to track down what’s exactly happening once, but I didn’t get anywhere and just made a mental note that the client and crawler are pretty useless once the shutdown is called.

    I would recommend the same thing as Louis: Make your tests independend. Beside that it’s not working with the client, think about the time when something breaks on your create page. In effect, your edit page tests also break, although the page itself might be ok.

    Depends is normally used to further validate objects like if you would like to test the reponse a bit more in-depth. You would use a depending test and return the response from the first one. In this case, it’s also ok that both tests break, because if your create page breaks, of course your response content doesn’t look like it should.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a PHPUnit test suite that is currently causing a fatal error due
We currently have a suite of integration tests that run via MbUnit test suites.
I have the classical structure for tests, I have a test suite of different
I have this in my phpunit.xml file: <phpunit ...> <testsuites> <testsuite name=MyTests> <directory>../path/to/some/tests</directory> </testsuite>
I have a test suite that runs across several versions of a software application.
I have a test suite DLL written in C# that uses Selenium.This is then
I have a test suite to perform smoke tests. I have all my script
I have a test suite to perform smoke tests. I have all my script
I have a Robotium test suite that I am trying to run and for
I have a suite of PHPUnit tests for my extension, and I want to

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.