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 8480417
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T19:17:22+00:00 2026-06-10T19:17:22+00:00

// src/Acme/DemoBundle/Tests/Controller/DemoControllerTest.php namespace Acme\DemoBundle\Tests\Controller; use Symfony\Bundle\FrameworkBundle\Test\WebTestCase; class DemoControllerTest extends WebTestCase { public function testIndex()

  • 0
// src/Acme/DemoBundle/Tests/Controller/DemoControllerTest.php
namespace Acme\DemoBundle\Tests\Controller;

use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;

class DemoControllerTest extends WebTestCase
{
    public function testIndex()
    {
        $client = static::createClient();

        $crawler = $client->request('GET', '/demo/hello/Fabien');

        $this->assertGreaterThan(0, $crawler->filter('html:contains("Hello Fabien")')->count());
    }
}

this working OK in my tests, but i would like use this crawler also in controller. How can i do it?

i make route, and add to controller:

<?php

// src/Ens/JobeetBundle/Controller/CategoryController

namespace Acme\DemoBundle\Controller;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Acme\DemoBundle\Entity\Category;
use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;

class CategoryController extends Controller
{   
  public function testAction()
  {
    $client = WebTestCase::createClient();

    $crawler = $client->request('GET', '/category/index');
  }

}

but this return me error:

Fatal error: Class 'PHPUnit_Framework_TestCase' not found in /acme/vendor/symfony/src/Symfony/Bundle/FrameworkBundle/Test/WebTestCase.php on line 24
  • 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-10T19:17:23+00:00Added an answer on June 10, 2026 at 7:17 pm

    The WebTestCase class is a special class that is designed to be run within a test framework (PHPUnit) and you cannot use it in your controller.

    But you can create a HTTPKernel client like this:

    use Symfony\Component\HttpKernel\Client;
    
    ...
    
    public function testAction()
    {
        $client = new Client($this->get('kernel'));
        $crawler = $client->request('GET', '/category/index');
    }
    

    Note that you will only be able to use this client to browse your own symfony application. If you want to browse an external server you will need to use another client like goutte.

    The crawler created here is the same crawler returned by WebTestCase so you can follow the same examples detailed in the symfony testing documentation

    If you need more information, here is the documentation for the crawler component and here is the class reference

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

Sidebar

Related Questions

buildIMG = (src, resize) -> html = '<div class=left><div class=foods_image>' html += '<a onclick=popitup(http://somewhere.com/test
What are the programmatic steps to turn this string: AcmeProjectBundle::home.html.twig into this? /path/Symfony/src/Acme/ProjectBundle/Resources/views/home.html.twig
//src/com/test/animal/Animal.java package com.test.animal; public class Animal { Animal() { init(); } public void init()
I have this custom form field {# src/Acme/DemoBundle/Resources/views/Form/fields.html.twig #} {% block gender_widget %} {%
I am getting the following error: The autoloader expected class Acme\HelloBundle\Controller\HelloController to be defined
I have a .java src file that looks like this: class Test { public
I store uploaded files in the web directory: //src/Acme/CocoBundle/Entity/CocoFromTheNorth.php /** * @ORM\Column(type=string, length=255, nullable=true)
package src; import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; public class Command { public static
In SpringMVC in src/main/resources I have my hibernate.cfg.xml I have a class that's my
I need to create a form class,I'm following the symfony book in http://symfony.com/doc/current/book/forms.html I

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.