PHP code example of fan / laty

1. Go to this page and download the library: Download fan/laty 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/ */

    

fan / laty example snippets


api_controller_actions:
  base_url: https://localhost/api
  logging:
    file: php://stderr
    verbosity: 0
    query: false



namespace Tests\Api;

use Fan\Laty\Laravel\ApiTestCase;
use Illuminate\Contracts\Console\Kernel;
use Illuminate\Support\Facades\Auth;
use Laravel\Passport\Passport;
use App\Models\User;

class WebServiceTest extends ApiTestCase
{
    public function webServiceAutomatedProvider()
    {
        return $this->apiControllerAutomatedProvider(static::getConfigPrefix());
    }

    /**
    * @param array $seeds database seeds
    * @param string $method HTTP method
    * @param string $uri URI
    * @param array $parameters request parameters
    * @param array $cookies request cookies
    * @param array $files files posted
    * @param array $server server parameters
    * @param string $content data posted
    * @param unknown $checks
    * @dataProvider webServiceAutomatedProvider
    */
    public function testWebServices(
        $seeds,
        $method,
        $uri,
        $parameters,
        $cookies,
        $files,
        $server,
        $content,
        $checks,
        $test_id
    ) {
        return $this->apiControllerAutomatedTest(
            $seeds,
            $method,
            $uri,
            $parameters,
            $cookies,
            $files,
            $server,
            $content,
            $checks,
            $test_id
        );
    }

    protected static function getConfigPaths()
    {
        return array(__DIR__.'/specs/');
    }

    protected static function getConfigPrefix()
    {
        return 'api_controller_actions';
    }

    protected function authenticateUser($user_name, $server)
    {
        $user = $this->getUser($user_name);

        if (! is_null($user)) {
            // if you are using Passport for authentication
            Passport::actingAs($user);
        }

        return $server;
    }

    private function getUser($user_name)
    {
        return User::find($user_name);
    }

    protected function getAuthenticatedUser()
    {
        return Auth::user();
    }

    protected function prepareCache(array $checks)
    {
        // add your cache layer mock here
    }

    /**
     * Creates the application.
     *
     * @return \Illuminate\Foundation\Application
     */
    public function createApplication()
    {
        $app = 

    "test:api": [
        "php vendor/bin/phpunit tests/Api"
    ]

$composer test:api
> php vendor/bin/phpunit tests/Api
PHPUnit 9.5.21 #StandWithUkraine

.                                                                   1 / 1 (100%)

Time: 00:00.270, Memory: 18.00 MB

OK (1 tests, 1 assertions)

composer test:api test_filter=users/show/0 "logging[verbosity]=6"
> php vendor/bin/phpunit tests/Api 'test_filter=users/show/0' 'logging[verbosity]=6'
PHPUnit 9.5.21 #StandWithUkraine

"Sending request data "[]" to "https://localhost/api/user""
"""
Received response data "HTTP/1.1 401 Unauthorized\r\n
Access-Control-Allow-Origin: *\r\n
Cache-Control:               no-cache, private\r\n
Content-Type:                application/json\r\n
Date:                        Mon, 15 Aug 2022 03:01:33 GMT\r\n
\r\n
{"message":"Unauthenticated."}"
"""
.                                                                   1 / 1 (100%)

Time: 00:00.328, Memory: 24.00 MB

OK (1 test, 1 assertion)

> php vendor/bin/phpunit tests/Api 'test_filter=comments/show/1' 'logging[query]=true'
PHPUnit 9.5.21 #StandWithUkraine

array:2 [
  0 => array:3 [
    "query" => "select * from `users` where `id` = ? limit 1"
    "bindings" => array:1 [
      0 => "11"
    ]
    "time" => 3.0
  ]
  1 => array:3 [
    "query" => "select * from `comments` where `id` = ? and `comments`.`deleted_at` is null limit 1"
    "bindings" => array:1 [
      0 => "1"
    ]
    "time" => 2.87
  ]
]
.                                                                   1 / 1 (100%)

Time: 00:00.290, Memory: 26.00 MB

OK (1 test, 2 assertions)