Integrating Codeigniter 2 with phpspec2

江枫思渺然 提交于 2019-12-23 03:14:11

问题


I want to integrate phpspec2 with CodeIgniter 2. I've succesfully installed phpspec using composer as described on phpspec website. Now I'd like to integrate it into my CodeIgniter 2 installation. I've found an article by AniDear on this subject and did everything as described. However when I run bin/phpspec I get an error:

PHP Warning: require(core/Common.php): failed to open stream: No such file or directory 
in  C:\xampp\htdocs\eljotengine\spec\ci_bootstrap.php on line 37

Warning: require(core/Common.php): failed to open stream: No such file or directory in C:\xampp\htdocs\eljotengine\spec\ci_bootstrap.php on line 37

and so on. My file structure looks like this:

eljotengine
|-application
|-sytem
|- ... other CI
|-spec
| |- ci_bootstrap.php

I am using xampp on Windows 7. My ci_bootstrap.php file looks like the one in the above mentioned article by AniDear.

I've tried to change the paths in the ci_bootstrap.php file (it seems to be the problem) however it did not change much.

Any ideas how to make this work?

Greets :)


回答1:


I am having problem with PHPSpec2 too. Since I have only tried it with PHPSpec (not PHPSpec2), I would suggest you to install PHPSpec instead. Just change the file composer.json, on the line "phpspec/phpspec2": "*" to "phpspec/phpspec": "*" , then runs composer update again.

Run this phpspec, by using command vendor\bin\phpspec.php.bat spec on your project path, whereas "spec" is the folder containing spec files.

And since you're running phpspec from your project directory, I suggest changing content inside ci_bootstrap.php as follow

define('BASEPATH',realpath('system/').'/'); //set absolute path to CI system/
define('APPPATH', 'application/'); //set relative path to CI application
set_include_path(
    get_include_path().PATH_SEPARATOR.
    realpath(APPPATH).PATH_SEPARATOR.
    realpath(BASEPATH).PATH_SEPARATOR.
    'spec');  //adding 'spec' in path, for easily do require 'ci_bootstrap.php' from inside spec files

require BASEPATH.'core/Common.php';
require APPPATH.'config/constants.php';
require BASEPATH.'core/Controller.php';


来源:https://stackoverflow.com/questions/13649408/integrating-codeigniter-2-with-phpspec2

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!