Create php test unit case
php artisan make:test GetPosTest —unit
vim tests/Unit/GetPosTest.php
<?php
namespace Tests\Unit;
use App\Services;
use Tests\TestCase;
use Illuminate\Foundation\Testing\WithFaker;
use Illuminate\Foundation\Testing\RefreshDatabase;
class GetPosTest extends TestCase
{
private static $empty_array = [];
private static $one_item_array = [
['posx' => 327, 'poxy' => 444 ]
];
private static $more_items_array_1 = [
['posx' => 82, 'poxy' => 444 ],
['posx' => 327, 'poxy' => 444 ],
['posx' => 230, 'poxy' => 622 ],
];
private static $more_items_array_2 = [
['posx' => 82, 'poxy' => 444 ],
['posx' => 327, 'poxy' => 504 ],
['posx' => 400, 'poxy' => 622 ],
];
private static $more_items_array_3 = [
['posx' => 82, 'poxy' => 444 ],
['posx' => 327, 'poxy' => 444 ],
['posx' => 230, 'poxy' => 444 ],
];
/**
* @group testGetPersonalPos
* @return void
*/
public function testGetPersonalPos()
{
$case1 = Services::getPersionPosInPage(self::$empty_array);
var_dump($case1);
$this->assertEmpty($case1);
$case2 = Services::getPersionPosInPage(self::$one_item_array);
var_dump($case2);
$this->assertIsArray($case2);
$this->assertEquals(self::$one_item_array[0], $case2);
$case3 = Services::getPersionPosInPage(self::$more_items_array_1);
var_dump($case3);
$this->assertIsArray($case3);
$this->assertEquals(self::$more_items_array_1[0], $case3);
$case4 = Services::getPersionPosInPage(self::$more_items_array_2);
var_dump($case4);
$this->assertIsArray($case4);
$this->assertEquals(self::$more_items_array_2[0], $case4);
$case5 = Services::getPersionPosInPage(self::$more_items_array_3);
var_dump($case5);
$this->assertIsArray($case5);
$this->assertEquals(self::$more_items_array_3[0], $case5);
}
}
Look at help of phpunit
./vendor/bin/phpunit -h
Exec phpuint test case by file
./vendor/bin/phpunit tests/Unit/GetPosTest.php
Exec phpuint test case by groups
./vendor/bin/phpunit --group testGetPersonalPos
Exec phpunit test case by file and by groups
./vendor/bin/phpunit --group testGetPersonalPos tests/Unit/GetPosTest.php