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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T01:42:51+00:00 2026-06-11T01:42:51+00:00

I want do one functional test over on service Symfony2. The idea is call

  • 0

I want do one functional test over on service Symfony2. The idea is call before to the controller and after that, load the service with the function. The function is this one:

function save($title,$description,$setId,$html,$validate,$articles){
    $articles = explode(',', $articles);

    if (false === $this->container->get('security.context')->isGranted('ROLE_USER')) {
        throw new \Exception("Not allowed");
    }else{
        $profileId  = $this->container->get('security.context')->getToken()->getUser()->getId();
        $userName   = $this->container->get('security.context')->getToken()->getUser()->getUserName();
    }
}

and now my test code is :

    $client = static::createClient();

    $crawler = $client->request('GET','/sets/save',
            array(
                    "title"=>"rtyui",
                    "description"=>"aksdjhashdkjahskjdh",
                    "set_id"=>"",
                    "html"=>"",
                    "validate"=>1,
                    "articels"=>"3,4"
                )
        ); 

but doesn’t work already that I have this lines:

if (false === $this->container->get('security.context')->isGranted('ROLE_USER')) {
        throw new \Exception("Not allowed");

Now, the question is, how i can do the validation process? I’ve tried to do this validation process as show the documentation:

$client = static::createClient(array(), array(
    'PHP_AUTH_USER' => 'username',
    'PHP_AUTH_PW'   => 'pa$$word',
));

but I got the same error.

  • 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-11T01:42:52+00:00Added an answer on June 11, 2026 at 1:42 am

    Also you can login user by Security Token:

    $client = static::createClient();
    $container = $client->getContainer();
    $container->get('security.context')->setToken(
        new UsernamePasswordToken(
            $user, null, 'main', $user->getRoles()
        )
    );
    

    Where:

    1. $user – instance of User entity with role ROLE_USER,
    2. main – your security provider name
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to have one callback function after actions are done, I'm trying something
I have one function ParseHtmlTable(string htmlContent) . Now in that function I want to
I have one r function i want to run it automatically(scheduling) after every predefined
I've read that static variables are used inside function when one doesn't want the
Would I want to nest one function into another?
I want to execute a function on one element in the center of the
I want to issue multiple mysql commands with one mysql_query function. This is my
If I have a function in SSJS and I want to pass one firm
Let's say I want to run the same function on every one of my
I'm working on a play app and want to improve my test coverage before

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.