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


PHP SerializerInterface::expects方法代码示例

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


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

示例1: testNormalize

    public function testNormalize()
    {
        $obj = new GetSetDummy();
        $object = new \stdClass();
        $obj->setFoo('foo');
        $obj->setBar('bar');
        $obj->setBaz(true);
        $obj->setCamelCase('camelcase');
        $obj->setObject($object);

        $this->serializer
            ->expects($this->once())
            ->method('normalize')
            ->with($object, 'any')
            ->will($this->returnValue('string_object'))
        ;

        $this->assertEquals(
            array(
                'foo' => 'foo',
                'bar' => 'bar',
                'baz' => true,
                'fooBar' => 'foobar',
                'camelCase' => 'camelcase',
                'object' => 'string_object',
            ),
            $this->normalizer->normalize($obj, 'any')
        );
    }
开发者ID:ninvfeng,项目名称:symfony,代码行数:29,代码来源:GetSetMethodNormalizerTest.php

示例2: testCircularNormalize

 /**
  * @expectedException \Symfony\Component\Serializer\Exception\CircularReferenceException
  */
 public function testCircularNormalize()
 {
     $this->normalizer->setCircularReferenceLimit(1);
     $this->serializer->expects($this->once())->method('normalize')->will($this->returnCallback(function ($data, $format, $context) {
         $this->normalizer->normalize($data['qux'], $format, $context);
         return 'string_object';
     }));
     $this->assertEquals('string_object', $this->normalizer->normalize(new JsonSerializableDummy()));
 }
开发者ID:symfony,项目名称:symfony,代码行数:12,代码来源:JsonSerializableNormalizerTest.php

示例3: testNormalizeWithAccountContext

 /**
  * Tests the normalize() method with account context passed.
  *
  * @covers ::normalize
  */
 public function testNormalizeWithAccountContext()
 {
     $mock_account = $this->getMock('Drupal\\Core\\Session\\AccountInterface');
     $context = ['account' => $mock_account];
     $this->serializer->expects($this->any())->method('normalize')->with($this->containsOnlyInstancesOf('Drupal\\Core\\Field\\FieldItemListInterface'), 'test_format', $context)->will($this->returnValue('test'));
     // The mock account should get passed directly into the access() method on
     // field items from $context['account'].
     $definitions = array('field_1' => $this->createMockFieldListItem(TRUE, $mock_account), 'field_2' => $this->createMockFieldListItem(FALSE, $mock_account));
     $content_entity_mock = $this->createMockForContentEntity($definitions);
     $normalized = $this->contentEntityNormalizer->normalize($content_entity_mock, 'test_format', $context);
     $this->assertArrayHasKey('field_1', $normalized);
     $this->assertEquals('test', $normalized['field_1']);
     $this->assertArrayNotHasKey('field_2', $normalized);
 }
开发者ID:eigentor,项目名称:tommiblog,代码行数:19,代码来源:ContentEntityNormalizerTest.php

示例4: validateRetrieveApiCall

 protected function validateRetrieveApiCall($method, $uri, array $urlParameters, $statusCode, $type, $transformedResult, array $serializerMap = array())
 {
     $rawResponse = 'the-server-response';
     $response = $this->getMockBuilder('\\Psr\\Http\\Message\\ResponseInterface')->getMock();
     $response->expects($this->any())->method('getStatusCode')->willReturn($statusCode);
     $response->expects($this->any())->method('getHeader')->with('Content-Type')->willReturn(array('application/json'));
     $response->expects($this->any())->method('getBody')->willReturn($rawResponse);
     $request = $this->validateRequest($method, $uri, $urlParameters);
     if (404 === $statusCode) {
         $this->requestHandler->expects($this->once())->method('executeRequest')->with($request)->willThrowException(new NotFoundException('Not found'));
     } else {
         $this->requestHandler->expects($this->once())->method('executeRequest')->with($request)->willReturn($response);
     }
     $this->validateSerializer($serializerMap);
     if ($statusCode < 400) {
         $this->serializer->expects($this->once())->method('deserialize')->with($rawResponse, 'Xabbuh\\XApi\\Model\\' . $type, 'json')->willReturn($transformedResult);
     }
 }
开发者ID:php-xapi,项目名称:client,代码行数:18,代码来源:ApiClientTest.php

示例5: testSupportsInvalidArray

 public function testSupportsInvalidArray()
 {
     $this->serializer->expects($this->any())->method('supportsDenormalization')->will($this->returnValue(false));
     $this->assertFalse($this->denormalizer->supportsDenormalization(array(array('foo' => 'one', 'bar' => 'two'), array('foo' => 'three', 'bar' => 'four')), __NAMESPACE__ . '\\InvalidClass[]'));
 }
开发者ID:symfony,项目名称:symfony,代码行数:5,代码来源:ArrayDenormalizerTest.php


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