%PDF- %GIF98; %PNG; .
Cyber Programmer
Logo of a company Server : Apache
System : Linux host.digitalbabaji.in 4.18.0-513.11.1.el8_9.x86_64 #1 SMP Wed Jan 17 02:00:40 EST 2024 x86_64
User : addictionfreeind ( 1003)
PHP Version : 7.2.34
Disable Function : exec,passthru,shell_exec,system
Directory :  /home/addictionfreeind/www/admin1/vendor/craftsys/msg91-php/tests/Support/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Current File : /home/addictionfreeind/www/admin1/vendor/craftsys/msg91-php/tests/Support/RequestTest.php
<?php

namespace Craftsys\Tests\Msg91\Support;

use Craftsys\Msg91\Exceptions\ResponseErrorException;
use Craftsys\Msg91\Options;
use Craftsys\Msg91\Support\Request;
use Craftsys\Tests\Msg91\TestCase;
use GuzzleHttp\Client as HttpClient;
use GuzzleHttp\Handler\MockHandler;
use GuzzleHttp\HandlerStack;
use GuzzleHttp\Psr7\Response;
use GuzzleHttp\Middleware;

class RequestTest extends TestCase
{
    protected $container = [];

    protected function setUp(): void
    {
        parent::setUp();
        $this->container = [];
    }

    protected function createMockHttpClient(
        $status_code = 200,
        $body = [
            "type" => "success", "message" => "Success"
        ]
    ): HttpClient {
        $history = Middleware::history($this->container);
        $mock = new MockHandler([
            new Response($status_code, [], json_encode($body)),
        ]);

        $handler = HandlerStack::create($mock);
        $handler->push($history);

        $client = new HttpClient(['handler' => $handler]);
        return $client;
    }

    public function test_response_error_when_invalid_request()
    {
        $this->expectException(ResponseErrorException::class);
        (new SampleRequest($this->createMockHttpClient(422), (new SampleOptions())))
            ->handle();

        $this->expectException(ResponseErrorException::class);
        (new SampleRequest($this->createMockHttpClient(200, ['type' => 'error', 'message' => 'Testing the error response with 200 code']), (new SampleOptions())))->handle();

        $this->expectException(ResponseErrorException::class);
        (new SampleRequest($this->createMockHttpClient(200, ['msg_type' => 'error', 'msg' => 'Testing the error response with 200 code']), (new SampleOptions())))->handle();
    }
}

class SampleRequest extends Request
{
    protected $url = "https://apis.craftsys.com";
}

class SampleOptions extends Options
{

    protected $payload = [
        'authkey' => 'random_auth_key'
    ];
}

VaKeR 2022