建立測試

tests\Feature\ApiTest.php

    /**
     * 測試呼叫 Api
     *
     * @return void
     */
    public function testGetTime()
    {
        $parameters = [
            'grant_type' => 'client_credentials',
            'client_id' => '3',
            'client_secret' => '2Ur6aIyJCZpAeuTwcWHyCq9YGYsPYwN23GDg4xJW',
        ];

        // 取得 token
        $response = $this->call('POST', 'oauth/token', $parameters);

        $getToken = json_decode($response->getContent(), true);
        $token = $getToken['access_token'];

        // 傳送參數
        $response = $this->call('GET', 'api/time',
            [/* params */],
            [/* cookies */],
            [/* files */],
            ['HTTP_Authorization' => 'Bearer '. $token]
        );

        $this->assertEquals(200, $response->getStatusCode());
    }

Unit test

$ vendor\bin\phpunit tests\Feature\ApiTest.php

results matching ""

    No results matching ""