Love Fuel?    Donate

FuelPHP Forums

Ask your question about FuelPHP in the appropriate forum, or help others by answering their questions.
Functional Tests?
  • I know FuelPHP can play nicely with PHPUnit and can be invoked via oil. I've already written unit tests for a CouchDB package I've created. I'm curious if the framework provides any methods or helpers for doing functional tests for testing controllers? Perhaps something that "fakes" a request to the application and provides various additional assertions for web-related testing. If not, how do other people test their controllers?
  • All these tools are great and definitely have a place in every applications testing stack. They don't truly fill the void of no functional tests however.
  • Hi, PHPUnit supports functional tests.. if you check http://www.phpunit.de/manual/current/en/selenium.html It explains how to use PHPUnit with Selenium.. On your fuelphp tests classes just extend from \PHPUnit_Extensions_SeleniumTestCase instead of just TestCase And add to fuel/core/bootstrap_phpunit.php // Import the Extensions_SeleniumTestCase
    import('seleniumtestcase'); It will include the extension on load. Example of a unit test class: class WebTest extends \PHPUnit_Extensions_SeleniumTestCase
    {
    protected function setUp()
    {
    $this->setBrowser('*firefox');
    $this->setBrowserUrl('http://www.example.com/');
    } public function testTitle()
    {
    $this->open('http://www.example.com/');
    $this->assertTitle('Example WWW Page');
    }
    } I would apreciate any improvements to this post as I'm just starting to learn fuel. Have fun.
  • Functional tests for controller methods are going to be complex if not impossible using an automated test tool like PHPUnit. For some controllers (those that require no input and produce static pages) you could get away with using PHPUnit and some complicated assertions with lots of data, but for most controllers, that is not an option. You could look at Selenium (http://seleniumhq.com) which provides you with a toolset to automate browser interaction with a web application. It allows you to test the application flow, but also the response to actions, up to the placement of html elements on your page.
  • Just wanted to add, that depending on your platform of choice, there may even be graphical testing tools, that are actually easy and fun to use. If you have a Mac, for instance, you can have a look at: http://fakeapp.com/
  • Sorry.. totally forgot: to do the trick.. a class must be added fuel/core/classes/ file: seleniumtestcase.php contents: namespace Fuel\Core;
    class SeleniumTestCase extends \PHPUnit_Extensions_SeleniumTestCase { } For sure there is better ways of doing this.. Cheers.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

In this Discussion