Jump to content

Perform functional tests


Recommended Posts

As we know, to perform the unit tests in general is used phpunit https://phpunit.de/

But for functional tests?


For example, let's consider the following script


+ cat bin/example-script

require "src/App.php";

* @return string Application output.
function main(): string {
	$app = new App;
	// --- BEGIN CONFIG ---
	// ...
	// ...
	// ...
	// --- END CONFIG ---
	$output = $app->run(); # RETURN: "Helo world!!!"
	return $output;

echo main() . PHP_EOL; # ECHO: "Helo world!!!" . PHP_EOL
exit(123); # EXIT CODE: 123


We highlight some lines


+ grep '# ' bin/example-script
	$output = $app->run(); # RETURN: "Helo world!!!"
echo main() . PHP_EOL; # ECHO: "Helo world!!!" . PHP_EOL
exit(123); # EXIT CODE: 123

Request 1

I want to test that the output is the desired one: "Helo world!!!" . PHP_EOL

Request 2

I want to test that the exit code is the desired one: 123


How can it be done?

Is there a recommended practice?

Edited by rick645
Link to comment
Share on other sites

In general, functional testing of web apps involves some sort of tool that can either simulate a browser (Codeception, Testing Library)  or integrate with one (Selenium, Watir).  They are specifically built to deal with browser clients.

For testing of CLI programs, there aren't a lot of options out there that I'm familiar with, but one that you can look at is cli-testing-library  

Confusingly there is another library worth looking at with the same name.

Either library should allow you to write and run functional tests for the outcomes you described, but also provide ways for providing input, options and interaction.

Let us know if one or the other worked out for you. 

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.