PHP Mocking Final Class

Since you mentioned you don’t want to use any other framework, you are only leaving yourself one option: uopz uopz is a black magic extension of the runkit-and-scary-stuff genre, intended to help with QA infrastructure. uopz_flags is a function that can modify the flags of functions, methods and classes. <?php final class Test {} /** … Read more

how to unit test curl call in php

As thomasrutter suggested, create a class to abstract the usage of the cURL functions. interface HttpRequest { public function setOption($name, $value); public function execute(); public function getInfo($name); public function close(); } class CurlRequest implements HttpRequest { private $handle = null; public function __construct($url) { $this->handle = curl_init($url); } public function setOption($name, $value) { curl_setopt($this->handle, $name, … Read more

Passing parameters to PHPUnit

You can use PHPUnit’s –bootstrap switch for this. –bootstrap <file> A “bootstrap” PHP file that is run before the tests. Then, make a bootstrap.php file that contains variables: $port = 4445; In your tests, you can grab those values: global $port; $this->setPort($port); Then run: phpunit –bootstrap boot.php MyTest.php

How to exclude file from PHPUnit test suite in xml config?

To exclude the file name TestCase.php. add this to your phpunit.xml <testsuites> <testsuite name=”BLABLA”> <directory suffix=”.php”>./tests</directory> <exclude>./tests/TestCase.php</exclude> </testsuite> </testsuites> Here is an additional excerpt from a real-live test-suite I can confirm it working with: … <testsuites> <testsuite name=”n98-magerun-tests”> <directory>./tests</directory> <exclude>tests/N98/Magento/Command/Installer/UninstallCommandTest.php</exclude> </testsuite> …

PHPUnit’s returnValueMap not yielding expected results

I had the same problem and eventually found out that returnValueMap() has to map all parameters of your function, including optional ones, then the desired return value. Example function from Zend Framework: public function getParam($key, $default = null) { $key = (string) $key; if (isset($this->_params[$key])) { return $this->_params[$key]; } return $default; } Has to mapped … Read more