mercredi 19 août 2020

How to write phpunit test in laravel for following function

public function storeAppUsePlaces($fromDate, $toDate) {
        $arrayData = $this->assignmentApplicationArr;
        DB::table('t_app_useplaces')->whereBetween('dtest_date', [$fromDate, $toDate])->delete(); 
        $arrayData = array_map(function($arrayData) {
            return array(
                'sexam_class' => $arrayData['exam_category'],
                'splace_code' => $arrayData['tc_code'],
                'sroom_code' => $arrayData['room_code'],
                'sroom_details_code' => $arrayData['room_detail_code'],
                'dtest_date' => $arrayData['test_date'],
                'stime_zone_class' => $arrayData['timezone'],
                'itotal_seats' => $arrayData['total_seats'],
                'itotal_applications' => $arrayData['total_applications'],
                'ireserve_count' => $arrayData['reserveCnt']
            );
        }, $arrayData);

        foreach ($arrayData as $key => $array_fam) {  
            $arrayData[$key]['idel_flg'] = 0;
            $arrayData[$key]['dcreate_date'] = date("Y-m-d");
            $arrayData[$key]['screate_name'] = 'app_allocation';
            $arrayData[$key]['dupdate_date'] = date("Y-m-d");
            $arrayData[$key]['supdate_name'] = '';
        }

        $items = collect($arrayData);
        $chunks = $items->chunk(ApplicationAllocationController::T_APP_USEPLACES_CHUNK_CNT);
        foreach ($chunks as $chunk) {
            DB::table('t_app_useplaces')->insert($chunk->toArray());
            return $chunks;
        }
    }

I already mock $arrayData = $this->assignmentApplicationArr; the array date like :

[0] => Array
        (
            [sexam_class] => 1
            [splace_code] => JT1841
            [sroom_code] => A1
            [sroom_details_code] => 01
            [dtest_date] => 2020-06-25
            [stime_zone_class] => 1
            [itotal_seats] => 20
            [itotal_applications] => 2
            [ireserve_count] => 2
            [idel_flg] => 0
            [dcreate_date] => 2020-08-17
            [screate_name] => app_allocation
            [dupdate_date] => 2020-08-17
            [supdate_name] =>
        )

but not understand how to write tests in PHPUnit in the Laravel framework for method storeAppUsePlaces. I'm new to PHPUnit and also new to Laravel. please, help me out.

Aucun commentaire:

Enregistrer un commentaire