403Webshell
Server IP : 54.233.248.239  /  Your IP : 172.28.20.13
Web Server : Apache
System : Linux ip-172-28-29-189 6.5.0-1014-aws #14~22.04.1-Ubuntu SMP Thu Feb 15 15:27:06 UTC 2024 x86_64
User : www-data ( 33)
PHP Version : 7.2.34-43+ubuntu22.04.1+deb.sury.org+1
Disable Function : pcntl_alarm,pcntl_fork,pcntl_waitpid,pcntl_wait,pcntl_wifexited,pcntl_wifstopped,pcntl_wifsignaled,pcntl_wifcontinued,pcntl_wexitstatus,pcntl_wtermsig,pcntl_wstopsig,pcntl_signal,pcntl_signal_get_handler,pcntl_signal_dispatch,pcntl_get_last_error,pcntl_strerror,pcntl_sigprocmask,pcntl_sigwaitinfo,pcntl_sigtimedwait,pcntl_exec,pcntl_getpriority,pcntl_setpriority,pcntl_async_signals,
MySQL : OFF  |  cURL : ON  |  WGET : ON  |  Perl : ON  |  Python : OFF  |  Sudo : ON  |  Pkexec : ON
Directory :  /var/www/html/vinumday2_0/vendor/pagarme/pagarme-php/tests/unit/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Command :


[ Back ]     

Current File : /var/www/html/vinumday2_0/vendor/pagarme/pagarme-php/tests/unit/ClientTest.php
<?php

namespace PagarMe\SdkTest;

use GuzzleHttp\Client as GuzzleClient;
use PagarMe\Sdk\Client;
use PagarMe\Sdk\RequestInterface;

class ClientTest extends \PHPUnit_Framework_TestCase
{
    const REQUEST_PATH   = 'test';
    const CONTENT        = 'sample content';
    const API_KEY        = 'myApiKey';

    private $guzzleClientMock;
    private $requestMock;

    public function setup()
    {
        $this->guzzleClientMock = $this->getMockBuilder('GuzzleHttp\Client')
            ->disableOriginalConstructor()
            ->getMock();

        $this->pagarMeRequestMock = $this->getMockBuilder('PagarMe\Sdk\RequestInterface')
            ->disableOriginalConstructor()
            ->getMock();

        $this->pagarMeRequestMock->method('getMethod')->willReturn(RequestInterface::HTTP_POST);
        $this->pagarMeRequestMock->method('getPath')->willReturn(self::REQUEST_PATH);
        $this->pagarMeRequestMock->method('getPayload')->willReturn(
            ['content' => self::CONTENT]
        );
    }

    /**
     * @test
     */
    public function mustSendRequest()
    {
        if ($this->isUsingLegacyGuzzle()) {
            $this->guzzleClientMock->method('createRequest')
                ->willReturn($this->getMock('GuzzleHttp\Message\RequestInterface'));
        }

        $responseMock = $this->getResponseMock();

        $this->guzzleClientMock->expects($this->once())->method('send')
            ->willReturn($responseMock);

        $client = new Client(
            $this->guzzleClientMock,
            self::API_KEY
        );

        $client->send($this->pagarMeRequestMock);
    }

    /**
     * @test
     */
    public function mustSendRequestWithProperContent()
    {
        if ($this->isUsingLegacyGuzzle()) {
            $this->guzzleClientMock->method('createRequest')
                ->with(
                    RequestInterface::HTTP_POST,
                    self::REQUEST_PATH,
                    [
                        'json' => [
                            'content'        => self::CONTENT,
                            'api_key'        => self::API_KEY
                        ]
                    ]
                )
                ->willReturn($this->getMock('GuzzleHttp\Message\RequestInterface'));
        }

        $responseMock = $this->getResponseMock();

        $this->guzzleClientMock->expects($this->once())->method('send')
            ->willReturn($responseMock);

        $client = new Client(
            $this->guzzleClientMock,
            self::API_KEY
        );

        $client->send($this->pagarMeRequestMock);
    }

    /**
    * @expectedException PagarMe\Sdk\ClientException
    * @test
     */
    public function mustReturnClientExeptionWhenGetRequestException()
    {
        $guzzleRequestMock = $this->getMock(
            $this->getGuzzleRequestInterfaceName()
        );

        if ($this->isUsingLegacyGuzzle()) {
            $this->guzzleClientMock->method('createRequest')
                ->willReturn($guzzleRequestMock);
        }

        $this->guzzleClientMock->method('send')
            ->will(
                $this->throwException(
                    new \GuzzleHttp\Exception\RequestException(
                        'Exception',
                        $guzzleRequestMock
                    )
                )
            );
        $this->guzzleClientMock->expects($this->once())->method('send');

        $client = new Client(
            $this->guzzleClientMock,
            self::API_KEY
        );
        $client->send($this->pagarMeRequestMock);
    }

    /**
     * @test
     */
    public function mustSetDefaultTimeout()
    {
        $timeout = 237;

        $guzzleRequestMock = $this->getMockBuilder(
            $this->getGuzzleRequestClassName()
            )->disableOriginalConstructor()
            ->getMock();

        if ($this->isUsingLegacyGuzzle()) {
            $this->guzzleClientMock->method('createRequest')
                ->willReturn($guzzleRequestMock);
        }

        $responseMock = $this->getResponseMock();

        $this->guzzleClientMock->expects($this->once())
            ->method('send')
            ->with(
                $this->isInstanceOf($this->getGuzzleRequestClassName()),
                ['timeout' => $timeout]
            )->willReturn($responseMock);

        $client = new Client(
            $this->guzzleClientMock,
            self::API_KEY,
            $timeout
        );

        $client->send($this->pagarMeRequestMock);
    }

    private function isUsingLegacyGuzzle()
    {
        return class_exists('\\GuzzleHttp\\Message\\Request');
    }

    private function getGuzzleRequestInterfaceName()
    {
        if ($this->isUsingLegacyGuzzle()) {
            return 'GuzzleHttp\Message\RequestInterface';
        }

        return 'Psr\Http\Message\RequestInterface';
    }

    private function getGuzzleRequestClassName()
    {
        if ($this->isUsingLegacyGuzzle()) {
            return 'GuzzleHttp\Message\Request';
        }

        return 'GuzzleHttp\Psr7\Request';
    }

    private function getResponseMock()
    {
        if ($this->isUsingLegacyGuzzle()) {
            $streamMock = $this->getMockBuilder(
            'GuzzleHttp\Stream\Stream'
            )->disableOriginalConstructor()
            ->getMock();

            $responseMock = $this->getMockBuilder(
                'GuzzleHttp\Message\Response'
                )->disableOriginalConstructor()
                ->getMock();

            $responseMock->method('getBody')
                ->willReturn($streamMock);

            return $responseMock;
        }

        $streamMock = $this->getMockBuilder(
            'Psr\Http\Message\StreamInterface'
            )->disableOriginalConstructor()
            ->getMock();

        $responseMock = $this->getMockBuilder(
            'GuzzleHttp\Psr7\Response'
            )->disableOriginalConstructor()
            ->getMock();

        $responseMock->method('getBody')
            ->willReturn($streamMock);

        return $responseMock;
    }
}

Youez - 2016 - github.com/yon3zu
LinuXploit