當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。