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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T01:53:48+00:00 2026-06-03T01:53:48+00:00

I am working on setting up a site with fosUserBundle. I need to write

  • 0

I am working on setting up a site with fosUserBundle. I need to write some unit tests, but I cannot seems to get authentication to work correctly for use with them. I have have tried a few methods with no luck.

approach1 – chain providers in security settings to make a standard login I can rely on. When I do this the only authentication that works is the in_memory provider meaning I can login in with the admin user but not any users created by fosUserBundle

security.yml

security:
    encoders:
        "FOS\UserBundle\Model\UserInterface": plaintext
        "Symfony\Component\Security\Core\User\User": plaintext

    providers:
        chain_provider:
            providers: [in_memory, fos_userbundle]
        in_memory:
            users:
                admin: { password: admin, roles: [ 'ROLE_ADMIN' ] }
        fos_userbundle:
            id: fos_user.user_manager


    firewalls:
        main:
            pattern: ^/
            form_login:
                provider: fos_userbundle
                login_path:  /
                csrf_provider: form.csrf_provider
                default_target_path: /media
            logout:       true
            anonymous:    true
            http_basic:
                provider: in_memory

Method 2- I created a user in my setup of the unit test. But with this method I can never login with the user I just created, I am not requiring user confirmation.

 public function setUp() {

        $kernel = static::createKernel();
        $this->repo = $kernel->boot();
        $this->repo = $kernel->getContainer();

        $userManager = $this->repo->get('fos_user.user_manager');

        $email = "testing".(string) self::newRandomNumber()."@test.com";
        $un = "test".(string) self::newRandomNumber();
        $fn = "testin";
        $ln = "laster";
        $pwd = "passworD1";

        $user = $userManager->createUser();

        $user->setEmail($email);
        $user->setUsername($un);
        $user->setFirstName($fn);
        $user->setLastName($ln);
        $user->setPlainPassword($pwd);
        $user->setBimStaff(True);

        // Persist the user to the database         
        $userManager->updateUser($user);

        $this->user = $user;

        $this->client = static::createClient();
        $crawler = $this->client->request('GET', '/');

        $form = $crawler->selectButton('Login')->form();

        // set some values
        $un = 'Lucas'.self::newRandomNumber();
        $form['_username'] = $un;
        $form['_password'] = $pwd;

        // submit the form

        $crawler = $this->client->submit($form);
        print_r($this->client->getResponse());

        $this->client->followRedirects();

    }

I have tried both login in at the form and http basic authentication but neither seem to work.

Any one have any advice?

Thanks,
Cory

  • 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-03T01:53:49+00:00Added an answer on June 3, 2026 at 1:53 am

    Hmm, It seems that if you chain providers in the security you cannot use just one of the providers, at least that solved the issue for me.

    // security.yml 
    providers:
        chain_provider:
            providers: [in_memory, fos_userbundle]
        in_memory:
            users:
                admin: { password: admin, roles: [ 'ROLE_ADMIN' ] }
        fos_userbundle:
            id: fos_user.user_manager
    
    
    firewalls:
        main:
            pattern: ^/
            form_login:
                provider: chain_provider
                login_path:  /
                csrf_provider: form.csrf_provider
                default_target_path: /media
            logout:       true
            anonymous:    true
            http_basic:
                provider: chain_provider
    

    FOr some reason as soon as I changed both providers to chain_provider it started cooperating.

    My unit test now looks like this

    public function setUp() {
    
        $kernel = static::createKernel();
        $this->repo = $kernel->boot();
        $this->repo = $kernel->getContainer();
    
    
        $this->client = static::createClient(array(), array(
            'PHP_AUTH_USER' => 'admin',
            'PHP_AUTH_PW'   => 'admin',
        ));
        $this->client->followRedirects();
    
    }
    

    If copying this I would suggest using stronger passwords for your users 🙂

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

Sidebar

Related Questions

I have my site working perfectly in IE 6+ but it looks weird in
I need some help with setting up a cURL request to a page. In
Our site does a lot of JavaScript/jQuery work in the $(document).ready() function, setting up
I've build a mobile site using jQTouch, and now I've been working to get
I need some help programatically setting the selected item in a combobox. I've got
I'm working on a site that uses Django 1.2.5. It uses the Django authentication
so here's the setting: The whole site is working fine if I remove the
On a site that I am working on, if users change the language settings
I'm working on setting up NHibernate for a project and I have a few
I'm rather new to Powershell and am working on setting up my profile.ps1 file.

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.