Home >Backend Development >PHP Tutorial >Solutions to problems in phpunit testing

Solutions to problems in phpunit testing

jacklove
jackloveOriginal
2018-06-09 10:51:101269browse

Today we are going to set up a local LAMP development environment, because the system’s built-in PHP version is 5.5.14, but the development environment needs to be php 5.6 or above, so php 5.6.7 is installed. This results in two versions of php existing in the system.

There is no problem in normal development, but if phpunit is used, phpunit will call the system's own php 5.5.14 for execution. The PHP extensions I installed (such as memcache, redis, etc.) are all installed on the version of PHP 5.6.7.

When using phpunit for unit testing, you will be prompted that the extension is not installed. (e.g. memcache function not found).

The php called by phpunit is /usr/bin/php, so pointing the php at this location to the currently used php5.6.7 version can solve the problem.

The solution is as follows:

1. Check the currently used php version

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. Check the version of /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. Change /usr/ Back up the version of bin/php, you can restore it when there is a problem

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

4. Delete /usr/bin/php

sudo rm /usr/bin/php

5. Create /usr/bin/php softlink pointing to php5.6.7 php

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

6. Check/ Has usr/bin/php been updated?

/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

After execution, the problem is solved.

This article explains how to solve problems in phpunit testing. For more related content, please pay attention to the php Chinese website.

Related recommendations:

php str_replace Explanation of the method of replacing a specified number of times

About header, headers_sent, headers_list, header_remove usage instructions

##Querying mysql through PDO returns the field integer type into String type Solution

The above is the detailed content of Solutions to problems in phpunit testing. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn