Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/296.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
会话_start():无法读取会话数据:用户(路径:)-在phpUnit和zend测试中_Php_Phpunit_Zend Framework2_Vagrant_Zend Test - Fatal编程技术网

会话_start():无法读取会话数据:用户(路径:)-在phpUnit和zend测试中

会话_start():无法读取会话数据:用户(路径:)-在phpUnit和zend测试中,php,phpunit,zend-framework2,vagrant,zend-test,Php,Phpunit,Zend Framework2,Vagrant,Zend Test,我们是为zf2应用程序设置测试自动化的新手 我们使用zend test(AbstractHttpControllerTestCase)的测试类,因为它是zend应用程序。我们在《流浪汉》中通过phpUnit进行了调查 到目前为止,一切进展顺利,直到我们遇到以下错误: [ERR] session_start(): Failed to read session data: user (path: ) #0 [internal function]: PHPUnit_Util_ErrorHandler:

我们是为zf2应用程序设置测试自动化的新手

我们使用zend test(AbstractHttpControllerTestCase)的测试类,因为它是zend应用程序。我们在《流浪汉》中通过phpUnit进行了调查

到目前为止,一切进展顺利,直到我们遇到以下错误:

[ERR] session_start(): Failed to read session data: user (path: )
#0 [internal function]: PHPUnit_Util_ErrorHandler::handleError(2, 'session_start()...', 'app...', 140, Array)
#1 app/vendor/zendframework/zend-session/src/SessionManager.php(140): session_start()
#2 app/vendor/zendframework/zend-session/src/AbstractContainer.php(83): Zend\Session\SessionManager->start()
#3 app/module/APP/Controller/BaseController.php(175): Zend\Session\AbstractContainer->__construct('sessionForlogin...')
#4 [internal function]: APP\Controller\BaseController->APP\Controller\{closure}(Object(Zend\Mvc\MvcEvent))
#5 app/vendor/zendframework/zend-eventmanager/src/EventManager.php(490): call_user_func(Object(Closure), Object(Zend\Mvc\MvcEvent))
#6 app/vendor/zendframework/zend-eventmanager/src/EventManager.php(260): Zend\EventManager\EventManager->triggerListeners('dispatch', Object(Zend\Mvc\MvcEvent), Object(Closure))
#7 app/vendor/zendframework/zend-mvc/src/Controller/AbstractController.php(116): Zend\EventManager\EventManager->triggerEventUntil(Object(Closure), Object(Zend\Mvc\MvcEvent))
#8 app/vendor/zendframework/zend-mvc/src/DispatchListener.php(118): Zend\Mvc\Controller\AbstractController->dispatch(Object(Zend\Http\PhpEnvironment\Request), Object(Zend\Http\PhpEnvironment\Response))
#9 [internal function]: Zend\Mvc\DispatchListener->onDispatch(Object(Zend\Mvc\MvcEvent))
#10 app/vendor/zendframework/zend-eventmanager/src/EventManager.php(490): call_user_func(Array, Object(Zend\Mvc\MvcEvent))
#11 app/vendor/zendframework/zend-eventmanager/src/EventManager.php(260): Zend\EventManager\EventManager->triggerListeners('dispatch', Object(Zend\Mvc\MvcEvent), Object(Closure))
#12 app/vendor/zendframework/zend-mvc/src/Application.php(340): Zend\EventManager\EventManager->triggerEventUntil(Object(Closure), Object(Zend\Mvc\MvcEvent))
#13 app/vendor/zendframework/zend-test/src/PHPUnit/Controller/AbstractControllerTestCase.php(282): Zend\Mvc\Application->run()
#14 app/test2/Test2.php(38): Zend\Test\PHPUnit\Controller\AbstractControllerTestCase->dispatch('/')
#15 [internal function]: Test2->testIndexCanBeAccessed()
#16 app/vendor/phpunit/phpunit/src/Framework/TestCase.php(1062): ReflectionMethod->invokeArgs(Object(Test2), Array)
#17 app/vendor/phpunit/phpunit/src/Framework/TestCase.php(913): PHPUnit_Framework_TestCase->runTest()
#18 app/vendor/phpunit/phpunit/src/Framework/TestResult.php(686): PHPUnit_Framework_TestCase->runBare()
#19 app/vendor/phpunit/phpunit/src/Framework/TestCase.php(868): PHPUnit_Framework_TestResult->run(Object(Test2))
#20 app/vendor/phpunit/phpunit/src/Framework/TestSuite.php(733): PHPUnit_Framework_TestCase->run(Object(PHPUnit_Framework_TestResult))
#21 app/vendor/phpunit/phpunit/src/Framework/TestSuite.php(733): PHPUnit_Framework_TestSuite->run(Object(PHPUnit_Framework_TestResult))
#22 app/vendor/phpunit/phpunit/src/TextUI/TestRunner.php(517): PHPUnit_Framework_TestSuite->run(Object(PHPUnit_Framework_TestResult))
#23 app/vendor/phpunit/phpunit/src/TextUI/Command.php(186): PHPUnit_TextUI_TestRunner->doRun(Object(PHPUnit_Framework_TestSuite), Array, true)
#24 app/vendor/phpunit/phpunit/src/TextUI/Command.php(116): PHPUnit_TextUI_Command->run(Array, true)
#25 app/vendor/phpunit/phpunit/phpunit(52): PHPUnit_TextUI_Command::main()
我们使用自己的自定义会话处理程序,下面是它的read()方法:

我们尝试执行的测试只是主页上的一个简单访问:

/** @test */
    public function testIndexCanBeAccessed()
    {   
           
        $this->dispatch('/');  
        $this->assertResponseStatusCode(200);
        $this->assertControllerClass('IndexController:class');
    }
但是,由于上述错误,不会执行断言并在分派时停止

另外,在许可范围内,我们只在运行phpunit时使用“sudo”。另一个用户被设置为应用程序文件夹/文件的所有者

我希望您能帮助我们继续执行测试

/** @test */
    public function testIndexCanBeAccessed()
    {   
           
        $this->dispatch('/');  
        $this->assertResponseStatusCode(200);
        $this->assertControllerClass('IndexController:class');
    }