Installation of wamp php Unit Test Tool PHPUnit under Windows and Configuration Method of Generating Log File

  • 2021-10-13 07:00:02
  • OfStack

This paper describes the installation of wamp php unit test tool PHPUnit under Windows and the configuration method of generating log files. Share it for your reference, as follows:

phpunit download website http://www.phpunit.cn/

1. Install PHPUnit

1. Choose a version

I'm using php version 5.6. 25, so I chose PHPUnit 5.7

2. Installation process

① Create a directory for the binary executable files of PHP, for example C:\ bin

2. Will; C:\ bin appended to PATH environment variable "php's directory; E:\ wamp64\ bin\ php\ php5.6. 25 also appended to PATH environment variable"

③ Download phpunit. phar and save the file to C:\ bin\ phpunit.phar

④ Open the command line of CMD

⑤ Create an outer wrapping batch script (C:\ bin\ phpunit.cmd file will be automatically generated in the last bin directory):


C:\Users\username> cd C:\bin
C:\bin> echo @php "%~dp0phpunit.phar" %* > phpunit.cmd
C:\bin> exit

⑥ "Note that downloaded 1 is generally phpunitx-y. phar, with version number, so the version number should be removed and the file name should be changed to phpunitx. phar"

⑦ Open a new CMD command line window, and confirm that PHPUnit can be executed in any path under 1:


C:\bin>phpunit --version
PHPUnit 5.7.19 by Sebastian Bergmann and contributors.

2. Testing with PHPUnit

Create the file StackTest. php in the C:\ bin directory


<?php
use PHPUnit\Framework\TestCase;
 class StackTest extends TestCase
 {
  public function testPushAndPop()
  {
   $stack = [];
   $this->assertEquals(0, count($stack));
   array_push($stack, 'foo');
   $this->assertEquals('foo', $stack[count($stack)-1]);
   $this->assertEquals(1, count($stack));
   $this->assertEquals('foo', array_pop($stack));
   $this->assertEquals(0, count($stack));
  }
 }
?>

Conduct a test


C:\bin>phpunit StackTest.php
PHPUnit 5.7.19 by Sebastian Bergmann and contributors.
.                 1 / 1 (100%)
Time: 543 ms, Memory: 13.00MB
OK (1 test, 5 assertions)

3. Configuration method of phpunit generating three log files

# Directory structure windows

Under the bin directory

(phpunit. phar)
(phpunit. cmd)
(phpunit. xml)
(build. xml)
(ArrTest. php)
tmp
logfile. json
(logfile. tap)
logfile. xml

# Log XML file configuration New file build. xml placed in root directory


<logging>
<log type="json" target="tmp/1ogfile.json"/>
<log type="junit" target="tmp/logfile.xml" logIncompleteSkipped="false"/>
<log type="tap" target="tmp/logfile.tap"/>
</logging>

# Command

* Generate log files in xml format


phpunit --log-junit tmp/logfile.xml ArrTest.php

* Generate log files in tap format


phpunit --log-tap tmp/logfile.tap ArrTest.php

* Generate log files in json format


phpunit --log-json tmp/logfile.json ArrTest.php

For more readers interested in PHP related content, please check the topics on this site: "Summary of PHP Error and Exception Handling Methods", "Summary of php String (string) Usage", "Encyclopedia of PHP Array (Array) Operation Skills", "Summary of PHP Operation and Operator Usage", "Summary of PHP Network Programming Skills", "Introduction to PHP Basic Syntax", "Introduction to php Object-Oriented Programming" and "Summary of php Excellent Development Framework"

I hope this article is helpful to everyone's PHP programming.


Related articles: