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


PHP ObjectProphecy::load方法代码示例

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


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

示例1: testGet

 /**
  */
 public function testGet()
 {
     $id = 1;
     /** @var EntityInterface|ObjectProphecy $entity */
     $entity = $this->prophesize('AppBundle\\Entity\\EntityInterface');
     $this->fertilizerObjectManager->load($id)->willReturn($entity->reveal())->shouldBeCalledTimes(1);
     $this->assertSame($entity->reveal(), $this->handler->get($id));
 }
开发者ID:JahHub,项目名称:fertilizer,代码行数:10,代码来源:AbstractEntityHandlerTest.php

示例2: testResponseFormat

 /**
  * @covers ::getResponseFormat
  *
  * Note this does *not* need to test formats being requested that are not
  * accepted by the server, because the routing system would have already
  * prevented those from reaching RequestHandler.
  *
  * @param string[] $methods
  *   The HTTP methods to test.
  * @param string[] $supported_formats
  *   The supported formats for the REST route to be tested.
  * @param string|false $request_format
  *   The value for the ?_format URL query argument, if any.
  * @param string[] $request_headers
  *   The request headers to send, if any.
  * @param string|null $request_body
  *   The request body to send, if any.
  * @param string|null $expected_response_content_type
  *   The expected MIME type of the response, if any.
  * @param string $expected_response_content
  *   The expected content of the response.
  *
  * @dataProvider providerTestResponseFormat
  */
 public function testResponseFormat($methods, array $supported_formats, $request_format, array $request_headers, $request_body, $expected_response_content_type, $expected_response_content)
 {
     $rest_config_name = $this->randomMachineName();
     $parameters = [];
     if ($request_format !== FALSE) {
         $parameters['_format'] = $request_format;
     }
     foreach ($request_headers as $key => $value) {
         unset($request_headers[$key]);
         $key = strtoupper(str_replace('-', '_', $key));
         $request_headers[$key] = $value;
     }
     foreach ($methods as $method) {
         $request = Request::create('/rest/test', $method, $parameters, [], [], $request_headers, $request_body);
         $route_requirement_key_format = $request->isMethodSafe() ? '_format' : '_content_type_format';
         $route_match = new RouteMatch('test', new Route('/rest/test', ['_rest_resource_config' => $rest_config_name], [$route_requirement_key_format => implode('|', $supported_formats)]));
         $resource = $this->prophesize(StubRequestHandlerResourcePlugin::class);
         // Mock the configuration.
         $config = $this->prophesize(RestResourceConfigInterface::class);
         $config->getFormats($method)->willReturn($supported_formats);
         $config->getResourcePlugin()->willReturn($resource->reveal());
         $config->getCacheContexts()->willReturn([]);
         $config->getCacheTags()->willReturn([]);
         $config->getCacheMaxAge()->willReturn(12);
         $this->entityStorage->load($rest_config_name)->willReturn($config->reveal());
         // Mock the resource plugin.
         $response = new ResourceResponse($method !== 'DELETE' ? ['REST' => 'Drupal'] : NULL);
         $resource->getPluginDefinition()->willReturn([]);
         $method_prophecy = new MethodProphecy($resource, strtolower($method), [Argument::any(), $request]);
         $method_prophecy->willReturn($response);
         $resource->addMethodProphecy($method_prophecy);
         // Test the request handler.
         $handler_response = $this->requestHandler->handle($route_match, $request);
         $this->assertSame($expected_response_content_type, $handler_response->headers->get('Content-Type'));
         $this->assertEquals($expected_response_content, $handler_response->getContent());
     }
 }
开发者ID:eigentor,项目名称:tommiblog,代码行数:61,代码来源:RequestHandlerTest.php


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