Rumah  >  Artikel  >  pembangunan bahagian belakang  >  关于phpunit测试出现问题的解决方法

关于phpunit测试出现问题的解决方法

jacklove
jackloveasal
2018-06-09 10:51:101193semak imbas

今天要搭建本机的LAMP开发环境,因系统自带的php版本是5.5.14,但开发要使用的是php 5.6以上,因此安装了php 5.6.7。这样导致了系统中有两个版本的php存在。

正常开发是没有问题的,但如果使用了phpunit,phpunit会调用系统自带的php 5.5.14来执行。而我安装的php扩展(例如memcache,redis等)都是安装在php 5.6.7的那个版本上。

使用phpunit做单元测试时,会提示扩展没有安装的情况。(例如memcache function not found)。

phpunit 调用的php是/usr/bin/php,因此把这个位置的php指向现在使用的php5.6.7版本即可解决问题。

解决方法如下:

1.查看当前使用的php版本

php -v
PHP 5.6.7 (cli) (built: Apr 20 2015 23:10:47) (DEBUG)
Copyright (c) 1997-2015 The PHP Group
Zend Engine v2.6.0, Copyright (c) 1998-2015 Zend Technologies
    with Xdebug v2.3.2, Copyright (c) 2002-2015, by Derick Rethans

2.查看/usr/bin/php的版本

/usr/bin/php -v
PHP 5.5.14 (cli) (built: Sep  9 2014 19:09:25) 
Copyright (c) 1997-2014 The PHP Group
Zend Engine v2.5.0, Copyright (c) 1998-2014 Zend Technologies

3.把/usr/bin/php的版本备份,当有问题时可以恢复

sudo cp /usr/bin/php /usr/bin/php55

4.把/usr/bin/php删除

sudo rm /usr/bin/php

5.创建/usr/bin/php softlink 指向php5.6.7的php

sudo ln -s /usr/local/Cellar/php56/5.6.7/bin/php /usr/bin/php

6.检查/usr/bin/php 是否已更新

/usr/bin/php -v
PHP 5.6.7 (cli) (built: Apr 20 2015 23:10:47) (DEBUG)
Copyright (c) 1997-2015 The PHP Group
Zend Engine v2.6.0, Copyright (c) 1998-2015 Zend Technologies
    with Xdebug v2.3.2, Copyright (c) 2002-2015, by Derick Rethans

执行后,问题解决。

本文讲解了关于phpunit测试出现问题的解决方法 ,更多相关内容请关注php中文网的。

相关推荐:

php str_replace 替换指定次数方法 的讲解

关于header,headers_sent,headers_list,header_remove 使用说明

通过PDO 查询mysql返回字段整型变为String型的解决方法

Atas ialah kandungan terperinci 关于phpunit测试出现问题的解决方法. Untuk maklumat lanjut, sila ikut artikel berkaitan lain di laman web China PHP!

Kenyataan:
Kandungan artikel ini disumbangkan secara sukarela oleh netizen, dan hak cipta adalah milik pengarang asal. Laman web ini tidak memikul tanggungjawab undang-undang yang sepadan. Jika anda menemui sebarang kandungan yang disyaki plagiarisme atau pelanggaran, sila hubungi admin@php.cn