phisby/phisby

REST API Endpoint Testing built on PHPUnit

dev-master / 1.0.x-dev 2015-10-02 23:55 UTC

This package is auto-updated.

Last update: 2024-03-29 02:17:35 UTC


README

Build Status Coverage Status

A REST API testing framework inspired by frisby-js, written in PHP

Documentation

Documentation for this library can be found on readthedocs

Installation

Run the following composer command:

$ composer require "phisby/phisby"

Basic Usage.

use Phisby\Phisby

$phisby = new Phisby();

$phisby
    ->get('http://localhost/api/1.0/users/3.json')
    ->expectStatus(200)
    ->expectJSONTypes('.', [
        'id'        => 'integer',
        'username'  => 'string',
        'is_admin'  => 'boolean'
    ])
    ->expectJSON('.',[
        'id'        => 3,
        'username'  => 'johndoe',
        'is_admin'  => false
    ])
    ->send();

PHPUnit test case.

use Phisby\PhisbyTestCase;

class PhisbyTest extends PhisbyTestCase
{
    public function testGithubSearch()
    {
        $this->phisby
            ->get('https://api.github.com/search/repositories?q=doctrine+language:php&sort=stars&order=desc&per_page=1')
            ->expectStatus(200)
            ->expectHeaders([
                'Content-Type' => 'application/json; charset=utf-8'
            ])
            ->expectJSONTypes('.', [
                'total_count'        => 'integer',
                'incomplete_results' => 'boolean',
                'items'              => 'array'
            ])
            ->expectJSONTypes('items[0]', [
                'id'      => 'integer',
                'name'    => 'string',
                'private' => 'boolean'
            ])
            ->expectJSON('items[0]',[
                'id'    => 597887,
                'name'  => 'doctrine2'
            ])->send();
    }
}