PHP Classes

File: test/AbstractTestCase.php

Recommend this page to a friend!
  Classes of nvb  >  PHP CURL Component  >  test/AbstractTestCase.php  >  Download  
File: test/AbstractTestCase.php
Role: Unit test script
Content type: text/plain
Description: Unit test script
Class: PHP CURL Component
Compose and execute HTTP requests with Curl
Author: By
Last change: replaced >>array()<< notation with >>[]<<
Date: 3 years ago
Size: 3,131 bytes
 

Contents

Class file image Download
<?php
/**
 * @author: stev leibelt <artodeto@bazzline.net>
 * @since: 2015-12-14
 */

namespace Test\Net\Bazzline\Component\Curl;

use
Mockery;
use
Net\Bazzline\Component\Curl\Builder\Builder;
use
Net\Bazzline\Component\Curl\Dispatcher\DispatcherInterface;
use
Net\Bazzline\Component\Curl\Request\Request;
use
Net\Bazzline\Component\Curl\Response\Response;
use
Net\Bazzline\Component\Toolbox\HashMap\Merge;
use
PHPUnit_Framework_TestCase;

abstract class
AbstractTestCase extends PHPUnit_Framework_TestCase
{

   
/**
     * @param string $method
     * @param array $headerLines
     * @param array $options
     * @param null|mixed $data
     * @return array
     */
   
protected function buildDispatcherOptions($method, array $headerLines = [], array $options = [], $data = null)
    {
       
$isDataProvided = (!is_null($data));
       
$headerLines[] = 'X-HTTP-Method-Override: ' . $method; //@see: http://tr.php.net/curl_setopt#109634
       
$dispatcherOptions = $options;

       
$dispatcherOptions[CURLOPT_CUSTOMREQUEST] = $method;
       
$dispatcherOptions[CURLOPT_HTTPHEADER] = $headerLines;

        if (
$isDataProvided) {
           
$dispatcherOptions[CURLOPT_POSTFIELDS] = $data;
        }

        return
$dispatcherOptions;
    }

   
/**
     * @return Mockery\MockInterface|\Net\Bazzline\Component\Curl\ResponseBehaviour\ResponseBehaviourInterface'
     */
   
protected function getMockOfTheBehaviour()
    {
        return
Mockery::mock('Net\Bazzline\Component\Curl\ResponseBehaviour\ResponseBehaviourInterface');
    }

   
/**
     * @return Mockery\MockInterface|DispatcherInterface
     */
   
protected function getMockOfTheDispatcher()
    {
        return
Mockery::mock('Net\Bazzline\Component\Curl\Dispatcher\DispatcherInterface');
    }

   
/**
     * @param Request $request
     * @param array $defaultResponseBehaviours
     * @return Builder
     */
   
protected function getNewBuilder(Request $request, array $defaultResponseBehaviours = [])
    {
        return new
Builder($request, new Merge(), $defaultResponseBehaviours);
    }

   
/**
     * @param DispatcherInterface $dispatcher
     * @param array $defaultHeaderLines
     * @param array $defaultOptions
     * @return Request
     */
   
protected function getNewRequest(DispatcherInterface $dispatcher, array $defaultHeaderLines = [], array $defaultOptions = [])
    {
        return new
Request($dispatcher, new Merge(), $defaultHeaderLines, $defaultOptions);
    }

   
/**
     * @param mixed $content
     * @param string $contentType
     * @param string $error
     * @param int $errorCode
     * @param array $headLines
     * @param int $statusCode
     * @return Response
     */
   
protected function getNewResponse($content = 'example content', $contentType = 'example content type', $error = '', $errorCode = 0, array $headLines = [], $statusCode = 200)
    {
        return new
Response($content, $contentType, $error, $errorCode, $headLines, $statusCode);
    }

   
/**
     * @return string
     */
   
protected function getUrl()
    {
        return
'http://www.foo.bar';
    }
}


For more information send a message to info at phpclasses dot org.