Exemple #1
0
 /**
  * pickup() をテストします. 以下を確認します.
  * 
  * - string, numeric, bool など各キーワードを解釈すること (文字の大小は問わず)
  * - その他の文字列はクラス / インタフェース名として解釈すること
  * - 第 3 引数に true を指定した場合は元の配列の添字を維持すること
  * 
  * @covers Peach\Util\Arrays::pickup
  * @covers Peach\Util\Arrays::pickupMatch
  */
 public function testPickup()
 {
     $obj1 = new ArraysTest_Object("Hoge", 100);
     $obj2 = new ArraysTest_Object("Fuga", 200);
     $arr = array("A", 1, null, array(), $obj1, "B", true, $obj2, 2.5, array(1, 3, 5), null, false, self::$fp);
     $expected1 = array("A", "B");
     $this->assertSame($expected1, Arrays::pickup($arr, "string"));
     $expected2 = array(1, 2.5);
     $this->assertSame($expected2, Arrays::pickup($arr, "numeric"));
     $this->assertSame($expected2, Arrays::pickup($arr, "float"));
     $expected3 = array(1);
     $this->assertSame($expected3, Arrays::pickup($arr, "INT"));
     $this->assertSame($expected3, Arrays::pickup($arr, "integer"));
     $expected4 = array(true, false);
     $this->assertSame($expected4, Arrays::pickup($arr, "bool"));
     $this->assertSame($expected4, Arrays::pickup($arr, "Boolean"));
     $expected5 = array(self::$fp);
     $this->assertSame($expected5, Arrays::pickup($arr, "resource"));
     $expected6 = array(null, null);
     $this->assertSame($expected6, Arrays::pickup($arr, "null"));
     $expected7 = array(array(), array(1, 3, 5));
     $this->assertSame($expected7, Arrays::pickup($arr, "array"));
     $expected8 = array($obj1, $obj2);
     $this->assertSame($expected8, Arrays::pickup($arr, "object"));
     $this->assertSame($expected8, Arrays::pickup($arr, "Peach\\Util\\ArraysTest_Object"));
     $expected9 = array();
     $this->assertSame($expected9, Arrays::pickup($arr, "Unknown_Object"));
     // 第3引数を TRUE にした場合は添字を維持する
     $expectedA = array(0 => "A", 1 => "B");
     $this->assertSame($expectedA, Arrays::pickup($arr, "string", false));
     $expectedB = array(0 => "A", 5 => "B");
     $this->assertSame($expectedB, Arrays::pickup($arr, "string", true));
 }