本文整理汇总了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')
);
}
示例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()));
}
示例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);
}
示例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);
}
}
示例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[]'));
}