powered by nequal
Home » Net_Carrier_Detect_MobileJp » Timeline » 1497

Changeset 1497 -- 2010-01-07 10:38:16

Author
okonomi
Comment
判定結果を変更しようとしたとき、添字が数字なのにarray_mergeしてたので上書きできてなかった。

Diffs

Net_Carrier_Detect_MobileJp/trunk/test/Net_Carrier_Detect_MobileJpTest.php

@@ -52,4 +52,31 @@
}
}
}
+
+    public function testChangeDetectValues()
+    {
+        $detect_values = array(
+            Net_Carrier_Detect_MobileJp::MOBILE_NONMOBILE => 'a',
+            Net_Carrier_Detect_MobileJp::MOBILE_DOCOMO    => 'b',
+        );
+        $expected = array(
+            'foo'      => 'a',
+            'docomo'   => 'b',
+            'softbank' => 'softbank',
+            'au'       => 'au',
+            'willcom'  => 'willcom',
+            'emobile'  => 'emobile',
+        );
+
+        foreach ($expected as $value => $expect) {
+            try {
+                $this->assertEquals(
+                    $expect,
+                    Net_Carrier_Detect_MobileJp::detect($value, $detect_values));
+            } catch (PHPUnit_Framework_ExpectationFailedException $e) {
+                echo "fail: value=$value, expect=$expect", PHP_EOL;
+                throw $e;
+            }
+        }
+    }
}

Net_Carrier_Detect_MobileJp/trunk/src/Net/Carrier/Detect/MobileJp.php

@@ -23,10 +23,7 @@
static function detect($str, $return_val = array())
{
-        $return_val = array_merge(
-            self::$_detect_value,
-            $return_val
-        );
+        $return_val += self::$_detect_value;
switch (strtolower($str)) {