phpunit

PHPUnit: Test an abstract class without concrete methods

Hi all, I've following abstract class and have a question about how to write a unit test for this. Is this in fact needed? As this class doesn't have any concrete methods. <?php abstract class PickupPoint_Abstract { public function __construct($client) {} public function getPickupPoints($countryCode, $postalCode, $city) {} ...

PHPUnit: Test an an factory class with a dependency

Hi all, I've got following factory class which has a dependency $client. I moved the dependency to the factory class as it first occurred in Service_Service1 class so I could test the service class. But how can I test the factory class? class Factory implements Service { public static function factory($service) { $conf...

How to change database connection on the fly for PhpUnit tests.

I am working on a Magento 1.4.1 project, and I want to use PhpUnit to test my models. I am able to run my PhpUnit test using the default connection, but I want to use a different database connection than the one I use to test the interface. What I would like to know (if its possible): Is there a way to select a different connection f...

How to use Firefox on Win from Selenium-rc on Linux

I am using phpunit 3.4.15. On Centos 5.3 linux I started Selenium server 1.0.3: java -jar selenium-server.jar I would like to call a browser running on Windows to run the test. This is the script I try to run: <?php require_once 'PHPUnit/Extensions/SeleniumTestCase.php'; class Example extends PHPUnit_Extensions_SeleniumTestCase { ...

Using janrain's OpenId php libs' test scripts. (PHPUnit)

I'm trying to run the test scripts that come with JanRain's php openid libraries. I've installed PHPUnit using pear. When I try to run the scripts I get: Fatal error: Class 'PHPUnit_Framework_TestCase' not found in /var/www/localhost/htdocs/openid/openid/Tests/Auth/OpenID/StoreTest.php on line 72 I'm sure this is a really simple ...

Installed PHPUnit Via PEAR But Cannot Find PHPUnit.bat To Add To Netbeans

Hi. i installed PHPUnit via pear and cannot find the phpunit.bat file to add to the path in netneans. Where should it be? My pear dir is c:/server/xampp/php/PEAR ...

Using PHPUnit on a Zend Framework application, how can I force the locale to be used for a given test?

I am testing a multi-lingual site with phpunit. One of the tests I want to perform is that the application will detect the locale of the user and automatically redirect. That is, user accesses the site on /. The application detects they're from France and redirects to /fr-FR/ The application does appear to do this, but trying to wri...

How would you test this code? (phpUnit)

How would you test the following code with phpUnit? class Product { protected $id = null; public function __construct($id) { $this->id = $id; } public function getDescription($language_id) { $db_query = mysql_query("SELECT * FROM products_description WHERE products_id = " . (int) $this->id . " AND lang...

How to execute code after trigger_error(..., E_USER_WARNING) in unit test (PHPUnit)?

I have code like this: class ToBeTested { function simpleMethod($param) { if(0 === $param) { trigger_error("Param is 0!", E_USER_WARNING); return false; } return true; } } and test for this code: class SimpleTest extends PHPUnit_Framework_TestCase { function testSimpleMethod() { $toBeTest...

Refactoring of model for testing purpose

Hi All, I want to refactor my model so I can properly write a unit test for it. But I have some dependencies. Can anybody point me in the right direction how I can remove these dependencies? class Customer { public function save(array $data, $id = NULL) { // create or update if (empty($id)) { $custom...

Is there a way to disable code coverage in PHPUnit for a single test?

Every time I run a single unit test in PHPUnit, a code coverage report is also generated. I have an older computer here at work, and if I could disable the code coverage when I don't need it, that would put less strain on my CPU. Is there a way to disable the code coverage on a per-test basis? I couldn't find any command-line switch tha...

Why is my unit test failing via Hudson/Phing, but succeeding via Phing on the command line?

General Info: PHP 5.3.3 PHPUnit 3.4 Zend Framework 1.10.8 Phing build target <target name="test"> <echo msg="PHPUnit..." /> <phpunit codecoverage="false" haltonfailure="true" haltonerror="true" printsummary="true" bootstrap="${testdir}/application/bootstrap.php"> <batchtest> <fileset dir="${testdir}"> <include name=...

PHPUnit Test How Many Times A Function Is Called

I'm working on a test in phpunit and I'm running into an issue. I have a public function on my class that I am trying to test. Depending on the parameters passed in to the method, a protected function also in my test class will be called one or two times. I currently have a test in place to check that the return data is correct, but I...

PHPUnit error with AddDirectoryToFilter

Hello Everyone, I am again trying to work on a TDD (Test Driven Design) way. So I installed my PHPUnit again to work with my ZendFramework application. After running my testSuite I get this following error message: (...) test: [exec] PHP Notice: Please no longer include "PHPUnit/Framework.php". in /usr/share/php/PHPUnit/Framewor...

phpUnit & Ant unrecognized option --log-xml

Hello, I am trying to automate my testing procedure using Ant. This is my error: test: PHPUnit 3.5.0 by Sebastian Bergmann. unrecognized option --log-xml /var/www/nrka2/build/build.xml:30: exec returned: 1 BUILD FAILED (total time: 1 second) And this is my build.xml <?xml version="1.0" encoding="UTF-8"?> <project name="eventManager...

Errors in PHPUnit itself

PHP Notice: Please no longer include "PHPUnit/Framework.php". in /usr/share/php/PHPUnit/Framework.php on line 50 Fatal error: Class 'PHPUnit_Runner_StandardTestSuiteLoader' not found in /usr/share/php/PHPUnit/TextUI/TestRunner.php on line 434 PHP Fatal error: Class 'PHPUnit_Runner_StandardTestSuiteLoader' not found in /usr/share/p...

Errors when testing with PHPUnit 3.5

Hello, After installing phpUnit 3.5 i am trying to run my tests this way: phpunit AllTests.php But I am getting the following errors: PHP Fatal error: Class 'PHPUnit_TextUI_TestRunner' not found in /usr/share/php/PHPUnit/TextUI/Command.php on line 140 Fatal error: Class 'PHPUnit_TextUI_TestRunner' not found in /usr/share/php/PHPUni...

The xdebug extension is not loaded

Hi guys, I've got xdebug installed fine (showing up in phpinfo()) but I'm trying to get it to work with PHPUnit's code coverage functionality. It keeps telling me "The XDebug extension is not loaded". I've got phpunit working fine with WAMP. When i run php -m i don't see xdebug listed in neither php modules nor zend modules which point...

Using Selenium to determine whether checkboxes with a specific class are checked

I'm using Selenium with PHPUnit to try to tell whether a bunch of checkboxes with a specific class are checked and I'm having a bit of trouble. My code: $count = $this->getXpathCount('//form//input[@type="checkbox" and @class="required"]'); for ($i = 1; $i <= $count; $i++) { $this->assertTrue($this->isChecked(sprintf('xpath=//form/...

Simple PHP Selenium test doesn't work

I have the following Selenium test in PHP: <?php require_once('PHPUnit/Extensions/SeleniumTestCase.php'); class Example extends PHPUnit_Extensions_SeleniumTestCase { protected function setUp() { $this->setBrowser("*chrome"); $this->setBrowserUrl("http://change-this-to-the-site-you-are-testing/"); } public function tes...