Skip to content

Api testing framework based on guzzle and phpunit

Notifications You must be signed in to change notification settings

happyhacker-fun/bran

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

17 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

基于PHPUnit和Guzzle的Api单元测试工具

安装

执行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;
    }
}

About

Api testing framework based on guzzle and phpunit

Resources

Stars

Watchers

Forks

Packages

No packages published

Languages