All Questions

54
votes
9answers
50430 views

Mock private method with PHPUnit

I have a question about using PHPUnit to mock a private method inside a class. Let me introduce with an example: class A { public function b() { // some code $this->c(); // some mo...
217
votes
8answers
81420 views

Best practices to test protected methods with PHPUnit

I found the discussion on Do you test private method informative. I have decided, that in some classes, I want to have protected methods, but test them. Some of these methods are static and short. Be...
34
votes
4answers
11113 views

Reaching 100% Code Coverage with PHPUnit

I've been in the process of creating a test suite for a project, and while I realize getting 100% coverage isn't the metric one should strive to, there is a strange bit in the code coverage report to ...
37
votes
5answers
45553 views

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($user...
17
votes
2answers
9304 views

Can't install PHPUnit via PEAR, requires PEAR Installer >= 1.9.2, can't upgrade PEAR from 1.9.0

I read the other PHPUnit installation questions but haven't had any success. What is going on with my PEAR install? $ sudo pear update-channels Updating channel "components.ez.no" Channel "components...
38
votes
3answers
21826 views

unit testing and Static methods

Reading up and picking up on unit testing, trying to make sense of the following post on that explains the hardships of static function calls. I don't clearly understand this issue. I have always a...
45
votes
6answers
15476 views

Mock in PHPUnit - multiple configuration of the same method with different arguments

Is it possible to configure PHPUnit mock in this way? $context = $this->getMockBuilder('Context') ->getMock(); $context->expects($this->any()) ->method('offsetGet') ->with...
59
votes
10answers
13912 views

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 look...
125
votes
12answers
28005 views

SimpleTest vs PHPunit

I was wondering if anyone that have experience in both these stuff can shed some light on the significant difference between the two, if any? Any specific strength of each that makes it suitable for ...
188
votes
10answers
89022 views

PHPUnit assert that an exception was thrown?

Does anyone know whether there is an assert or something like that which can test whether an exception was thrown in the code being tested?

Previous Next