Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

[Security][Guard] check if session exist before using it #19218

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 9 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Move Mock class at the send of the test class
  • Loading branch information
pasdeloup committed Jun 29, 2016
commit 30d1d7d66b1347dcbba4d989e183a772df7b4ec4
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@

use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\Security\Core\Exception\AuthenticationException;
use Symfony\Component\Security\Core\User\UserInterface;
use Symfony\Component\Security\Core\User\UserProviderInterface;
use Symfony\Component\Security\Guard\Authenticator\AbstractFormLoginAuthenticator;

/**
* @author Jean Pasdeloup <jpasdeloup@sedona.fr>
Expand Down Expand Up @@ -110,3 +113,73 @@ protected function tearDown()
$this->requestWithSession = null;
}
}

class MockFormLoginAuthenticator extends AbstractFormLoginAuthenticator
Copy link
Member

@nicolas-grekas nicolas-grekas Jun 30, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we usually name these TestFormLoginAuthenticator, because that's what you test, isn't it? (not a dep you mock)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually, just using FormLoginAuthenticator as class name would fit here too.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You're right, it's not a Mock as it's what is tested, and that's why I didn't like the idea of using a PHPUnit mock either.

I checked in the code to be consistent with existing code for abstract class testings and found 2 main ways of doing it (and a few mixes) :

  1. Test class should be named FormLoginAuthenticatorTest
    Tested concrete class is defined after the test and named TestFormLoginAuthenticator
  2. Test class should be named AbstractFormLoginAuthenticatorTest
    Tested concrete class is defined before the test and named ConcreteFormLoginAuthenticator

I pushed a version using the 1st way as it seems the more common.

{
private $loginUrl;
private $defaultSuccessRedirectUrl;

/**
* @param mixed $defaultSuccessRedirectUrl
*
* @return MockFormLoginAuthenticator
*/
public function setDefaultSuccessRedirectUrl($defaultSuccessRedirectUrl)
{
$this->defaultSuccessRedirectUrl = $defaultSuccessRedirectUrl;

return $this;
}

/**
* @param mixed $loginUrl
*
* @return MockFormLoginAuthenticator
*/
public function setLoginUrl($loginUrl)
{
$this->loginUrl = $loginUrl;

return $this;
}

/**
* {@inheritdoc}
*/
protected function getLoginUrl()
{
return $this->loginUrl;
}

/**
* {@inheritdoc}
*/
protected function getDefaultSuccessRedirectUrl()
{
return $this->defaultSuccessRedirectUrl;
}

/**
* {@inheritdoc}
*/
public function getCredentials(Request $request)
{
return 'credentials';
}

/**
* {@inheritdoc}
*/
public function getUser($credentials, UserProviderInterface $userProvider)
{
return $userProvider->loadUserByUsername($credentials);
}

/**
* {@inheritdoc}
*/
public function checkCredentials($credentials, UserInterface $user)
{
return true;
}
}

This file was deleted.

Morty Proxy This is a proxified and sanitized view of the page, visit original site.