在php单元测试中我得到一个非法的字符串错误,ErrorException:非法字符串偏移'tableData'

时间:2018-01-23 07:27:45

标签: php laravel phpstorm

laravel中的控制器和单元testController。并获取'tableData'的非法字符串错误,该表定义为映射$ arrViewBoundData数组

 public function getGroupList()
        {
            try {
                $requiredPermissions = [
                    config('permission.group_list_view_own'),
                    config('permission.group_list_view_all'),
                ];
                if (!$this->userPermissionHelper->checkHasPermissionFor($requiredPermissions)) {
                    return view('error.permission-denied');
                }
                $arrGroup = $this->groupRepo->getGroupList(Input::get());
                return view('group.index', $arrGroup);
            } catch (\Exception $ex) {
                return view('error.error_404');
            }
        }
    public function testGetGroupListForListOfRecords()
        {
            $this->app->instance('middleware.disable', true);
            $sampleJsonFile = file_get_contents(base_path('tests\Unit\sample_outputs\group_list.json'));
            $sampleOutput = json_decode($sampleJsonFile, true);

            $sampleOutput['tableData'] = array((object) $sampleOutput['tableData']);
            $sampleOutput['langList'] = array((object) $sampleOutput['langList']);
            $this->objMockGroupRepositoryInterface->shouldReceive('getGroupList')->andReturn($sampleOutput);
            $this->app->instance(GroupRepositoryInterface::class, $this->objMockGroupRepositoryInterface);
            $response = $this->call('GET', 'test-group/group');
            $arrViewBoundData = $response->original;
            $this->assertGreaterThan(0,count($arrViewBoundData['tableData']));
        }

0 个答案:

没有答案