• Categories
    • PHP
    • phpMyAdmin
    • PHPMailer
    • FFMpeg
    • PHPEXcel
    • PHPDoc
    • PHPUnit
    • CakePHP
    • CakePHP 2.0
    • Cake PHP 2.1
    • CakePHP Model
    • Facebook PHP SDK
    • composer-php
    • PHP 7
    • PHP GD
    All Categories
  • About

PHPUnit - REST API testing

restphpunitguzzle


PHP Snippet 1:

$response = $this->call('POST', '/api/v1.0/pages', $parameters);
$data = $response->getData();

PHP Snippet 2:

var_dump($response->getBody()->getContents());

PHP Snippet 3:

$client = new GuzzleHttp\Client();
$response = $client->get('http://192.168.99.100/v1/hello');
var_dump($response->getBody()->getContents());

PHP Snippet 4:

string(13) "{"bar":"foo"}"

Related Snippets

How do I do HTTP basic authentication using Guzzle?

Laravel + phpunit + github actions = Failed asserting that '1' is identical to 1

PHPUnit gives error: Target [IlluminateContractsViewFactory] is not instantiable

PHPUnit 7: Failed asserting that exception of type InvalidArgumentException is thrown

How to assert parameter attribute sub-structures in PHPUnit mock call expectations

Autoloading classes in PHPUnit using Composer and autoload.php

Guzzle Not Sending Grant Type to Laravel Passport

How should I get started using PHPUnit as a testing framework for a bunch of functions and classes I have already made?

phpunit - mockbuilder - set mock object internal property

Phpunit partial mock + proxy Entity

How can I make Laravel return a custom error for a JSON REST API

Custom API and cunsuming in php?

laravel and phpunit: could not find driver (SQL: PRAGMA foreign_keys = ON;)

GuzzleHttp Hangs When Using Localhost

Trying to mock an http client that is inside a controller, using phpunit, but it doesn't work

About Contact Privacy policy Terms and conditions