<commit_before><?php

namespace Risan\OAuth1\Test\Unit\Request;

use PHPUnit\Framework\TestCase;
use Risan\OAuth1\Config\ConfigInterface;
use Risan\OAuth1\Request\RequestFactory;
use Risan\OAuth1\Request\RequestInterface;
use Risan\OAuth1\Request\RequestFactoryInterface;
use Risan\OAuth1\Credentials\TemporaryCredentials;
use Risan\OAuth1\Request\AuthorizationHeaderInterface;

class RequestFactoryTest extends TestCase
{
    private $authorizationHeaderStub;
    private $configStub;
    private $requestFactory;
    private $requestFactoryStub;
    private $requestStub;
    private $temporaryCredentialsStub;

    function setUp()
    {
        $this->authorizationHeaderStub = $this->createMock(AuthorizationHeaderInterface::class);
        $this->configStub = $this->createMock(ConfigInterface::class);
        $this->requestFactory = new RequestFactory($this->authorizationHeaderStub);
        $this->requestStub = $this->createMock(RequestInterface::class);
        $this->temporaryCredentialsStub = $this->createMock(TemporaryCredentials::class);

        $this->requestFactoryStub = $this->getMockBuilder(RequestFactory::class)
            ->setConstructorArgs([$this->authorizationHeaderStub])
            ->setMethods(['getConfig', 'create'])
            ->disableOriginalClone()
            ->disableArgumentCloning()
            ->disallowMockingUnknownTypes()
            ->getMock();
    }

    /** @test */
    function it_implements_request_factory_interface()
    {
        $this->assertInstanceOf(RequestFactoryInterface::class, $this->requestFactory);
    }

    /** @test */
    function it_can_get_authorization_header()
    {
        $this->assertSame($this->authorizationHeaderStub, $this->requestFactory->getAuthorizationHeader());
    }

    /** @test */
    function it_can_get_config()
    {
        $this->authorizationHeaderStub
            ->expects($this->once())
            ->method('getConfig')
            ->willReturn($this->configStub);

        $this->assertSame($this->configStub, $this->requestFactory->getConfig());
    }

    /** @test */
    function it_can_create_for_temporary_credentials()
    {
        $this->requestFactoryStub
            ->expects($this->once())
            ->method('getConfig')
            ->willReturn($this->configStub);

        $this->configStub
            ->expects($this->once())
            ->method('getTemporaryCredentialsUri')
            ->willReturn('http://example.com');

        $this->authorizationHeaderStub
            ->expects($this->once())
            ->method('forTemporaryCredentials')
            ->willReturn('OAuth1');

        $this->requestFactoryStub
            ->expects($this->once())
            ->method('create')
            ->with('POST', 'http://example.com', [
                'headers' => ['Authorization' => 'OAuth1'],
            ])
            ->willReturn($this->requestStub);

        $this->assertSame($this->requestStub, $this->requestFactoryStub->forTemporaryCredentials());
    }

    /** @test */
    function it_can_create_for_token_credentials()
    {
        $this->requestFactoryStub
            ->expects($this->once())
            ->method('getConfig')
            ->willReturn($this->configStub);

        $this->configStub
            ->expects($this->once())
            ->method('getTokenCredentialsUri')
            ->willReturn('http://example.com');

        $this->authorizationHeaderStub
            ->expects($this->once())
            ->method('forTokenCredentials')
            ->with($this->temporaryCredentialsStub, 'verification_code')
            ->willReturn('OAuth1');

        $this->requestFactoryStub
            ->expects($this->once())
            ->method('create')
            ->with('POST', 'http://example.com', [
                'headers' => ['Authorization' => 'OAuth1'],
                'form_params' => ['oauth_verifier' => 'verification_code'],
            ])
            ->willReturn($this->requestStub);

        $this->assertSame(
            $this->requestStub,
            $this->requestFactoryStub->forTokenCredentials($this->temporaryCredentialsStub, 'verification_code')
        );
    }
}<commit_msg>:white_check_mark: Update request factory test.<commit_after><?php

namespace Risan\OAuth1\Test\Unit\Request;

