phpunit

PHPUnit Test Question - How to Unit test my class

Hi, I'm trying to get into Unit testing for the obvious positives it introduces, and I'm trying to write a Unit test for a class I wrote the other day. (I know this is the opposite to TDD, please bear with me) My class, Image, is used in conjunction with some others for image manipulation. Image essentially wraps a GD image resource ...

(Hopefully Simple) Question about Unit test seperation

Hi, This question is related to PHPUnit, although it should be a global xUnit design question. I'm writing a Unit test case for a class Image. One of the methods of this class is setBackgroundColor(). There are 4 different behaviors I need to test for this method, Trying to set an invalid background color. Multiple invalid paramete...

How to assert link href value using Zend_Test without an DOMXPath error

Hi, What is the best way to verify that a link with a specific url and content exists on a tested page? I'm using Zend_Test and the following simplified example works fine until there is a dot (".") in the url, which obviously can happen very often... This is OK: $this->assertQueryContentContains('a[href="/index"]', 'Home'); Now if...

Autotest equivalent for PHP?

I have been using autotest for unit testing in ruby. Is there an equivalent for PHP that will run my unit tests after my code has been updated? I am using PHPUnit and Eclipse. ...

phpunit xdebug reporting

Hi there. I am trying to produce an html report of some tests using PHPUnit, Selenium and Xdebug. I run the test like so: phpunit --coverage-html ./report blah.php But the report generated is somewhat lacking in information and it doesn't seem to coincide with the official documentation here. I just get a green bar with "100.00% | ...

Creating Mock object of Interface with type-hint in method fails on PHPUnit

I created the following interface: <?php interface Action { public function execute(\requests\Request $request, array $params); } Then I try to make a Mock object of this interface with PHPUnit 3.4, but I get the following error: Fatal error: Declaration of Mock_Action_b389c0b1::execute() must be compatible with that of Action::e...

How do I run phpunit command in Windows command line no matter what directory I am in?

all examples of phpunit I saw run the simple command line tool: phpunit TestClass but when I try the same on a directory other than the xampp php dir, I end up getting an "unknown command..." Is there a way to execute the phpunit command from any directory in the Windows command line? ...

Cygwin and PHPUnit: Could not open input file: /cygdrive/c/xampp/php/phpunit

Hello, Is there a way to run PHPUnit from Cygwin? Everytime I run PHPUnit I get this error: Could not open input file: /cygdrive/c/xampp/php/phpunit I am trying to run my unit tests in my Zend Framework App. I am trying to use Cygwin because I am more familiar with *Nix commands (I'm no expert though) rather than Windows. Thanks, We...

PHP-CodeBrowser not following path in checkstyle.xml correctly

I've set up phpUnderControl and it's all working very well, except that for a few projects that I have aren't getting any output in the PHP-CodeBrowser tab. If I run the command manually I get: phpcb --log projects/devvo/build/logs --source projects/devvo/source --output projects/devvo/build/php-code-browser Generating PHP_CodeBrowser...

phing versus phpunit codecoverage results

I have created a build.xml file for phing to create code coverage reports. It uses phpunit codecoverage="true" and is pointed to the same file(s) as done with phpunit --coverage-html. The result differ, however. With phing I have 100% code coverage for all files, which I have not. There is probably something I don't know about running...

Testing Zend Framework controllers that return HTML5

I have a controller test case that looks like the following: class LoginControllerTest extends Zend_Test_PHPUnit_ControllerTestCase { public function testLoginFormIsShown() { $this->dispatch('/login'); $this->assertQuery('form#login'); } } However our site is written using HTML5 and contains elements like <...

How to make a general profile for PHPUnit testing in WebIDE?

I'm playing a bit with beta version of PHP Storm (PHP version of WebIDE) and its integration of PHPUnit. I know how to set a profile to run tests in particular file, directory or class. Problem is, I'd like to create some profile where Run button would run tests in currently opened file. Any idea if there's a way to do it? Or perhaps it...

PHPUnit - testing file inclusion methods (include, require, require_once)

I'm writing and testing a ClassLoader component, which can be instantiated many times, with various mappings between class names and their relevant paths. Each ClassLoader should work as a loader for a specific package. Is there an easy, unobtrusive way to test or mock inclusion of files handled by the ClassLoader? Let me clarify with ...

PEAR/PHPUnit installation on shared hosting

I’ve installed a local (per-account) PEAR instance on shared web-hosting. After that I’ve installed PHPUnit. It doesn’t work in command-line mode because PHPUnit classes are not under default include_path that is ".:/usr/local/lib/php". The same, I think, would happen with local phing and other command-line tools installed via PEAR. Is...

PHPUnit Mock Objects and Static Methods

I am looking for the best way to go about testing the following static method (specifically using a Doctrine Model): class Model_User extends Doctrine_Record { public static function create($userData) { $newUser = new self(); $newUser->fromArray($userData); $newUser->save(); } } Ideally, I would use...

Can I "Mock" time in PHPUnit?

... not knowing if 'mock' is the right word. Anyway, I have an inherited code-base that I'm trying to write some tests for that are time-based. Trying not to be too vague, the code is related to looking at the history of an item and determining if that item has now based a time threshold. At some point I also need to test adding someth...

PHPUnit, superglobal vars. How to setup test such that $_SERVER and $_GET are properly set?

Hi All, I am writing some PHP code to parse incoming URLs. It relies heavily on PHP globals such as $_SERVER and $_GET. I am thinking of manually setting these up in PHPUnit unit test setUp() function. Is there a better way of doing this? thanks, G ...

A strange bug, is Mysql asynchronous?

Hello, I have a strange bug. I launch a PHP Unit test Suite. At the beginning, it executes a big query to initialize the database. If I put a breakpoint just after the execution of the sql, there is no problem and my tests pass. If I don't put any break point, they don't pass and say that the tables don't exist! It works as if the s...

How to set a variable within a mock object

Is there any way to set a class level variable within a mock object? I have the mock object set similar to this: $stub = $this->getMock('SokmeClass', array('method')); $stub->expects($this->once()) ->method('method') ->with($this->equalTo($arg1)); Win the real class there is a variable that needs to be set for it to...

Would you consider this a proper test case?

I would like to get some feedback on what is one of my first PHPUnit test cases. The subject of the tests is a simple configuration class in a PHP app. It is used to create, store and retrieve configuration settings. The settings are stored in an array within the class. Each setting has the following properties: key (for example fro...