phpunit

PHPStorm + PHPUnit Color output

♀尐吖头ヾ 提交于 2019-12-21 17:24:00
问题 So I have PHPUnit running in PHPStorm 7.1, but I can't find out how to get the ANSI color codes working from within tests. My PHPunit.xml has colors = "true" in the property list, but every time I try something like: echo "\033[31mError! Error!\033[0m\n"; Inside one of my test cases, it just gives me: [31mError! Error![0m in the PHPstorm phpunit output. Is there any way to make the colors appear properly when using ANSI color codes in tests in PHPStorm? 回答1: PhpStorm has special integration

Slow PHPUnit Tests

风流意气都作罢 提交于 2019-12-21 16:59:13
问题 I am running PHPUnit to test a CodeIgniter application using CIUnit (a third party interface between the two). A number of the tests select data from an empty MySQL database that is populated with 5-10 records in setUp(). On Windows and the web server (Ubuntu 10.04/Apache 2.2/MySQL 5.1/PHP 5.3), the 105 tests run in 2-3 seconds with a memory usage of around 30mb. On my local (Ubuntu 12.04/Apache 2.2/MySQL 5.5/PHP 5.3), the 105 tests run with the same memory usage, but take approx 45 seconds.

How to use PHPUnit's setExpectedException()?

拜拜、爱过 提交于 2019-12-21 15:24:19
问题 With PHPUnit I can successfully test if a specific call to a class properly throws an exception like this: try { $dummy = Import_Driver_Excel::get_file_type_from_file_name('BAD_NAME.nnn'); } catch (Exception $ex) { return; } $this->fail("Import_Driver_Excel::get_file_type_from_file_name() does not properly throw an exception"); But I read here that there is a simpler way , basically in one line using setExpectedException() : class ExceptionTest extends PHPUnit_Framework_TestCase { public

How to unit test calls to Google API

房东的猫 提交于 2019-12-21 12:49:40
问题 I have a following method, which retrieves top visited pages from Google Analytics: public function getData($limit = 10) { $ids = '12345'; $dateFrom = '2011-01-01'; $dateTo = date('Y-m-d'); // Google Analytics credentials $mail = 'my_mail'; $pass = 'my_pass'; $clientLogin = Zend_Gdata_ClientLogin::getHttpClient($mail, $pass, "analytics"); $client = new Zend_Gdata($clientLogin); $reportURL = 'https://www.google.com/analytics/feeds/data?'; $params = array( 'ids' => 'ga:' . $ids, 'dimensions' =>

Making PHPUnit ignore things?

非 Y 不嫁゛ 提交于 2019-12-21 12:41:18
问题 I have a PHPUnit Test class that I'd like to be ignored from a test run. I know I can do it by renaming it so that it doesn't contain the word Test in its filename, but I'd rather not do that since it muddies up the source control waters more than I'd like. Does anyone have a suggestion? 回答1: There are a couple of options for the phpunit command that can help define which tests should and should not be run : $ phpunit --help PHPUnit 3.4.0beta5 by Sebastian Bergmann. Usage: phpunit [switches]

PHPUnit Code Coverage

风流意气都作罢 提交于 2019-12-21 07:24:18
问题 I am learning the ropes with Unit testing Zend Framework applications. So far I have set up PHPUnit to work with Zend Framework and have started writing some simple Test Cases. My issue is that I am wondering why Code Coverage does not work in spite of being set in the logging tag in my phpunit.xml . I don't get any error but no coverage report is generated. However it works when I run phpunit --coverage <dir> The logging section of my phpunit is as below: <phpunit bootstrap="./application

PhpStorm PHPUnit testreporter error

回眸只為那壹抹淺笑 提交于 2019-12-21 07:13:25
问题 I have installed PHPUnit via Composer and set it up to run the unit tests with my installation through settings. But when I run the tests I get the following error for the test reporter (the tets executes just fine): Unable to attach test reporter to test framework or test framework quit unexpectedly 回答1: You should point to your vendor/autoload.php at Settings | PHP | PHPUnit when using PHPUnit via Composer. This blog post has all the details (with pictures) to successfully configure IDE for

Testing File uploads in Symfony2

妖精的绣舞 提交于 2019-12-21 07:06:09
问题 In the Symfony2 documentation it gives the simple example of: $client->request('POST', '/submit', array('name' => 'Fabien'), array('photo' => '/path/to/photo')); To simulate a file upload. However in all my tests I am getting nothing in the $request object in the app and nothing in the $_FILES array. Here is a simple WebTestCase which is failing. It is self contained and tests the request that the $client constructs based on the parameters you pass in. It's not testing the app. class

Mockery - call_user_func_array() expects parameter 1 to be a valid callback

自作多情 提交于 2019-12-21 06:58:29
问题 I have a class I need to mock: class MessagePublisher { /** * @param \PhpAmqpLib\Message\AMQPMessage $msg * @param string $exchange - if not provided then one passed in constructor is used * @param string $routing_key * @param bool $mandatory * @param bool $immediate * @param null $ticket */ public function publish(AMQPMessage $msg, $exchange = "", $routing_key = "", $mandatory = false, $immediate = false, $ticket = null) { if (empty($exchange)) { $exchange = $this->exchangeName; } $this-

PHPUnit doesn't continue test after expecting an exception

ぃ、小莉子 提交于 2019-12-21 06:50:30
问题 Why doesn't PHPUnit do last exception assertion in this code? public function testConfigOverriding() { $this->dependencyContainer = new DependencyContainer(__DIR__ . "/../../Resources/valid_json.json"); $this->assertEquals('overriden', $this->dependencyContainer->getConfig('shell_commander')['pygmentize_command']); $unexisting = "unexisting_file"; $this->setExpectedException('Exception', "Configuration file at path \"$unexisting\" doesn't exist."); $this->dependencyContainer = new