当前位置: 首页>>代码示例>>PHP>>正文


PHP ApiResult::unsetValue方法代码示例

本文整理汇总了PHP中ApiResult::unsetValue方法的典型用法代码示例。如果您正苦于以下问题:PHP ApiResult::unsetValue方法的具体用法?PHP ApiResult::unsetValue怎么用?PHP ApiResult::unsetValue使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在ApiResult的用法示例。


在下文中一共展示了ApiResult::unsetValue方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: testStaticDataMethods

 /**
  * @covers ApiResult
  */
 public function testStaticDataMethods()
 {
     $arr = array();
     ApiResult::setValue($arr, 'setValue', '1');
     ApiResult::setValue($arr, null, 'unnamed 1');
     ApiResult::setValue($arr, null, 'unnamed 2');
     ApiResult::setValue($arr, 'deleteValue', '2');
     ApiResult::unsetValue($arr, 'deleteValue');
     ApiResult::setContentValue($arr, 'setContentValue', '3');
     $this->assertSame(array('setValue' => '1', 'unnamed 1', 'unnamed 2', ApiResult::META_CONTENT => 'setContentValue', 'setContentValue' => '3'), $arr);
     try {
         ApiResult::setValue($arr, 'setValue', '99');
         $this->fail('Expected exception not thrown');
     } catch (RuntimeException $ex) {
         $this->assertSame('Attempting to add element setValue=99, existing value is 1', $ex->getMessage(), 'Expected exception');
     }
     try {
         ApiResult::setContentValue($arr, 'setContentValue2', '99');
         $this->fail('Expected exception not thrown');
     } catch (RuntimeException $ex) {
         $this->assertSame('Attempting to set content element as setContentValue2 when setContentValue ' . 'is already set as the content element', $ex->getMessage(), 'Expected exception');
     }
     ApiResult::setValue($arr, 'setValue', '99', ApiResult::OVERRIDE);
     $this->assertSame('99', $arr['setValue']);
     ApiResult::setContentValue($arr, 'setContentValue2', '99', ApiResult::OVERRIDE);
     $this->assertSame('setContentValue2', $arr[ApiResult::META_CONTENT]);
     $arr = array('foo' => 1, 'bar' => 1);
     ApiResult::setValue($arr, 'top', '2', ApiResult::ADD_ON_TOP);
     ApiResult::setValue($arr, null, '2', ApiResult::ADD_ON_TOP);
     ApiResult::setValue($arr, 'bottom', '2');
     ApiResult::setValue($arr, 'foo', '2', ApiResult::OVERRIDE);
     ApiResult::setValue($arr, 'bar', '2', ApiResult::OVERRIDE | ApiResult::ADD_ON_TOP);
     $this->assertSame(array(0, 'top', 'foo', 'bar', 'bottom'), array_keys($arr));
     $arr = array();
     ApiResult::setValue($arr, 'sub', array('foo' => 1));
     ApiResult::setValue($arr, 'sub', array('bar' => 1));
     $this->assertSame(array('sub' => array('foo' => 1, 'bar' => 1)), $arr);
     try {
         ApiResult::setValue($arr, 'sub', array('foo' => 2, 'baz' => 2));
         $this->fail('Expected exception not thrown');
     } catch (RuntimeException $ex) {
         $this->assertSame('Conflicting keys (foo) when attempting to merge element sub', $ex->getMessage(), 'Expected exception');
     }
     $arr = array();
     $title = Title::newFromText("MediaWiki:Foobar");
     $obj = new stdClass();
     $obj->foo = 1;
     $obj->bar = 2;
     ApiResult::setValue($arr, 'title', $title);
     ApiResult::setValue($arr, 'obj', $obj);
     $this->assertSame(array('title' => (string) $title, 'obj' => array('foo' => 1, 'bar' => 2, ApiResult::META_TYPE => 'assoc')), $arr);
     $fh = tmpfile();
     try {
         ApiResult::setValue($arr, 'file', $fh);
         $this->fail('Expected exception not thrown');
     } catch (InvalidArgumentException $ex) {
         $this->assertSame('Cannot add resource(stream) to ApiResult', $ex->getMessage(), 'Expected exception');
     }
     try {
         ApiResult::setValue($arr, null, $fh);
         $this->fail('Expected exception not thrown');
     } catch (InvalidArgumentException $ex) {
         $this->assertSame('Cannot add resource(stream) to ApiResult', $ex->getMessage(), 'Expected exception');
     }
     try {
         $obj->file = $fh;
         ApiResult::setValue($arr, 'sub', $obj);
         $this->fail('Expected exception not thrown');
     } catch (InvalidArgumentException $ex) {
         $this->assertSame('Cannot add resource(stream) to ApiResult', $ex->getMessage(), 'Expected exception');
     }
     try {
         $obj->file = $fh;
         ApiResult::setValue($arr, null, $obj);
         $this->fail('Expected exception not thrown');
     } catch (InvalidArgumentException $ex) {
         $this->assertSame('Cannot add resource(stream) to ApiResult', $ex->getMessage(), 'Expected exception');
     }
     fclose($fh);
     try {
         ApiResult::setValue($arr, 'inf', INF);
         $this->fail('Expected exception not thrown');
     } catch (InvalidArgumentException $ex) {
         $this->assertSame('Cannot add non-finite floats to ApiResult', $ex->getMessage(), 'Expected exception');
     }
     try {
         ApiResult::setValue($arr, null, INF);
         $this->fail('Expected exception not thrown');
     } catch (InvalidArgumentException $ex) {
         $this->assertSame('Cannot add non-finite floats to ApiResult', $ex->getMessage(), 'Expected exception');
     }
     try {
         ApiResult::setValue($arr, 'nan', NAN);
         $this->fail('Expected exception not thrown');
     } catch (InvalidArgumentException $ex) {
         $this->assertSame('Cannot add non-finite floats to ApiResult', $ex->getMessage(), 'Expected exception');
     }
//.........这里部分代码省略.........
开发者ID:ucfengzhun,项目名称:mediawiki,代码行数:101,代码来源:ApiResultTest.php


注:本文中的ApiResult::unsetValue方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。