phpunit

Best practices to test protected methods with PHPUnit (on abstract classes)

折月煮酒 提交于 2019-12-17 22:16:30
问题 With PHPUnit and PHP >= 5.3 it is possible to test protected methods. The following page at stackoverflow outlined the best practice on it: "Best practices to test protected methods with PHPUnit" protected static function callProtectedMethod($name, $classname, $params) { $class = new ReflectionClass($classname); $method = $class->getMethod($name); $method->setAccessible(true); $obj = new $classname($params); return $method->invokeArgs($obj, $params); } To test public methods on abstract

Installing PEAR and PHPUnit with xampp

為{幸葍}努か 提交于 2019-12-17 22:07:26
问题 I am trying to get PHPUnit up and running the following are the steps I am currently following: ### Install new PEAR Version needed for PHPUnit 3.X ### Download: http://pear.php.net/go-pear.phar Save it under C:\xampp\php Open a command prompt and go to C:\xampp\php Type "php go-pear.phar" (Installs new PEAR) Type "pear update-channels" (updates channel definitions) Type "pear upgrade --alldeps" (upgrades all existing packages and pear) Type "pear channel-discover components.ez.no" (this is

PhpUnit failing in PhpStorm w/ exit code 255 in Symfony 2 project

丶灬走出姿态 提交于 2019-12-17 20:58:09
问题 I'm having trouble getting phpunit working inside of a Symfony project in PhpStorm - phpunit -c app works fine in the OSX terminal. Here is the error: Unable to attach test reporter to test framework of test framework quit unexpectedly /Applications/MAMP/bin/php/php5.4.4/bin/php/private/var/folders/4l/hw8g4qlj6nnc37lfkc6hcj7w0000gn/T/ide-phpunit.php --bootstrap /Users/greg/Repos/MyApp/app/bootstrap.php.cache --configuration /Users/greg/Repos/MyApp/app/phpunit.xml.dist MyApp\MyBundle\Tests

How to test for expected headers?

落爺英雄遲暮 提交于 2019-12-17 18:57:30
问题 I have a unit test that fails because headers are already sent. However, the header in this scenario is expected. How do I tell PHPUnit to expect a 500 header? I've read this question but it didn't help. The method is wrapped inside an output buffer. ob_start(); $foo->methodWhichSendsHeader(); ob_clean(); 回答1: If you have xdebug installed you can use xdebug_get_headers() to get the headers. Then you can test them as needed. $headers=xdebug_get_headers(); gets you an array which looks like...

PHPUnit via Composer and PhpStorm

一世执手 提交于 2019-12-17 17:45:15
问题 I'm now trying for hours to setup PhpStorm for unit testing. Whatever I do, I get this Process finished with exit code 1 Cannot find PHPUnit in include path ... PHPUnit is (via command line) accessible from anywhere; I've set the correct include path and have added PHPUnit to the external libraries. No chance. Is it possible at all or does it only work with installations via PEAR? I've worked through all related questions here, am on Mac and PHPUnit is running smoothly via CLI. 回答1: Patrick

Fatal Error - Too many open files

落爺英雄遲暮 提交于 2019-12-17 17:44:36
问题 I try to run PHPUnit Tests in my new machine and I get this error: PHP Fatal error: Uncaught exception 'UnexpectedValueException' with message 'RecursiveDirectoryIterator::__construct(/usr/lib/php/pear/File/Iterator): failed to open dir: Too many open files' in /usr/lib/php/pear/File/Iterator/Factory.php:114 The same code on the old machine run well... New machine environment: PHP Version: PHP 5.3.21 (cli) Older: PHP 5.3.14 PHPUnit output every time: ...............

Testing Abstract Classes

╄→尐↘猪︶ㄣ 提交于 2019-12-17 17:33:09
问题 How do I test the concrete methods of an abstract class with PHPUnit? I'd expect that I'd have to create some sort of object as part of the test. Though, I've no idea the best practice for this or if PHPUnit allows for this. 回答1: Unit testing of abstract classes doesn't necessary mean testing the interface, as abstract classes can have concrete methods, and this concrete methods can be tested. It is not so uncommon, when writing some library code, to have certain base class that you expect to

Install phpunit on windows

拜拜、爱过 提交于 2019-12-17 17:26:45
问题 How to install phpunit? I read documentation https://github.com/sebastianbergmann/phpunit, but have an error: >pear upgrade PEAR Nothing to upgrade >pear config-set auto_discover 1 config-set succeeded >pear install pear.phpunit.de/PHPUnit No releases available for package "pear.phpunit.de/PHPUnit" install failed How can I fix this error? 回答1: Try the following instructions: In the command prompt, switch to the directory that you installed PHP to by running cd C:\php\ Then install PEAR by

PHPUnit best practices to organize tests

北城以北 提交于 2019-12-17 17:20:03
问题 I am currently going to start from scratch with the phpunit tests for a project. So I was looking into some projects (like Zend) to see how they are doing things and how they organizing their tests. Most things are pretty clear, only thing I have some problems with is how to organize the test suites properly. Zend has an AllTests.php from which loads others test suites. Tough looking at the class it is useing PHPUnit_Framework_TestSuite to create a suite object and then add the other suites

global variables are null when using PHPUnit

橙三吉。 提交于 2019-12-17 16:35:43
问题 I am putting PHPUnit testing into an existing project. Global constants variables are used extensively. In my unit test functions are failing because the global variables are null. Here is an example of a failing test static $secret_key = "a secret Key"; class secret_key_Test extends PHPUnit_Framework_TestCase { function test_secret_key() { global $secret_key; $this->assertEquals($secret_key, "a secret Key"); } } >> Failed asserting that 'a secret Key' matches expected null Any help would be