Automated testing of PHP 7 extension

Source: Internet
Author: User
: This article mainly introduces the automated test of PHP 7 extension. For more information about PHP tutorials, see. During the installation of PHP 7 and various extensions, if you use the source code for installation, you will notice that after make is successful, there will always be a prompt: Don't forget to run 'Make test '. this make test is an automated test for running PHP.

If you have just installed PHP7 and run make test directly, after a long wait, the final statistical result is like this:

There will be so many skips and fail that some extensions are not installed, and the configuration of the relevant environment needs to be optimized.

However, we generally do not need to run so many test scripts, especially for a single extension, we can test the related interfaces, so let's look at how to run the test script independently.

First open the php Makefile file. let's see what make test has done.

test: all        @if test ! -z "$(PHP_EXECUTABLE)" && test -x "$(PHP_EXECUTABLE)"; then \                INI_FILE=`$(PHP_EXECUTABLE) -d 'display_errors=stderr' -r 'echo php_ini_loaded_file();' 2> /dev/null`; \                if test "$$INI_FILE"; then \                        $(EGREP) -h -v $(PHP_DEPRECATED_DIRECTIVES_REGEX) "$$INI_FILE" > $(top_builddir)/tmp-php.ini; \                else \                        echo > $(top_builddir)/tmp-php.ini; \                fi; \                INI_SCANNED_PATH=`$(PHP_EXECUTABLE) -d 'display_errors=stderr' -r '$$a = explode(",\n", trim(php_ini_scanned_files())); echo $$a[0];' 2> /dev/null`; \                if test "$$INI_SCANNED_PATH"; then \                        INI_SCANNED_PATH=`$(top_srcdir)/build/shtool path -d $$INI_SCANNED_PATH`; \                        $(EGREP) -h -v $(PHP_DEPRECATED_DIRECTIVES_REGEX) "$$INI_SCANNED_PATH"/*.ini >> $(top_builddir)/tmp-php.ini; \                fi; \                TEST_PHP_EXECUTABLE=$(PHP_EXECUTABLE) \                TEST_PHP_SRCDIR=$(top_srcdir) \                CC="$(CC)" \                        $(PHP_EXECUTABLE) -n -c $(top_builddir)/tmp-php.ini $(PHP_TEST_SETTINGS) $(top_srcdir)/run-tests.php -n -c $(top_builddir)/tmp-php.ini -d extensi/modules/ $(PHP_TEST_SHARED_EXTENSIONS) $(TESTS); \                TEST_RESULT_EXIT_CODE=$$?; \                rm $(top_builddir)/tmp-php.ini; \                exit $$TEST_RESULT_EXIT_CODE; \        else \                echo "ERROR: Cannot run tests without CLI sapi."; \        fi

Don't worry about the definition of those variables. The core content is the following sentence:

$(PHP_EXECUTABLE) -n -c $(top_builddir)/tmp-php.ini $(PHP_TEST_SETTINGS) $(top_srcdir)/run-tests.php -n -c $(top_builddir)/tmp-php.ini -d extensi/modules/ $(PHP_TEST_SHARED_EXTENSIONS) $(TESTS);

The original automatic test is carried out by executing the run-tests.php under the PHP source code root directory, the test script is generally placed under the tests folder

Open the./tests/basic file in the php installation directory. there are some phpt files, which are the test scripts one by one.

The content in some scripts is very simple. the content in 001. phpt is like this.

--TEST--Trivial "Hello World" test--FILE--
  --EXPECT--Hello World

Next, run 001. phpt.
First, you need to set the relevant environment variables to specify the PHP object to be tested. here, the main user uses the installation path
Php

Export TEST_PHP_EXECUTABLE =/usr/local/php7/bin/php

Run the following command in the php installation root directory:

Php run-tests.php./tests/basic/001. phpt

The following results can be obtained without an accident.

In this way, we can write a script to specify the phpt to be tested and calculate the final result.

OneAPM for PHP can go deep into all PHP applications to complete application performance management. it can go deep into all PHP applications to complete application performance management and monitoring, including visibility of code-level performance problems, fast identification and tracing of performance bottlenecks, Real User Experience Monitoring, server monitoring, and end-to-end application performance management. For more technical articles, visit the OneAPM official technical blog.

This article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.