Skip to content

Commit ee7e920

Browse files
committed
fix broken unit tests (E_NOTICE undefined index)
git-svn-id: http://svn.php.net/repository/pear/packages/Text_LanguageDetect/trunk@322176 c90b9560-bf6c-de11-be94-00142212c4b1
1 parent 234af00 commit ee7e920

File tree

1 file changed

+17
-39
lines changed

1 file changed

+17
-39
lines changed

tests/Text_LanguageDetectTest.php

Lines changed: 17 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@
44
* @package Text_LanguageDetect
55
* @version CVS: $Id$
66
*/
7+
set_include_path(
8+
__DIR__ . '/../' . PATH_SEPARATOR . get_include_path()
9+
);
710

811
require_once 'Text/LanguageDetect.php';
912
require_once 'PHPUnit/Framework/TestCase.php';
@@ -28,6 +31,7 @@ function test_setup ()
2831
{
2932
$err_result = $this->x->_setup_ok($err_obj);
3033

34+
$message = null;
3135
if (PEAR::isError($err_obj)) {
3236
$message = $err_obj->getMessage();
3337
}
@@ -52,9 +56,8 @@ function test_splitter ()
5256

5357
$str = 'aa aa';
5458
$result = $this->x->_trigram($str);
55-
$this->assertEquals(null, $result[' a'], ' a');
56-
$this->assertEquals(null, $result['a '], 'a ');
57-
59+
$this->assertArrayNotHasKey(' a', $result, ' a');
60+
$this->assertArrayNotHasKey('a ', $result, 'a ');
5861
}
5962

6063
function test_splitter2 ()
@@ -1035,6 +1038,7 @@ function test_long_example ()
10351038
$results = $this->x->detect($str);
10361039

10371040
$count = count($ranked);
1041+
$sum = 0;
10381042

10391043
//foreach ($this->x->_lang_db['english'] as $key => $value) {
10401044
foreach ($ranked as $key => $value) {
@@ -1119,22 +1123,7 @@ function test_french ()
11191123
);
11201124

11211125

1122-
//ksort($correct_ranks);
1123-
//ksort($ranked);
1124-
//$this->assertEquals($correct_ranks,$ranked);
11251126
$this->assertEquals(count($correct_ranks), count($ranked), "different number of trigrams found");
1126-
//print_r($correct_ranks);
1127-
//print_r($ranked);
1128-
//print_r(array_diff_assoc($correct_ranks, $ranked));
1129-
1130-
if (count($correct_ranks) == count($ranks)) {
1131-
foreach ($correct_ranks as $key => $value) {
1132-
$this->assertTrue(isset($ranks[$key]), "$key was not set");
1133-
if (isset($ranks[$key])) {
1134-
$this->assertEquals($value, $ranks[$key], "$key value incorrect");
1135-
}
1136-
}
1137-
}
11381127

11391128
$distances = array(
11401129
' de' => array('change' => 0, 'baserank' => 1, 'refrank' => 1),
@@ -1195,18 +1184,12 @@ function test_french ()
11951184
$this->assertTrue(isset($distances[$key]), $key);
11961185
if (isset($distances[$key])) {
11971186
$this->assertEquals($distances[$key]['baserank'], $ranked[$key], "baserank for $key");
1198-
$this->assertEquals($distances[$key]['refrank'], $french_ranks[$key], "refrank for $key");
1199-
$this->assertEquals($distances[$key]['change'], $difference, "difference for $key");
1200-
1201-
if ($distances[$key]['baserank'] != $ranked[$key] || $distances[$key]['refrank'] != $french_ranks[$key] || $distances[$key]['change'] != $difference) {
1202-
1203-
// don't flood
1204-
if ($local_errors++ > 10) {
1205-
$this->assertTrue(false, 'Exiting to prevent flooding');
1206-
break;
1207-
}
1187+
if ($distances[$key]['refrank'] === null) {
1188+
$this->assertArrayNotHasKey($key, $french_ranks);
1189+
} else {
1190+
$this->assertEquals($distances[$key]['refrank'], $french_ranks[$key], "refrank for $key");
12081191
}
1209-
1192+
$this->assertEquals($distances[$key]['change'], $difference, "difference for $key");
12101193
}
12111194

12121195
$sumchange += $difference;
@@ -1296,17 +1279,12 @@ function test_russian ()
12961279
$this->assertTrue(isset($correct_ranks[$key], $key));
12971280
if (isset($correct_ranks[$key])) {
12981281
$this->assertEquals($correct_ranks[$key]['baserank'], $ranked[$key], "baserank for $key");
1299-
$this->assertEquals($correct_ranks[$key]['refrank'], $russian[$key], "refrank for $key");
1300-
$this->assertEquals($correct_ranks[$key]['change'], $difference, "difference for $key");
1301-
1302-
if ($correct_ranks[$key]['baserank'] != $ranked[$key] || $correct_ranks[$key]['refrank'] != $russian[$key] || $correct_ranks[$key]['change'] != $difference) {
1303-
1304-
// don't flood
1305-
if ($local_errors++ > 6) {
1306-
$this->assertTrue(false, 'Exiting to prevent flooding');
1307-
break;
1308-
}
1282+
if ($correct_ranks[$key]['refrank'] === null) {
1283+
$this->assertArrayNotHasKey($key, $russian);
1284+
} else {
1285+
$this->assertEquals($correct_ranks[$key]['refrank'], $russian[$key], "refrank for $key");
13091286
}
1287+
$this->assertEquals($correct_ranks[$key]['change'], $difference, "difference for $key");
13101288
}
13111289

13121290
$sumchange += $difference;

0 commit comments

Comments
 (0)