Laravel Phpunit Test

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
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值