Weave Code
Code Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message

Github Api Laravel Package

knplabs/github-api

Lightweight, well-tested PHP wrapper for GitHub APIs v3 (REST) and v4 (GraphQL). PSR-17/PSR-18 compatible via HTTPlug, with easy setup using Guzzle, Symfony HttpClient, or other PSR clients. Supports framework integrations (Laravel via graham-campbell/github).

View on GitHub
Deep Wiki
Context7

Running and writing tests

Back to the navigation

Run Test Suite

The code is unit tested, there are also some functional tests. To run tests on your machine, from a CLI, run

$ composer update
$ phpunit

Write tests

It is always great if someone wants to contribute and extend the functionality of the API client. But all new features must be properly tested. To test a new API function, one should test its communication with the HTTP client. The code should never make an actual call to GitHub. Testing could easily be done with mocking.

If you want to write test for the function that shows you comments to a gist.

class Comments extends AbstractApi
{
    // ...
    public function show($gist, $comment)
    {
        return $this->get('/gists/'.rawurlencode($gist).'/comments/'.rawurlencode($comment));
    }
}

The test will look like this:

use Github\Tests\Api\TestCase;

class CommentsTest extends TestCase
{
    // ...

    /**
     * [@test](https://github.com/test)
     */
    public function shouldShowGistComment()
    {
        // Create a variable with the "Server response".
        $expectedValue = array('comment1');

        // Get the API mock (see "getApiClass" below).
        $api = $this->getApiMock();

        $api->expects($this->once())                    // Expect one call
            ->method('get')                             // A GET request
            ->with('/gists/123/comments/456')           // URI should be "/gists/123/comments/456"
            ->will($this->returnValue($expectedValue)); // Should return the "Server response"

        // Call Comments::show
        $result = $api->show(123, 456);

        // Verify that the result is the "Server response" as we expect.
        $this->assertEquals($expectedValue, $result);
    }

    protected function getApiClass()
    {
        // Tell the "getAPIMock" what class to mock.
        return \Github\Api\Gist\Comments::class;
    }
}
Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
davejamesmiller/laravel-breadcrumbs
artisanry/parsedown
christhompsontldr/phpsdk
bower-asset/punycode
bower-asset/inputmask
bower-asset/jquery
bower-asset/yii2-pjax
laravel/nova
spatie/laravel-mailcoach
spatie/laravel-superseeder
laravel/liferaft
nst/json-test-suite
danielmiessler/sec-lists
jackalope/jackalope-transport
twbs/bootstrap4
php-http/client-implementation
phpcr/phpcr-implementation
cucumber/gherkin-monorepo
haydenpierce/class-finder
psr/simple-cache-implementation