<?php
namespace Sil\SilAuth\tests\fakes;

use GuzzleHttp\Handler\MockHandler;
use GuzzleHttp\HandlerStack;
use Psr\Log\LoggerInterface;
use Sil\Idp\IdBroker\Client\IdBrokerClient;
use Sil\SilAuth\auth\IdBroker;

abstract class FakeIdBroker extends IdBroker
{
    public function __construct(
        string $baseUri,
        string $accessToken,
        LoggerInterface $logger,
        string $idpDomainName = 'fake.example.com'
    ) {
        parent::__construct($baseUri, $accessToken, $logger, $idpDomainName);
        
        // Now replace the client with one that will return the desired response.
        $this->client = new IdBrokerClient($baseUri, $accessToken, [
            'http_client_options' => [
                'handler' => HandlerStack::create(new MockHandler([
                    
                    /* Set up several, since this may be called multiple times
                     * during a test: */
                    $this->getDesiredResponse(),
                    $this->getDesiredResponse(),
                    $this->getDesiredResponse(),
                    $this->getDesiredResponse(),
                    $this->getDesiredResponse(),
                    $this->getDesiredResponse(),
                    $this->getDesiredResponse(),
                    $this->getDesiredResponse(),
                    $this->getDesiredResponse(),
                    $this->getDesiredResponse(),
                ])),
            ],
        ]);
    }
    
    abstract protected function getDesiredResponse();
}

<?php
namespace Sil\SilAuth\tests\fakes;

use GuzzleHttp\Handler\MockHandler;
use GuzzleHttp\HandlerStack;
use Psr\Log\LoggerInterface;
use Sil\SilAuth\auth\Authenticator;
use Sil\Idp\IdBroker\Client\IdBrokerClient;
use Sil\SilAuth\auth\IdBroker;

abstract class FakeIdBroker extends IdBroker
{
    public function __construct(
        string $baseUri,
        string $accessToken,
        LoggerInterface $logger,
        string $idpDomainName = 'fake.example.com'
    ) {
        parent::__construct($baseUri, $accessToken, $logger, $idpDomainName);
        
        // Now replace the client with one that will return the desired response.
        $this->client = new IdBrokerClient($baseUri, $accessToken, [
            'http_client_options' => [
                'handler' => HandlerStack::create(new MockHandler(
                    
                    /* Set up several, since this may be called multiple times
                     * during a test: */
                    array_fill(
                        0,
                        Authenticator::BLOCK_AFTER_NTH_FAILED_LOGIN * 2,
                        $this->getDesiredResponse()
                    )
                )),
            ],
        ]);
    }
    
    abstract protected function getDesiredResponse();
}

Allow more dummy calls to ID Broker.
Allow more dummy calls to ID Broker.
