rick645 Posted September 18 Share Posted September 18 (edited) 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 #!/usr/bin/php <?php require "src/App.php"; /** * @return string Application output. */ function main(): string { $app = new App; // --- BEGIN CONFIG --- $app->setProperty1( // ... ); $app->setProperty2( // ... ); $app->setProperty3( // ... ); // --- 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 September 18 by rick645 Quote Link to comment Share on other sites More sharing options...
rick645 Posted Monday at 05:47 AM Author Share Posted Monday at 05:47 AM UPPPPPPPPPPPP Quote Link to comment Share on other sites More sharing options...
gizmola Posted 2 hours ago Share Posted 2 hours ago 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. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.