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


PHP MethodProphecy::willReturn方法代码示例

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


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

示例1: testValidCommandsAreReturned

 /**
  * @dataProvider commandProvider
  */
 public function testValidCommandsAreReturned($command, $factoryMethod, Cli\Options $arguments = null)
 {
     $factory = $this->prophesize(Factory::class);
     if ($arguments != null) {
         $method = new MethodProphecy($factory, $factoryMethod, [$arguments]);
     } else {
         $method = new MethodProphecy($factory, $factoryMethod, []);
     }
     $method->willReturn($this->prophesize(Cli\Command::class)->reveal());
     $factory->addMethodProphecy($method);
     $locator = new CommandLocator($factory->reveal());
     $request = $this->prophesize(Cli\Request::class);
     $request->getCommand()->willReturn($command)->shouldBeCalled();
     $request->getCommandOptions()->willReturn($arguments);
     $result = $locator->getCommandForRequest($request->reveal());
     $this->assertInstanceOf(CLI\Command::class, $result);
 }
开发者ID:paul-schulleri,项目名称:phive,代码行数:20,代码来源:CommandLocatorTest.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\MethodProphecy::willReturn方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。