use PHPUnit\Framework\TestCase;
use Risan\OAuth1\Config\ConfigInterface;
use Risan\OAuth1\Request\RequestFactory;
use Risan\OAuth1\Request\RequestInterface;
use Risan\OAuth1\Request\RequestFactoryInterface;
use Risan\OAuth1\Credentials\TemporaryCredentials;
use Risan\OAuth1\Request\AuthorizationHeaderInterface;

class RequestFactoryTest extends TestCase
{
    private $authorizationHeaderStub;
    private $configStub;
    private $requestFactory;
    private $requestFactoryStub;
    private $requestStub;
    private $temporaryCredentialsStub;

    function setUp()
    {
        $this->authorizationHeaderStub = $this->createMock(AuthorizationHeaderInterface::class);
        $this->configStub = $this->createMock(ConfigInterface::class);
        $this->requestFactory = new RequestFactory($this->authorizationHeaderStub);
        $this->requestStub = $this->createMock(RequestInterface::class);
        $this->temporaryCredentialsStub = $this->createMock(TemporaryCredentials::class);

        $this->requestFactoryStub = $this->getMockBuilder(RequestFactory::class)
            ->setConstructorArgs([$this->authorizationHeaderStub])
            ->setMethods(['getConfig', 'create'])
            ->disableOriginalClone()
            ->disableArgumentCloning()
            ->disallowMockingUnknownTypes()
            ->getMock();
    }

    /** @test */
    function it_implements_request_factory_interface()
    {
        $this->assertInstanceOf(RequestFactoryInterface::class, $this->requestFactory);
    }

    /** @test */
    function it_can_get_authorization_header()
    {
        $this->assertSame($this->authorizationHeaderStub, $this->requestFactory->getAuthorizationHeader());
    }

    /** @test */
    function it_can_get_config()
    {
        $this->authorizationHeaderStub
            ->expects($this->once())
            ->method('getConfig')
            ->willReturn($this->configStub);

        $this->assertSame($this->configStub, $this->requestFactory->getConfig());
    }

    /** @test */
    function it_can_create_for_temporary_credentials()
    {
        $this->requestFactoryStub
            ->expects($this->once())
            ->method('getConfig')
            ->willReturn($this->configStub);

        $this->configStub
            ->expects($this->once())
            ->method('getTemporaryCredentialsUri')
            ->willReturn('http://example.com');

        $this->authorizationHeaderStub
            ->expects($this->once())
            ->method('forTemporaryCredentials')
            ->willReturn('OAuth1');

        $this->requestFactoryStub
            ->expects($this->once())
            ->method('create')
            ->with('POST', 'http://example.com', [
                'headers' => ['Authorization' => 'OAuth1'],
            ])
            ->willReturn($this->requestStub);

        $this->assertSame($this->requestStub, $this->requestFactoryStub->createForTemporaryCredentials());
    }

    /** @test */
    function it_can_create_for_token_credentials()
    {
        $this->requestFactoryStub
            ->expects($this->once())
            ->method('getConfig')
            ->willReturn($this->configStub);

        $this->configStub
            ->expects($this->once())
            ->method('getTokenCredentialsUri')
            ->willReturn('http://example.com');

        $this->authorizationHeaderStub
            ->expects($this->once())
            ->method('forTokenCredentials')
            ->with($this->temporaryCredentialsStub, 'verification_code')
            ->willReturn('OAuth1');

        $this->requestFactoryStub
            ->expects($this->once())
            ->method('create')
            ->with('POST', 'http://example.com', [
                'headers' => ['Authorization' => 'OAuth1'],
                'form_params' => ['oauth_verifier' => 'verification_code'],
            ])
            ->willReturn($this->requestStub);

        $this->assertSame(
            $this->requestStub,
            $this->requestFactoryStub->createForTokenCredentials($this->temporaryCredentialsStub, 'verification_code')
        );
    }
}
{'fraction_non_alphanumeric': 0.1473043893129771, 'fraction_numerical': 0.0026240458015267176, 'mean_word_length': 2.6615720524017465, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 199, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2754302', 'n_tokens_mistral': 2230, 'n_tokens_neox': 2298, 'n_words': 270}