A HTTP api testing framework based on phpunit and guzzle

1.0.1 2017-07-28 10:06 UTC

This package is not auto-updated.

Last update: 2021-07-24 10:41:08 UTC


README

安装

执行composer require subtlephp/bran

使用

  1. 使用Bran\Raven代替PHPUnit\Framework\TestCase来创建新的测试类

  2. 示例代码如下:

<?php

use Bran\Raven;

class RavenTest extends Raven
{
    protected $clientConfig = [
        'base_uri' => 'http://gank.io',
    ];

    protected $apiConfig = [
        'images' => [
            'pattern' => '/api/data/Android/10/1',
            'method' => 'get',
        ],
    ];

    public function testAssertStatusCode()
    {
        $entity = $this->call('images');

        $entity->assertStatusCode(200)
            ->assertHeader('Content-Type', 'application/json')
            ->assertJsonBodyHas('error')
            ->assertJsonBodyAttributeEquals('error', false);
    }

    public function setUp()
    {
        parent::setUp();
        $this->clientConfig['headers']['Cookie'] = $this->login();
    }

    public function login()
    {
        $entity = $this->call('login');
        return $entity->cookie;
    }
}