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