资讯专栏INFORMATION COLUMN

phpunit 安装

microelec / 1558人阅读

摘要:所以使用下载安装的方式。解决了,但警告还在,而且没有正常运行。从警告信息发现可以访问的目录包括,刚好即在变量中,也属于可以被脚本读取的目录,于是再运行,得到正确结果安装成功

官方指引

很遗憾, phpunit还没有在ArchLinux的仓库里。

所以使用下载安装的方式。按照官方的指引:

wget https://phar.phpunit.de/phpunit.phar
chmod +x phpunit.phar
sudo mv phpunit.phar /usr/local/bin/phpunit
phpunit --version

结果得到下面的错误:

PHP Warning:  realpath(): open_basedir restriction in effect. File(/usr/local/bin/phpunit) is not within the allowed path(s): (/srv/http/:/home/:/tmp/:/usr/share/pear/) in /usr/local/bin/phpunit on line 3
PHP Fatal error:  Class "Phar" not found in /usr/local/bin/phpunit on line 714
启用phar扩展

先解决Fatal error: Class "Phar" not found

ls /usr/lib/php/modules

发现有 phar.so,说明Phar的扩展已经安装,那么是不是该扩展没有Enable呢?
打开 /etc/php/php.ini搜索 phar,果然发现 extension=phar.so被注释掉了。去掉该行前面的 ;,保存php.ini,再次运行 phpunit --version

PHP Warning:  realpath(): open_basedir restriction in effect. File(/usr/local/bin/phpunit) is not within the allowed path(s): (/srv/http/:/home/:/tmp/:/usr/share/pear/) in /usr/local/bin/phpunit on line 3
PHP Warning:  Phar::mapPhar(): open_basedir restriction in effect. File(/usr/local/bin/phpunit) is not within the allowed path(s): (/srv/http/:/home/:/tmp/:/usr/share/pear/) in /usr/local/bin/phpunit on line 714

Fatal error解决了,但警告还在,而且phpunit没有正常运行。

php对文件访问的保护机制

google之,发现这里有解释: http://www.templatemonster.com/help/open_basedir-restriction-in-effect-filex-is-not-within-the-allowed-paths-y.html

  

PHP open_basedir protection tweak is a Safe Mode security measure that prevents users from opening files or scripts located outside of their home directory with PHP, unless the folder has specifically excluded. PHP open_basedir setting if enabled, will ensure that all file operations to be limited to files under certain directory, and thus prevent php scripts for a particular user from accessing files in unauthorized user’s account. When a script tries to open a file with, for example, fopen() or gzopen(), the location of the file is checked. When the file is outside the specified or permissible directory-tree, PHP will refuse to open it and the following errors may occur: ...

意思是说:php.ini中的open_basedir是php为保证安全进行文件访问的设置。如果该选项被赋值,所有的文件操作将限定在特定的目录里,这样可以防止某个用户使用php脚本读取未授权的内容。当你想通过fopengzopen打开一个文件时,如果该文件的位置不再被允许的目录下面,就会出现上述的警告信息。

从警告信息发现可以访问的目录包括 /srv/http/:/home/:/tmp/:/usr/share/pear/,刚好 ~/bin即在PATH变量中,也属于可以被php脚本读取的目录,于是

mv /usr/local/bin/phpunit ~/bin

再运行phpunit --version,得到正确结果:

PHPUnit 4.5.0 by Sebastian Bergmann and contributors.

phpunit安装成功!

文章版权归作者所有,未经允许请勿转载,若此文章存在违规行为,您可以联系管理员删除。

转载请注明本文地址:https://www.ucloud.cn/yun/20938.html

相关文章

  • phpUnit 安装,实例和简单部署

    背景:一个小脚本,保证稳定为主;所以试用了下phpunit,快捷方便 phpunit 的安装 phpunit是一个轻量级的php单元测试框架,通过pear安装安装过程 wget https://phar.phpunit.de/phpunit.phar chmod +x phpunit.phar sudo mv phpunit.phar /usr/local/bin/phpunit phpunit ...

    617035918 评论0 收藏0
  • PHP单元测试框架PHPUnit的使用

    摘要:以前在学习开发时有专门写过的单元测试的文章,开发学习之单元测试,今天再总结下怎么在中使用单元测试。是一个用编程语言开发的开源软件,是一个单元测试框架。单元测试框架经常会包含每个测试的报告,以及给出你已经覆盖到的代码覆盖率。 以前在学习IOS开发时有专门写过Objective-C的单元测试的文章,IOS开发学习之单元测试,今天再总结下怎么在PHP中使用单元测试。 一、前言 在这篇文章中,...

    Bryan 评论0 收藏0
  • PHP 单元测试

    摘要:上面的规定是必须遵守的,如果代码没有遵守规定不会把他当做单元测试代码。每个单元测试类以被测试的类名开头。每个单元测试函数应该为被测试函数名结尾。函数可能在测试环境不可执行,那么无法获取的执行结果,从而无法对进行单元测试。 本文首发于 https://jaychen.cc/article/34作者 Jaychen showImg(https://segmentfault.com/img/...

    娣辩孩 评论0 收藏0
  • phpunit入门

    摘要:安装安装教程参考说明下安装那个盘符无所谓下如果不定义全局变量,可以进入所在目录才能执行,例如当然配环境变量,全局配置操作更方便一点全局配置,配置环境变量的路径是建立外包覆批处理脚本最后得到官方教程里面第五步的所在路径配置配置参考例如核心 安装 安装教程参考 说明 windows下安装那个盘符无所谓 windows下如果不定义全局变量,可以进入phpunit.phar所在目录才能执行...

    ls0609 评论0 收藏0
  • Laravel 测试: PHPUnit 入门教程

    摘要:介绍是最古老和最著名的单元测试包之一。它主要用于单元测试,这意味着可以用尽可能小的组件测试代码,但是它也非常灵活,可以用于很多不仅仅是单元测试。这时,的测试助手可以使这些测试像单元测试简单组件一样容易。新的测试代码如下注意到,在我们新建的 showImg(https://segmentfault.com/img/remote/1460000018355157?w=1440&h=585)...

    张宪坤 评论0 收藏0

发表评论

0条评论

microelec

|高级讲师

TA的文章

阅读更多
最新活动
阅读需要支付1元查看
<