Example #1
0
 /**
  * @covers Peach\DF\JsonCodec\Context::__construct
  * @covers Peach\DF\JsonCodec\Context::getOption
  */
 public function testGetOption()
 {
     $options = new ArrayMap();
     $options->put(JsonCodec::BIGINT_AS_STRING, true);
     $context = new Context("This is a pen.", $options);
     $this->assertFalse($context->getOption(JsonCodec::OBJECT_AS_ARRAY));
     $this->assertTrue($context->getOption(JsonCodec::BIGINT_AS_STRING));
 }
 /**
  * encode の結果が, 引数の値を serialize した結果に等しくなることを確認します.
  *  
  * @covers Peach\DF\SerializationCodec::encode
  */
 public function testEncode()
 {
     $obj = $this->object;
     $map = new ArrayMap();
     $map->put("TEST1", "foo");
     $map->put("TEST2", "bar");
     $map->put("TEST3", "baz");
     $expected = serialize($map);
     $this->assertSame($expected, $obj->encode($map));
 }
Example #3
0
 /**
  * 指定されたオプションが ON かどうかを調べます.
  * 
  * @param  int $code オプション (JsonCodec で定義されている定数)
  * @return bool      指定されたオプションが ON の場合は true, それ以外は false
  */
 public function getOption($code)
 {
     return $this->options->get($code, false);
 }
Example #4
0
 /**
  * 以下を確認します.
  * 
  * - 配列を引数にして日付の設定が出来ること
  * - Map を引数にして日付の設定が出来ること
  * - 範囲外のフィールドが指定された場合に, 上位のフィールドから順に調整されること
  * 
  * @covers Peach\DT\Date::setAll
  */
 public function testSetAll()
 {
     $d = new Date(2012, 5, 21);
     $test1 = $d->setAll(array("year" => 2015, "date" => 10));
     $this->assertEquals(new Date(2015, 5, 10), $test1);
     $map = new ArrayMap();
     $map->put("month", 12);
     $map->put("date", 31);
     $test2 = $d->setAll($map);
     $this->assertEquals(new Date(2012, 12, 31), $test2);
     // 2011-14-31 => 2012-02-31 => 2012-03-02
     $this->assertEquals(new Date(2012, 3, 2), $d->setAll(array("year" => 2011, "month" => 14, "date" => 31)));
 }
Example #5
0
 /**
  * マッチした文字列を整数に変換した値を適用します.
  * 
  * @param ArrayMap $fields  適用先のフィールド
  * @param string   $matched マッチした文字列
  */
 public function apply(ArrayMap $fields, $matched)
 {
     $fields->put($this->fieldName, intval($matched));
 }
Example #6
0
 /**
  * 与えられた日付を表現する Peach_DT_Date オブジェクトを構築します.
  *
  * @param int $year  年
  * @param int $month 月
  * @param int $date  日
  */
 public function __construct($year, $month, $date)
 {
     $fields = new ArrayMap();
     $fields->put(self::$YEAR, intval($year));
     $fields->put(self::$MONTH, intval($month));
     $fields->put(self::$DATE, intval($date));
     $this->init($fields);
 }
Example #7
0
 /**
  * 以下を確認します.
  * 
  * - 配列を引数にして日付の設定が出来ること
  * - Map を引数にして日付の設定が出来ること
  * - 範囲外のフィールドが指定された場合に, 上位のフィールドから順に調整されること
  * 
  * @covers Peach\DT\Timestamp::setAll
  * @covers Peach\DT\FieldAdjuster::__construct
  * @covers Peach\DT\FieldAdjuster::moveUp
  * @covers Peach\DT\FieldAdjuster::moveDown
  */
 public function testSetAll()
 {
     $d = new Timestamp(2012, 5, 21, 7, 30, 15);
     $test1 = $d->setAll(array("min" => 34, "sec" => 59, "hour" => 6));
     $this->assertEquals(new Timestamp(2012, 5, 21, 6, 34, 59), $test1);
     $map = new ArrayMap();
     $map->put("mon", 2);
     $map->put("sec", 1);
     $map->put("min", 15);
     $test2 = $d->setAll($map);
     $this->assertEquals(new Timestamp(2012, 2, 21, 7, 15, 1), $test2);
     // 2012-05-21T-3:131:-85 => 2012-05-20T21:131:-85 => 2012-05-20T23:11:-85 => 2012-05-20T23:09:45
     $this->assertEquals(new Timestamp(2012, 5, 20, 23, 9, 35), $d->setAll(array("hour" => -3, "min" => 131, "sec" => -85)));
 }
