PHP code example of saritasa / laravel-testbed

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

    

saritasa / laravel-testbed example snippets


use Saritasa\LaravelTestbed\Traits\ApiListSortingCheck;

/**
 * Vendor tests.
 */
class VendorTest extends TestCase
{
    use ApiListSortingCheck;
}

/**
 * Check that API returns list sorted by specified field (order by single field - check for each of passed fields).
 *
 * @param string $url Api endpoint to check
 * @param int $count Count of created models
 * @param array|string[] $sortingFields Sorting fields to check
 * @param array|string[] $auth Auth
 * @param string|null $envelope Results envelope (like 'results', 'items', etc.)
 *
 * @return void
 */
public function assertSortingWorks(string $url, int $count, array $sortingFields, array $auth, ?string $envelope = null): void
/**
 * Check that API returns list sorted by specified fields
 *  (order by multiple fields - check for combinations of passed fields).
 *
 * @param string $url Api endpoint to check
 * @param int $count Count of created models
 * @param array|string[] $sortingFields Sorting fields to check
 * @param array|string[] $auth Auth
 * @param string|null $envelope Results envelope (like 'results', 'items', etc.)
 *
 * @return void
 */
public function assertMultiSortingWorks(string $url, int $count, array $sortingFields, array $auth, ?string $envelope = null): void

    /** Sorting options test */
    public function testOrderBy()
    {
        $count = 15;
        $auth = Helpers::createAndAuthenticateUser();

        factory(Vendor::class, $count)->create();
        
        $envelope = 'results';
        
        $this->assertSortingWorks("/api/vendors", $count, VendorListRequest::SORTING_FIELDS, $auth, $envelope);
    }

    /** Multi sorting options test */
    public function testMultiOrderBy()
    {
        $count = 15;
        $auth = Helpers::createAndAuthenticateUser();

        factory(Vendor::class, $count)->create();
        
        $envelope = 'results';

        $this->assertMultiSortingWorks("api/vendors", $count, VendorListRequest::SORTING_FIELDS, $auth, $envelope);
    }