Tag Archives: phpunit

Assert that a function gets called

When testing with phpunit, I want to assert a function call:
Given a Class:

Class TimeWrapper {
  public function time() {
    return time();
  }
}

And Its unittest:

Class TimeWrapperTest extends PHPUnit_FrameworkTestCase {
  public function testTime() {
    //Pseudocode as example 

Continue reading

Tagged , | Leave a comment

phpunit testing with ajax and zend framework

i have a problem with writing tests for my action that gets called by jquery via ajax. i don’t know how to catch the data that is being sent back to the view, by the action, so that i could… Continue reading

Tagged , , , | Leave a comment

ZF + PHPUnit: How to assert existence of html elements within ajax response?

Should I extend the ControllerTestCase and create a custom method to handle this? What is the best way?… Continue reading

Tagged , , | Leave a comment

With PHPUnit, using a Data Provider, the last data set always shows “The test case was unexpectedly terminated”

So I’m using PHPUnit for testing. Trying to use a DataProvider with one of my tests.

/**
 * Tests Events_Event->Events_Event()
 * @dataProvider provider
 */
public function testEvents_Event($Name, $param, $time) {
        //$this->assertInstanceOf("Events_Event", $this->Events_Event->Events_Event("test2", array()));
        $this->assertTrue(true);
    }

public static function provider()
    {
        

Continue reading

Tagged , , | 1 Comment

PHPUnit undefined function mysql_connect()

When I try to connect to my MySQL database from PHP code all seems to be fine, all queries are executed successfully. However, when the code is tested with unit tests in PHPUnit, I get the following fatal PHP error:… Continue reading

Tagged , , | Leave a comment

Netbeans “no tests executed”

I have a php project with unit tests included. I use Netbeans for development and would like to have phpunit intergration in my IDE. If I run phpunit from the commandline, it is working. If I press Alt+F6 to run… Continue reading

Tagged , , , | 1 Comment

Failed opening 'SiteTest: Firefox.php' when running Yii Functional Test

Warning: include(): Failed opening 'SiteTest: Firefox.php' for inclusion
... yiiframeworkYiiBase.php on line 418

Yii v1.1.10
PHPUnit v3.6.10
PHPUnit_Selenium v 1.2.6
I get this error when trying to run the example on the book “Agile Web Development with Yii 1.1 and Continue reading

Tagged , , , | Leave a comment

Using YAML Files as data provider in PHPUnit (CIUnit)

I am writing an application using the PHP CodeIgniter Framework. I am trying to test the application using CI_Unit, by extension PHPUnit. To test a model, I am trying to load a YAML data provider as defined in the PHPUnit… Continue reading

Tagged , , , | Leave a comment

How to use Selenium features from Selenium2 class?

I’m using PHPUnit and Selenium in my PHP project.
I have been following instruction at: http://www.phpunit.de/manual/3.6/en/selenium.html. Currently I am able to start Selenium server and I’ve done few test classes extending either PHPUnit_Extensions_Selenium2TestCase or PHPUnit_Extensions_SeleniumTestCase class.
I’ve been using https://github.com/sebastianbergmann/phpunit-selenium/blob/master/Tests/Selenium2TestCaseTest.php… Continue reading

Tagged , , , | Leave a comment

How can I PHPUnit test a Controller_Plugin that uses a Redirector helper to redirect?

I can’t work this out.

    $this->_request->setBasePath('http://localhost/');
    $this->_request->setModuleKey('admin');
    $this->_request->setControllerKey('controller-page');
    $this->_request->setActionKey('index');

    $this->_sslRedirect->preDispatch($this->_request);

    $this->assertRedirectRegex('/https:/');

In my controller plugin preDispatch() may or may not do a redirect to SSL. This works in the browser, however I’m not able to write a test for it. Continue reading

Tagged , , | Leave a comment
13 pages