Example #8
0
 /**
  * 以下を確認します.
  * 
  * - 配列を引数にして日付の設定が出来ること
  * - Util_Map を引数にして日付の設定が出来ること
  * - 範囲外のフィールドが指定された場合に, 上位のフィールドから順に調整されること
  * 
  * @covers Peach\DT\Datetime::setAll
  */
 public function testSetAll()
 {
     $d = new Datetime(2012, 5, 21, 7, 30);
     $test1 = $d->setAll(array("min" => 34, "hour" => 18));
     $this->assertEquals(new Datetime(2012, 5, 21, 18, 34), $test1);
     $map = new ArrayMap();
     $map->put("mon", 10);
     $map->put("min", 55);
     $test2 = $d->setAll($map);
     $this->assertEquals(new Datetime(2012, 10, 21, 7, 55), $test2);
     // 2012-05-21T36:-72 => 2012-05-22T12:-72 => 2012-05-22T10:48
     $this->assertEquals(new Datetime(2012, 5, 22, 10, 48), $d->setAll(array("hour" => 36, "min" => -72)));
 }
Example #9
0
 /**
  * handle のテストです. 以下を確認します.
  * 
  * - 第 1 引数の文字列を持つ Context を handle した結果, 第 2 引数の値が得られること
  * - Context の現在位置が 第 1 引数の長さ分だけ進められること
  * 
  * @param string $str      Context が持つ文字列
  * @param int    $expected 得られるはずの値
  * @param bool   $bigInt   オプション BIGINT_AS_STRING を ON にする場合は true
  */
 private function checkHandleByString($str, $expected, $bigInt = false)
 {
     $opt = new ArrayMap();
     if ($bigInt) {
         $opt->put(JsonCodec::BIGINT_AS_STRING, true);
     }
     $expr = new Number();
     $context = new Context("{$str},", $opt);
     $expr->handle($context);
     $this->assertSame($expected, $expr->getResult());
     $this->assertSame(",", $context->current());
 }
Example #10
0
 /**
  * この要素に複数の属性を一括して設定します.
  * <code>
  * $element->setAttributes(array("id" => "foo", "class" => "bar"));
  * </code>
  * のように, キーに属性名, 値に属性の値を指定してください.
  * 
  * キーが省略された場合 (具体的にはキーに整数が指定された場合) は,
  * その値を属性名とする Boolean 属性を設定します.
  * 
  * @param array|ArrayMap $attr 属性の一覧
  */
 public function setAttributes($attr)
 {
     if ($attr instanceof ArrayMap) {
         $this->setAttributes($attr->asArray());
         return;
     }
     if (!is_array($attr)) {
         throw new InvalidArgumentException("Array required.");
     }
     foreach ($attr as $key => $value) {
         if (is_numeric($key)) {
             $attrName = $value;
             $attrValue = null;
         } else {
             $attrName = $key;
             $attrValue = $value;
         }
         $this->setAttribute($attrName, $attrValue);
     }
 }
Example #11
0
 /**
  * setAttributes() および getAttributes() のテストです. 以下を確認します.
  * - 引数に指定した配列が属性としてセットされること
  * - 引数に指定した Map オブジェクトが属性としてセットされること
  * - 配列のキーに整数が指定されている場合, その値が Boolean 属性としてセットされること
  * 
  * @covers Peach\Markup\Element::setAttributes
  * @covers Peach\Markup\Element::getAttributes
  */
 public function testAccessAttributes()
 {
     $arr = array("first" => 1, "second" => 2, "third" => 3);
     $map = new ArrayMap();
     $map->put("aaa", "xxxx");
     $map->put("bbb", "yyyy");
     $map->put("ccc", "zzzz");
     $expected = array("first" => "1", "second" => "2", "third" => "3", "aaa" => "xxxx", "bbb" => "yyyy", "ccc" => "zzzz");
     $obj = $this->object;
     $obj->setAttributes($arr);
     $obj->setAttributes($map);
     $this->assertSame($expected, $obj->getAttributes());
 }
Example #12
0
 /**
  * 与えられた時刻を表現する Timestamp オブジェクトを構築します.
  * 
  * @param int $year  年
  * @param int $month 月
  * @param int $date  日
  * @param int $hour  時
  * @param int $min   分
  * @param int $sec   秒
  */
 public function __construct($year, $month, $date, $hour, $min, $sec)
 {
     $fields = new ArrayMap();
     $fields->put(self::$YEAR, intval($year));
     $fields->put(self::$MONTH, intval($month));
     $fields->put(self::$DATE, intval($date));
     $fields->put(self::$HOUR, intval($hour));
     $fields->put(self::$MINUTE, intval($min));
     $fields->put(self::$SECOND, intval($sec));
     $this->init($fields);
 }
Example #13
0
 /**
  * 引数のフィールドを, $amount だけ増加 (負の場合は減少) させます.
  * @param  string $field  対象のフィールド
  * @param  int    $amount 加算する量. マイナスの場合は過去方向に移動する.
  * @return Time           設定後の時間オブジェクト
  */
 public final function add($field, $amount)
 {
     $newFields = new ArrayMap($this->fields);
     $key = $this->getFieldIndex($field);
     $current = $this->fields->get($key);
     $newFields->put($key, $current + $amount);
     return $this->newInstance($newFields);
 }
Example #14
0
 /**
  * 指定されたデコード用オプションが ON かどうかを調べます.
  * 
  * @param  int $code オプション (定義されている定数)
  * @return bool      指定されたオプションが ON の場合は true, それ以外は false
  */
 public function getDecodeOption($code)
 {
     return $this->decodeOptions->get($code, false);
 }