howto: run tests in browser

Notice: This thread is very old.
petrb
Member | 8
+
0
-

Could you please give a short example on how to run the tests in browser?

My current approach is to rename *.phpt to *.php and add <?php echo "<pre>"; ?> on the beginning to make test result readable in browser

greeny
Member | 405
+
0
-

One question – why do you need to run tests in browser?

petrb
Member | 8
+
0
-

not possible to use CLI on webservers. The tester docs is talking about supporting both CLI and browser, waiting for someone who knows how to use the second one

greeny
Member | 405
+
0
-

Well then why dont you clone the project to your local machine and run tests there?

petrb
Member | 8
+
0
-

because local machine environment is different than webservers. if we agree that we can enumerate all posibilities how to do it “the other way”, then how to do it as the question and manual says, with browser?

Jan Tvrdík
Nette guru | 2595
+
+3
-

You need to configure web server to process PHP in *.phpt files and then you can just open it in a browser. Because tests usually do not output anything you don't need to add <pre> or change content type to text/plain.

Milo
Nette Core | 1283
+
+2
-

As @JanTvrdík wrote, the best way is to configure Apache/Nginx to handle *.phpt too. If not possible, do it by some script with only require 'path/to/test.phpt';. But be careful about security. The purpose is just to run test file as an ordinary PHP script.

In test's bootstrap, you can distinguish between current environments and do setup (Content-Type for example):

if (getenv(Tester\Environment::RUNNER)) {
    # Running by Tester (e.g. vendor/bin/tester tests/MyTest.phpt)
} elseif (PHP_SAPI === 'cli') {
    # Running as ordinary CLI script (e.g. php tests/MyTest.phpt)
} else {
    # Browser
}