mirror of
https://github.com/wallabag/wallabag.git
synced 2025-08-01 17:38:38 +00:00
Make LoginFormAuthenticator a service and remove Factory
This commit is contained in:
parent
81d269dec1
commit
0c49aee192
4 changed files with 30 additions and 66 deletions
|
@ -15,15 +15,18 @@ use PHPUnit\Framework\TestCase;
|
|||
use Wallabag\Guzzle\AuthenticatorSubscriber;
|
||||
use Wallabag\SiteConfig\ArraySiteConfigBuilder;
|
||||
use Wallabag\SiteConfig\Authenticator\Authenticator;
|
||||
use Wallabag\SiteConfig\Authenticator\Factory;
|
||||
|
||||
class AuthenticatorSubscriberTest extends TestCase
|
||||
{
|
||||
public function testGetEvents()
|
||||
{
|
||||
$authenticator = $this->getMockBuilder(Authenticator::class)
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
|
||||
$subscriber = new AuthenticatorSubscriber(
|
||||
new ArraySiteConfigBuilder(),
|
||||
new Factory()
|
||||
$authenticator
|
||||
);
|
||||
$events = $subscriber->getEvents();
|
||||
|
||||
|
@ -35,8 +38,12 @@ class AuthenticatorSubscriberTest extends TestCase
|
|||
|
||||
public function testLoginIfRequiredNotRequired()
|
||||
{
|
||||
$authenticator = $this->getMockBuilder(Authenticator::class)
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
|
||||
$builder = new ArraySiteConfigBuilder(['example.com' => []]);
|
||||
$subscriber = new AuthenticatorSubscriber($builder, new Factory());
|
||||
$subscriber = new AuthenticatorSubscriber($builder, $authenticator);
|
||||
|
||||
$logger = new Logger('foo');
|
||||
$handler = new TestHandler();
|
||||
|
@ -75,16 +82,8 @@ class AuthenticatorSubscriberTest extends TestCase
|
|||
$authenticator->expects($this->once())
|
||||
->method('login');
|
||||
|
||||
$factory = $this->getMockBuilder(Factory::class)
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
|
||||
$factory->expects($this->once())
|
||||
->method('buildFromSiteConfig')
|
||||
->willReturn($authenticator);
|
||||
|
||||
$builder = new ArraySiteConfigBuilder(['example.com' => ['requiresLogin' => true]]);
|
||||
$subscriber = new AuthenticatorSubscriber($builder, $factory);
|
||||
$subscriber = new AuthenticatorSubscriber($builder, $authenticator);
|
||||
|
||||
$logger = new Logger('foo');
|
||||
$handler = new TestHandler();
|
||||
|
@ -124,8 +123,12 @@ class AuthenticatorSubscriberTest extends TestCase
|
|||
|
||||
public function testLoginIfRequestedNotRequired()
|
||||
{
|
||||
$authenticator = $this->getMockBuilder(Authenticator::class)
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
|
||||
$builder = new ArraySiteConfigBuilder(['example.com' => []]);
|
||||
$subscriber = new AuthenticatorSubscriber($builder, new Factory());
|
||||
$subscriber = new AuthenticatorSubscriber($builder, $authenticator);
|
||||
|
||||
$logger = new Logger('foo');
|
||||
$handler = new TestHandler();
|
||||
|
@ -161,19 +164,11 @@ class AuthenticatorSubscriberTest extends TestCase
|
|||
->method('isLoginRequired')
|
||||
->willReturn(false);
|
||||
|
||||
$factory = $this->getMockBuilder(Factory::class)
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
|
||||
$factory->expects($this->once())
|
||||
->method('buildFromSiteConfig')
|
||||
->willReturn($authenticator);
|
||||
|
||||
$builder = new ArraySiteConfigBuilder(['example.com' => [
|
||||
'requiresLogin' => true,
|
||||
'notLoggedInXpath' => '//html',
|
||||
]]);
|
||||
$subscriber = new AuthenticatorSubscriber($builder, $factory);
|
||||
$subscriber = new AuthenticatorSubscriber($builder, $authenticator);
|
||||
|
||||
$logger = new Logger('foo');
|
||||
$handler = new TestHandler();
|
||||
|
@ -221,19 +216,11 @@ class AuthenticatorSubscriberTest extends TestCase
|
|||
$authenticator->expects($this->once())
|
||||
->method('login');
|
||||
|
||||
$factory = $this->getMockBuilder(Factory::class)
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
|
||||
$factory->expects($this->once())
|
||||
->method('buildFromSiteConfig')
|
||||
->willReturn($authenticator);
|
||||
|
||||
$builder = new ArraySiteConfigBuilder(['example.com' => [
|
||||
'requiresLogin' => true,
|
||||
'notLoggedInXpath' => '//html',
|
||||
]]);
|
||||
$subscriber = new AuthenticatorSubscriber($builder, $factory);
|
||||
$subscriber = new AuthenticatorSubscriber($builder, $authenticator);
|
||||
|
||||
$logger = new Logger('foo');
|
||||
$handler = new TestHandler();
|
||||
|
@ -276,7 +263,7 @@ class AuthenticatorSubscriberTest extends TestCase
|
|||
|
||||
public function testLoginIfRequestedRedirect()
|
||||
{
|
||||
$factory = $this->getMockBuilder(Factory::class)
|
||||
$authenticator = $this->getMockBuilder(Authenticator::class)
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
|
||||
|
@ -284,7 +271,7 @@ class AuthenticatorSubscriberTest extends TestCase
|
|||
'requiresLogin' => true,
|
||||
'notLoggedInXpath' => '//html',
|
||||
]]);
|
||||
$subscriber = new AuthenticatorSubscriber($builder, $factory);
|
||||
$subscriber = new AuthenticatorSubscriber($builder, $authenticator);
|
||||
|
||||
$logger = new Logger('foo');
|
||||
$handler = new TestHandler();
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue