PHP code example of brunty / api-testcase

1. Go to this page and download the library: Download brunty/api-testcase library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

brunty / api-testcase example snippets




use Brunty\ApiTestCase;

class BooksApiTest extends ApiTestCase
{
    public function setUp()
    {
        $options = [
            // ...
        ];
        
        // use this if you want to add additional options to the client when it's constructed
        $this->configureClientOptions($options);
        parent::setUp();
    }
}



use Brunty\ApiTestCase;

class BooksApiTest extends ApiTestCase
{
    /**
     * @test
     */
    public function the_api_retrieves_all_books()
    {
        $this->get('/books');
        $this->assertResponseOk();
    }
}



use Brunty\ApiTestCase;

class BooksApiTest extends ApiTestCase
{
    /**
     * @test
     */
    public function the_api_creates_a_book()
    {
        $this->post('/books', ['title' => 'My Book']);
        $this->assertResponseOk();
    }
}



use Brunty\ApiTestCase;

class BooksApiTest extends ApiTestCase
{
    /**
     * @test
     */
    public function the_api_updates_a_book()
    {
        $this->patch('/books/1', ['title' => 'My Updated Book']);
        $this->assertResponseOk();
    }
}



use Brunty\ApiTestCase;

class BooksApiTest extends ApiTestCase
{
    /**
     * @test
     */
    public function the_api_creates_or_updates_a_book()
    {
        $this->put('/books', ['title' => 'My Updated Book']);
        $this->assertResponseOk();
    }
}



use Brunty\ApiTestCase;

class BooksApiTest extends ApiTestCase
{
    /**
     * @test
     */
    public function the_api_deletes_a_book()
    {
        $this->delete('/books/1');
        $this->assertResponseOk();
    }
}