I have a test suite for my cakephp web app using the cakephp phpunit wrapper provided in 2.x. I would love to merge my test suite into production and be able to test periodically in production via a test database. My issue is as followed:
CakePHP uses a file called test.php to run the test suite and index.php to run the site. I want to lock access to my test suite behind our administrative login, because I don't want anyone to be able to run my test suite on our site just by navigating to www.myapp.com/test.php
I cannot find any information about how to do this. Its possible that no one is doing this because this is a bad strategy that I have propose. If that is the case, could someone please direct me to a better cakephp testing strategy. Sorry, I'm new to building tests.
Thank you to anyone that can help.
Don't use the web test suite but use the command line instead. See "Running tests from the command line".
cake test
Also running tests on a production system might not be a good idea either as it can put some load on the server and the site might respond very slow while the tests run.
If you run the tests via command line you can use the command "nice" and set how much CPU load the command you're going to execute is allowed to cause.
Here we set up a server that we run right next to production called development. These two servers are exact matches (I hope...) and we run our test suite from there. I still run them through the browser, but I agree that the command line works as describe by #burzum. Testing on live is a bad idea. It could mess things up and is not worth the risk for us.
Related
I am currently creating an automated test website where all codeception test logs can be shown. My server runs codeception through cron but the user should be able to run the test manually. My question is can I use codeception class in a php webpage without executing the commandline version? If possible anyone have an idea how?
Yes you can, it is actually also quite simple. Codeception uses the symfony console component for their command line tool. Take a look at the \Codeception\Command\Run::execute() method on how they do it. It can be a bit overwhelming at first glance, but in the end it boils down to this piece of code:
$this->codecept = new Codecept($userOptions);
if ($suite and $test) {
$this->codecept->run($suite, $test);
}
I'm trying to find specific information on how to setup Selenium with PHP bindings in a 'client-server' type of setup. I'm not even sure if what I want is possible, but I will try to do my best to describe the objective of what I am trying to achieve.
I do QA on a Web development project, where we are working with distributed team members. We need automated front end testing, and have decided that (due to a number of factors) Selenium makes the best candidate for the job.
Our team is specialized in PHP, so it makes sense to use Selenium with PHP bindings.
My biggest challenge is:
1) How do I install those PHP bindings?
2) How do I create and execute a Selenium script in PHP? This one might seem obvious, but I need to know if I need to create some sort of 'project' in PHP, or whether this requires different steps. Manuals are very clear and detailed when it concerns the default JAVA bindings, but hopelessly lacking on the PHP bindings.
3) How do I do all this, while wanting to invoke a test from a client, but having it executed by a 'server/VM'? (Keeping in mind that if the possibility were there, I would also like to be able to create tests on the server, that can execute/invoke testing activities on the desktop of the client.)
4) How do I setup a server that meets all requirements to run Selenium Server with PHP bindings?
The objective is to be able to initially create a VM (probably a Vagrant box) that would contain Selenium Server (and if needed other components) with the actual test scripts, which can be shared among team members.
This VM should both be able to execute headless tests, but ideally should also be able to drive tests on the host (if at all possible).
Technically it should support the scenario where QA finds an issue in the product, and should be able to just specify the required script to reproduce it. The developer that has the task to fix the issue should only have to run the script on his machine to actually reproduce the found error.
Eventually we would want to migrate the VM to an actual server, hence the reason we want to set it up like this from the start. This will keep things more simple once we are ready to move to a physical server.
I've been looking all over the internet for detailed documentation, but in just about any documentation many assumptions are made about already configured and set up environments. I really need a step by step explanation of how to set things up.
PHPUnit seems a bit of a weird choice to pair with Selenium, since they both cover completely different areas of testing. I have seen (again incomplete) instructions on the PHPUnit site, but that seems very clunky and our development team is not very keen on this setup.
We have people suggesting Jenkins, but I personally do not see how Jenkins would eliminate the normal setup of Selenium, which one has to go through from the start anyway.
I already have Selenium Server running as a service in a VM, I just need to know what else I need, and how I need to set it up, how to configure it. how to make things communicate, etc.
Any help/ideas would be highly appreciated.
To get this running locally, follow the instructions here:
https://github.com/facebook/php-webdriver#getting-started
Here is a sample PHP webdriver script that you can use. It will open firefox, take you to google's page and submit a search query:
// you'll need to modify this path so it points to the composer autoloader
require_once __DIR__ . '/vendor/autoload.php';
/**
* since I'm running the selenium jar locally, this is all I need.
* I just run it in the background and my php scripts connect to it and
* the tests
*/
$host = 'http://localhost:4444/wd/hub';
$driver = RemoteWebDriver::create($host, DesiredCapabilities::firefox());
$driver->get('http://google.com');
$element = $driver->findElement(WebDriverBy::name('q'));
$element->sendKeys('Cheese');
$element->submit();
Is this the sort of detail you're looking for?
I have a Codeigniter framework on place, which I'm building a test framework on top of it.
Once of the features of the test framework is to remotely deploy test suits. Therefore, I'm trying to deploy a Python test suit I wrote from the webpage:
public function deploy_test()
{
if( !$this->input->is_cli_request() ) {
echo json_encode(system("python test_suit.py"));
}
}
from my controller, so, when a test deployed, I want to run it. For proof of concept I did that way. However, the job never get deployed, nor is the command line ever executed.
When I ran that piece of code from the terminal, it works as supposed. What am I missing here?
Thank you
** Its curious to mention when I execute ls -l it works ...
Basically, this is a bad idea - if the host has declined access to executing things on the server (after all, how does it know that your code is not malicious), you really shouldn't try to work around this, at least without speaking to your provider and asking them if they're ok for you to do this!
After all, executing an LS isn't really going to be malicious, but you could try and execute a Python script that 'rm -rf's the server.
Now, you might be able to find a work around, but to my mind, the question is should you? They might interpret this as a hacking attempting.
This question already has answers here:
Closed 10 years ago.
Possible Duplicate:
“Web interface” to PHPUnit tests?
Are there any PHP unit testing systems that have a browser-based graphical interface to run the tests in (similar to this : http://view.jquery.com/tags/1.3.2/test/)?
All the unit test options I have looked at allow you to run them from the command line but have not seen any (or could not find documentation on how to) that allow you to somehow run them from the browser. I ask because I don't have access to the command line on the server I would need to run unit tests from.
Update:
In the end I decided to stick with PHPUnit. SimpleTest does have what I was looking for but PHPUnit is the defacto standard in PHP unit testing. I end up switching IDE from PhpED to PhpStorm and PhpStorm has a nice feature of being about to display PHPUnit test results that run on a remote server like ReSharper does for C#/Visual Studio.
SimpleTest does that:
http://www.simpletest.org/en/first_test_tutorial.html
I haven't tested it, but maybe you should try this:
http://mattmueller.me/blog/phpunit-test-report-unit-testing-in-the-browser
This sounds a bit difficult, since the browser is not able to run php natively, I would guess that there would be a php page that would trigger the running of the tests and return an html with the results.
I would suggest you run your tests locally and if you want to get even higher fidelity setup a server/virtual machine that very closely resembles the setup you have in your production server, but that grant's you access to the console and use it as your continuos integration server.
Is there a simple "Web interface" to running PHPUnit test suites? i.e. a PHP script that runs the test on the command line, and outputs a nicely formatted HTML result.
I develop web applications, and the day-to-day workflow usually switches between the IDE and the browser. I would like to have the unit testing in the same environment.
I'm looking for something really simple and PHP based - I am planning to get into phpUnderControl (which has the functionality I'm looking for) but not yet.
I recently discovered Visual PHPUnit which looks like a very very nice interface for everyone that doesn't want to run PHPUnit from the command line:
It seems to be the next iteration of #Matt's PHPUnit Test Report
I feel your frustration - I'm a UI guy myself. Looking at the terminal too long makes my head spin. I wrote a quick little application that you might find helpful.
(source: mattmueller.me)
You can find it here: http://mattmueller.me/blog/introducing-phpunit-test-report
Cheers!
Matt
After several hours of researching recently, the best PHPUnit web frontend I have come across was https://github.com/NSinopoli/VisualPHPUnit
You can use phing to run a PHPUnitTask and then convert the output with:
PHPUnitReport - This task transforms PHPUnit xml reports to HTML using XSLT.
Example:
<phpunitreport infile="reports/testsuites.xml"
format="frames"
todir="reports/tests"
styledir="/home/phing/etc"/>
See phpunit --help for the various output formats.
The 2.3 version of PHPUnit had a chapter on this, but it is gone for some time now. You might be able to find an old copy with Google somewhere.
Since you mention this is for phpUnderControl: if you are not fixed on that, consider using Jenkins and http://jenkins-php.org.
On a side note: unless we are talking CI servers, most people I know don't use PHPUnit through a web interface. They either just use the command line or their IDE integration.
You can use Jenkins to run any kind of tasks including PHPUnit tests. It can automatically checkout your app, run the tests, build a HTML report and even email you if the build fails.
Here's the templates you need to setup Jenkins to build a bunch of interesting reports and stats from your project.
If you don't care about reformatting the output and just want to run PHPUnit from a web page, you can do so with some PHP code like this:
<pre>
<?php
$argv[0] = "phpunit.phar";
$argv[1] = '--bootstrap';
$argv[2] = 'src/load.php';
$argv[3] = "tests/MoneyTest";
$_SERVER['argv'] = $argv;
include 'phpunit.phar';
?>
</pre>
The file src/load.php is just a bunch of includes to include the classes. The output then looks like this:
#!/usr/bin/env php
PHPUnit 4.1.2 by Sebastian Bergmann.
........................
Time: 122 ms, Memory: 3.25Mb
OK (24 tests, 43 assertions)
Just ignore that first line and you can see the results.
I'm shocked that PHPUnit does not include a basic way to do this. Some classes may be dependent on the web server. Do we just not test those? Some sites have you upload your files and don't allow command line executions.
I've never seen such a web-interface... But, as you say you are always using your IDE and your webbrowser, why not think the other way ?
i.e. a possible solution would be to launch the unittests from your IDE ;-)
Which means you should be able to click on the failing tests to "jump" to either the test method, or the reason that caused the test to fail, for instance.
In the PHP + PHPUnit world, I know that Zend Studio does that -- yes, it's not free, unfortunatly ;-(
Using Eclipse PDT, a solution would be to register PHPUnit as an external tool (see or instance this blogpost : Using PHPUnit with Eclipse PDT) -- but it's quite not sexy, and you cannot click on the results to jump the the methods/tests...
Another solution would be to develop a plugin to integrate PHPUnit into Eclipse PDT (like it's been done for Zend Studio, I suppose) -- A phpunit4eclipse was created some time ago, but it's just a start, and didn't get much succes, so the author didn't work on it after releasing that...
I found this:
I stumbeld upon a post from Parth Patil, whose solution was to create an xml-report from PHPUnit and then use this xml to create your own report.
I used his solution, made it PHPUnit 3.4 compatible and also added some Reflection to see my testcase doc-comments in the report. (Note: For the refelection i use the Zend_Framework reflection class)
Ok you said you'd prefer an independent IDE solution, but just so you know there is a recent plugin that enables executing PHPUnit simply into Eclipse, and having a nice representation (like in Zend Studio, but for free).
Here is the link, the main developper replies fast to emails too if you have a problem :
http://www.phpsrc.org/wiki/
I personnaly tested some web interface, but I have always been deceived (not really practital and stable). But this is your choice.
jframework also has a nice UI for PHPUnit. It breaks the results, and shows test coverage on all files and each file separately.
It works on both web and cli, with the cli one having the benefit of dumping every test after its done (the web-based one has to wait until everything is over).
You can always use the Maven for PHP from which you can use the surefire reports (mvn site).
More info here: http://www.php-maven.org