PHPUnit: How to show more info in testdox output when using data providers
Probably the geekiest and most obscure blog post title I’ll ever write, but we’ll see!
<?php
class DataProviderExampleTest extends PHPUnit_Framework_TestCase
{
/**
* @dataProvider colourStatementsProvider
*/
public function testItemIsCorrectColour($statement, $item, $colour)
{
$parts = explode(' is ', $statement);
$this->assertEquals($parts[0], $item);
$this->assertEquals($parts[1], $colour);
}
public function colourStatementsProvider()
{
return array(
'apple-is-green' => array('apple is green', 'apple', 'green'),
'apple-is-red' => array('apple is red', 'apple', 'red'),
'sky-is-blue' => array('sky is blue', 'sky', 'grey'),
);
}
} |
Now run the test:
% phpunit DataProviderExampleTest.php
PHPUnit 3.4.3 by Sebastian Bergmann.
..F
Time: 0 seconds
There was 1 failure:
1) DataProviderExampleTest::testItemIsCorrectColour with data set "sky-is-blue" ('sky is blue', 'sky', 'grey')
Failed asserting that two strings are equal.
--- Expected
+++ Actual
@@ @@
-blue
+grey
/Users/tim/Desktop/DataProviderExampleTest.php:12
FAILURES!
Tests: 3, Assertions: 6, Failures: 1. |
Here’s the testdox output:
% phpunit --testdox DataProviderExampleTest.php
PHPUnit 3.4.3 by Sebastian Bergmann.
DataProviderExample
[ ] Item is correct colour |
In previous versions of PHPUnit there used to be more info…
in PHPUnit_Util_TestDox_ResultPrinter change the following line (246) from (part of the startTest function)
from:
246
| $this->currentTestMethodPrettified = $this->prettifier->prettifyTestMethod($test->getName(FALSE)); |
to:
246
| $this->currentTestMethodPrettified = $this->prettifier->prettifyTestMethod($test->getName()); |
% phpunit --testdox DataProviderExampleTest.php
PHPUnit 3.4.3 by Sebastian Bergmann.
DataProviderExample
[x] Item is correct colour with data set "apple-is-green"
[x] Item is correct colour with data set "apple-is-red"
[ ] Item is correct colour with data set "sky-is-blue" |
much better.
Published at 2:19 pm on July 16th, 2011
Topic: PHP
Link to this entry (0 comments)
Import Ricoh GX100 RAW files into Apple’s Aperture in MacOS 10.5 Leopard
Here’s a little hack to enable you to use Ricoh GX100 RAW files in Apple’s Aperture.
Make a backup of the following file:
/System/Library/CoreServices/RawCamera.bundle/Contents/Resources/Raw.plist
Find the key for the Leica D-LUX 3 (line 3316 in MacOS 10.5.1):
3316: <key>Leica D-LUX 3</key> <string>Panasonic DMC-LX2</string> <!-- 10.4.10 -->
Then insert the following line before the line showing the Leica D-LUX 3:
3316: <key>RICOH Caplio GX100</key> <string>Panasonic DMC-LX2</string>
3317: <key>Leica D-LUX 3</key> <string>Panasonic DMC-LX2</string> <!-- 10.4.10 -->
You should now be able to use the Ricoh’s RAW files in Aperture.
This is based on a previous hack (detailed here), which doesn’t apply to Leopard.
Published at 5:57 pm on November 16th, 2007
Topic: Apple Mac
Link to this entry (6 comments)
Bristol City Council’s Planning application documents only viewable using Internet Explorer
From Britol City Council’s PublicAccess for Planning page:
Please note that the documents within PublicAccess can only be accessed by using Internet Explorer. This is due to a limitation within the system which has been raised with the suppliers.
Not good enough. Here’s form I knocked-up in about 2 minutes that gives users of other browsers access to associated planning documents. The associated documents are things like supporting letters, photographs, a copy of the application form etc.
Enter a planning application number to view any supporting documents.
Published at 10:43 am on August 1st, 2007
Topic: Bristol
Link to this entry (2 comments)
ActionScript trim function
ActionScript 2.0 doesn’t have a trim function to strip whitespace from the start and end of a string. Here’s a simple function I wrote because I couldn’t find a satisfactory example on Google!
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
| function trim(str:String):String
{
var stripCharCodes = {
code_9 : true, // tab
code_10 : true, // linefeed
code_13 : true, // return
code_32 : true // space
};
while(stripCharCodes["code_" + str.charCodeAt(0)] == true) {
str = str.substring(1, str.length);
}
while(stripCharCodes["code_" + str.charCodeAt(str.length - 1)] == true) {
str = str.substring(0, str.length - 1);
}
return str;
} |
The horrible "code_" prefix hack is there because I don’t think there’s a native way to search an array or object for a key or value in ActionScript.
Update: just found this function at: frogstyle.ch. This one does a similar thing, but strips more characters.
1
2
3
4
5
6
| function trim(str:String):String
{
for(var i = 0; str.charCodeAt(i) < 33; i++);
for(var j = str.length-1; str.charCodeAt(j) < 33; j--);
return str.substring(i, j+1);
} |
Update: as3corelib has a static trim method in com.adobe.utils.StringUtil.
Published at 4:26 pm on July 23rd, 2007
Topic: Flash
Link to this entry (26 comments)
array_mode
If you’ve ever needed to get calculate a mode value in php, you’ll notice that there isn’t a native function to do so.
I couldn’t get the function in Pear’s Math_Statistics to work with non-numeric values, so here’s a function that does.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
| <?php
/**
* Calculates the frequently occuring value(s) in an array.
*
* @param array $data
* @return array
*/
function array_mode($data)
{
if(!is_array($data)) {
throw new Exception('First argument $data must be an array.');
}
$frequencies = array_count_values($data);
// Double-check that frequencies are sorted in reverse order,
// I think array_count_values actually returns in this format
// already, but the manual doesn't mention it.
arsort($frequencies);
$isFirst = true; // Yuk
$mode = array();
foreach ($frequencies as $thisValue=>$thisFrequency) {
if ($isFirst == true) {
$isFirst = false; // Wince
$mode[] = $thisValue;
$modeFrequency = $thisFrequency;
continue;
}
if ($modeFrequency == $thisFrequency) {
$mode[] = $thisValue;
}
if ($modeFrequency > $thisFrequency) {
break;
}
}
return $mode;
}
var_dump(array_mode(array('a', 'a', 'b', 'c', 'd')));
/*
array(1) {
[0]=>
string(1) "a"
}
*/
var_dump(array_mode(array('a', 'a', 'b', 'b', 'c')));
/*
array(2) {
[0]=>
string(1) "a"
[1]=>
string(1) "b"
}
*/ |
Published at 10:49 am on May 3rd, 2007
Topic: PHP
Link to this entry (0 comments)