phpunit
Mocks vs Stubs in PHPUnit
PHPUnit used to support two ways of creating test doubles out of the box. Next to the legacy PHPUnit mocking framework we could choose prophecy as well. Prophecy support was removed in PHPUnit 9, but it can be added back by installing phpspec/prophecy-phpunit. PHPUnit Mocking Framework The createMock method is used to create three mostly … Read more
PHPUnit – does nothing, no errors, no output
I’m on OSX and MAMP. To get error messages I had to adjust the following entries in php.ini: display_errors = On display_startup_errors = On Please not that this has to go into /Applications/MAMP/bin/php/php5.3.6/conf/php.ini .
Remove “Remaining deprecation notices” in Symfony 2.8
Finally found the solution ! Just add <php> <env name=”SYMFONY_DEPRECATIONS_HELPER” value=”weak” /> </php> to your phpunit.xml (or any other file that you use to configure phpunit)
How to force a failure with phpunit
I believe this should work within a test case: $this->fail(‘Message’);
How to install an older version of PHPUnit through PEAR?
You need to know the exact version number you wish to downgrade to. At the time of writing, the last release you’re after is 3.3.17, which can be found out by checking the appropriate PEAR channel. To downgrade to that particular version execute two commands: pear uninstall phpunit/PHPUnit pear install phpunit/PHPUnit-3.3.17
PHPUnit mock objects and method type hinting
Update Oh, actually, the problem is pretty simple, but somehow hard to spot. Instead of: $observer = $this->getMock(‘SplObserver’, array(‘update’)) ->expects($this->once()) ->method(‘update’); You have to write: $observer = $this->getMock(‘SplObserver’, array(‘update’)); $observer->expects($this->once()) ->method(‘update’); That’s because getMock() returns a different thing than method(), that’s why you got the error. You passed the wrong object to attach. Original answer … Read more
Why does phpunit not show any errors in the console
This is a very common issue, especially when you are running tests on a production server or when the tester isn’t very aware of the PHP configuration. The issue is related to php.ini settings, as pointed by Alexander Yancharuk in his answer and all the solutions he suggests work fine. But there is another solution … Read more
How to exclude files / code blocks from code coverage with Netbeans / PHPStorm / PHPUnit integration
To ignore method code blocks: /** * @codeCoverageIgnore */ function functionToBeIgnored() { // function implementation } To ignore class code blocks: /** * @codeCoverageIgnore */ class Foo { // class implementation } And as @david-harkness said, to ignore individual lines: // @codeCoverageIgnoreStart print ‘this line ignored for code coverage’; // @codeCoverageIgnoreEnd More information can by … Read more