简体   繁体   English

如何使用 phpunit 批量测试多个文件?

[英]How can i batch testing several file with phpunit?

I've several php files, which each one declare the same class name.我有几个 php 文件,每个文件都声明了相同的类名。 I want to test all of them into a single phpunit batch, but i get "Fatal error: you cannot redeclare class" :(我想将它们全部测试到单个 phpunit 批处理中,但我收到“致命错误:您无法重新声明类”:(

Anyway to do batch testing ?无论如何要做批量测试? Or i've to test file per file ?或者我必须测试每个文件的文件?

Thanks.谢谢。

I'm not so sure to understand your problem.我不太确定理解你的问题。 Yet, here's what I'm doing for batch unit testing (hoping it will help you).然而,这就是我正在做的批量单元测试(希望它会帮助你)。

For batch unit testing a .bat script with all my unit test class listed like this (run_unit_test.bat):对于批处理单元测试 .bat 脚本,其中列出了我所有的单元测试类,如下所示 (run_unit_test.bat):

@ECHO OFF

CLS


ECHO.
ECHO FILE : AUTOMATIC_BACKUP_MANAGER_TEST.PHP
ECHO.
CALL PHPUNIT %~DP0/TEST/AUTOMATIC_BACKUP_MANAGER_TEST.PHP
ECHO.
ECHO.

Then I'm using Dos command (in Xampp console, not working for me in normal dos console) like the following to send the result to a text file (I use PHP to read the text file and display it).然后我使用 Dos 命令(在 Xampp 控制台中,在普通的 dos 控制台中不适用于我),如下所示将结果发送到文本文件(我使用 PHP 读取文本文件并显示它)。

C:\xampp\htdocs\PC_administration_interface\Controler/temp_unit_test.bat > C:\xampp\htdocs\PC_administration_interface\Controler/test_result.txt

For automatic testing, I use the task scheduler to call that script:对于自动测试,我使用任务调度程序来调用该脚本:

@echo off

call C:\xampp\htdocs\PC_administration_interface\Controler\launch_xampp.bat

call C:\xampp\xampp_shell.bat

cls

call C:\xampp\htdocs\PC_administration_interface\Controler\run_unit_test.bat > "C:\xampp\htdocs\PC_administration_interface\Controler\test_result.txt"

Here's the Launch xampp script:这是启动 xampp 脚本:

@echo off
tasklist | find /i "xampp-control.exe" && goto :eof

start /b "xampp-control.exe" "C:\xampp\xampp-control.exe"

The xampp_shell script launch the command prompt with all xampp configuration (you'll have this by default if you use Xampp that is). xampp_shell 脚本使用所有 xampp 配置启动命令提示符(如果您使用的是 Xampp,则默认情况下您将拥有此配置)。

In the task scheduler I'm running two operations.在任务调度程序中,我正在运行两个操作。 This one two run the script (start program in program/script textbox):这两个运行脚本(在程序/脚本文本框中启动程序):

C:\xampp\htdocs\PC_administration_interface\Controler\launch_automatic_test.bat

And this one to open a new tab in chrome to display the result:而这个在 chrome 中打开一个新标签来显示结果:

"C:\Program Files (x86)\Google\Chrome\Application\chrome.exe"

With something like this in the add argument textbox:在添加参数文本框中使用类似的内容:

http://localhost/PC_administration_interface/view/unit_test.php?DISPLAY_RESULT=TRUE

Beyond that solution, you probably should use "require_once" command to be sure that the declaration is really declared only once.除了该解决方案之外,您可能应该使用“require_once”命令来确保声明实际上只声明了一次。

Also, it is probably a good practice to declare one unit testing class for each of your class (and only include one class per file except for constant classes used to emulate enum).此外,为每个类声明一个单元测试类可能是一种很好的做法(并且每个文件只包含一个类,用于模拟枚举的常量类除外)。

Like I said, I'm not so sure to understand your problem.就像我说的,我不太确定理解你的问题。 You might need to provide us code sample if my solution doesn't work.如果我的解决方案不起作用,您可能需要向我们提供代码示例。

Most humbly,最谦虚,

Jonathan Parent-Lévesque from Montreal来自蒙特利尔的 Jonathan Parent-Lévesque

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM