本文整理汇总了PHP中Prophecy\Prophecy\MethodProphecy类的典型用法代码示例。如果您正苦于以下问题:PHP MethodProphecy类的具体用法?PHP MethodProphecy怎么用?PHP MethodProphecy使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了MethodProphecy类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: check
/**
* Tests that there were no calls made.
*
* @param Call[] $calls
* @param ObjectProphecy $object
* @param MethodProphecy $method
*
* @throws \Prophecy\Exception\Prediction\UnexpectedCallsException
*/
public function check(array $calls, ObjectProphecy $object, MethodProphecy $method)
{
if (!count($calls)) {
return;
}
throw new UnexpectedCallsException(sprintf("No calls expected that match:\n" . " %s->%s(%s)\n" . "but %d were made:\n%s", get_class($object->reveal()), $method->getMethodName(), $method->getArgumentsWildcard(), count($calls), $this->util->stringifyCalls($calls)), $method, $calls);
}
示例2:
/**
* @param \Prophecy\Prophecy\ObjectProphecy $object
* @param \Prophecy\Prophecy\MethodProphecy $method
* @param \Prophecy\Argument\ArgumentsWildcard $arguments
*/
function it_throws_NoCallsException_if_no_calls_found($object, $method, $arguments)
{
$method->getObjectProphecy()->willReturn($object);
$method->getMethodName()->willReturn('getName');
$method->getArgumentsWildcard()->willReturn($arguments);
$arguments->__toString()->willReturn('123');
$object->reveal()->willReturn(new \stdClass());
$object->findProphecyMethodCalls('getName', Argument::any())->willReturn(array());
$this->shouldThrow('Prophecy\\Exception\\Prediction\\NoCallsException')->duringCheck(array(), $object, $method);
}
示例3: array
function it_returns_null_if_method_prophecy_that_matches_makeCall_arguments_has_no_promise($objectProphecy, MethodProphecy $method, ArgumentsWildcard $arguments)
{
$method->getMethodName()->willReturn('getName');
$method->getArgumentsWildcard()->willReturn($arguments);
$method->getPromise()->willReturn(null);
$arguments->scoreArguments(array('world', 'everything'))->willReturn(100);
$objectProphecy->getMethodProphecies()->willReturn(array($method));
$objectProphecy->getMethodProphecies('getName')->willReturn(array($method));
$this->makeCall($objectProphecy, 'getName', array('world', 'everything'))->shouldReturn(null);
}
示例4:
/**
* @param \Prophecy\Prophecy\ObjectProphecy $object
* @param \Prophecy\Prophecy\MethodProphecy $method
* @param \Prophecy\Call\Call $call
* @param \Prophecy\Argument\ArgumentsWildcard $arguments
*/
function it_throws_UnexpectedCallsCountException_if_calls_found($object, $method, $call, $arguments)
{
$method->getObjectProphecy()->willReturn($object);
$method->getMethodName()->willReturn('getName');
$method->getArgumentsWildcard()->willReturn($arguments);
$arguments->__toString()->willReturn('123');
$call->getMethodName()->willReturn('getName');
$call->getArguments()->willReturn(array(5, 4, 'three'));
$call->getCallPlace()->willReturn('unknown');
$this->shouldThrow('Prophecy\\Exception\\Prediction\\UnexpectedCallsCountException')->duringCheck(array($call), $object, $method);
}
示例5:
function it_should_return_empty_string_if_argument_counts_do_not_match(UnexpectedCallException $exception, ObjectProphecy $objectProphecy, MethodProphecy $prophecy, ArgumentsWildcard $wildcard)
{
$exception->getObjectProphecy()->willReturn($objectProphecy);
$exception->getArguments()->willReturn(array('a', 'b'));
$exception->getMethodName()->shouldBeCalled();
$objectProphecy->getMethodProphecies(Argument::any())->willReturn(array($prophecy));
$objectProphecy->findProphecyMethodCalls(Argument::any(), Argument::any())->willReturn(array());
$prophecy->getArgumentsWildcard()->willReturn($wildcard);
$wildcard->getTokens()->willReturn(array('a'));
$this->presentDifference($exception)->shouldReturn('');
}
示例6:
/**
* @param \Prophecy\Prophecy\MethodProphecy $method1
* @param \Prophecy\Prophecy\MethodProphecy $method2
* @param \Prophecy\Argument\ArgumentsWildcard $arguments1
* @param \Prophecy\Argument\ArgumentsWildcard $arguments2
*/
function it_throws_AggregateException_if_defined_predictions_fail($method1, $method2, $arguments1, $arguments2)
{
$method1->getMethodName()->willReturn('getName');
$method1->getArgumentsWildcard()->willReturn($arguments1);
$method1->checkPrediction()->willReturn(null);
$method2->getMethodName()->willReturn('isSet');
$method2->getArgumentsWildcard()->willReturn($arguments2);
$method2->checkPrediction()->willThrow('Prophecy\\Exception\\Prediction\\AggregateException');
$this->prophesize()->addMethodProphecy($method1);
$this->prophesize()->addMethodProphecy($method2);
$this->shouldThrow('Prophecy\\Exception\\Prediction\\AggregateException')->duringCheckPredictions();
}
示例7: 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);
}
示例8: check
/**
* Tests that there was exact amount of calls made.
*
* @param Call[] $calls
* @param ObjectProphecy $object
* @param MethodProphecy $method
*
* @throws \Prophecy\Exception\Prediction\UnexpectedCallsCountException
*/
public function check(array $calls, ObjectProphecy $object, MethodProphecy $method)
{
if ($this->times == count($calls)) {
return;
}
$methodCalls = $object->findProphecyMethodCalls($method->getMethodName(), new ArgumentsWildcard(array(new AnyValuesToken())));
if (count($calls)) {
$message = sprintf("Expected exactly %d calls that match:\n" . " %s->%s(%s)\n" . "but %d were made:\n%s", $this->times, get_class($object->reveal()), $method->getMethodName(), $method->getArgumentsWildcard(), count($calls), $this->util->stringifyCalls($calls));
} elseif (count($methodCalls)) {
$message = sprintf("Expected exactly %d calls that match:\n" . " %s->%s(%s)\n" . "but none were made.\n" . "Recorded `%s(...)` calls:\n%s", $this->times, get_class($object->reveal()), $method->getMethodName(), $method->getArgumentsWildcard(), $method->getMethodName(), $this->util->stringifyCalls($methodCalls));
} else {
$message = sprintf("Expected exactly %d calls that match:\n" . " %s->%s(%s)\n" . "but none were made.", $this->times, get_class($object->reveal()), $method->getMethodName(), $method->getArgumentsWildcard());
}
throw new UnexpectedCallsCountException($message, $method, $this->times, $calls);
}
示例9: check
/**
* Tests that there was at least one call.
*
* @param Call[] $calls
* @param ObjectProphecy $object
* @param MethodProphecy $method
*
* @throws \Prophecy\Exception\Prediction\NoCallsException
*/
public function check(array $calls, ObjectProphecy $object, MethodProphecy $method)
{
if (count($calls)) {
return;
}
$methodCalls = $object->findProphecyMethodCalls($method->getMethodName(), new ArgumentsWildcard(array(new AnyValuesToken())));
if (count($methodCalls)) {
throw new NoCallsException(sprintf("No calls have been made that match:\n" . " %s->%s(%s)\n" . "but expected at least one.\n" . "Recorded `%s(...)` calls:\n%s", get_class($object->reveal()), $method->getMethodName(), $method->getArgumentsWildcard(), $method->getMethodName(), $this->util->stringifyCalls($methodCalls)), $method);
}
throw new NoCallsException(sprintf("No calls have been made that match:\n" . " %s->%s(%s)\n" . "but expected at least one.", get_class($object->reveal()), $method->getMethodName(), $method->getArgumentsWildcard()), $method);
}
示例10: let
/**
* @param \Prophecy\Prophecy\ObjectProphecy $objectProphecy
* @param \Prophecy\Prophecy\MethodProphecy $methodProphecy
* @param \Prophecy\Call\Call $call1
* @param \Prophecy\Call\Call $call2
*/
function let($objectProphecy, $methodProphecy, $call1, $call2)
{
$methodProphecy->getObjectProphecy()->willReturn($objectProphecy);
$this->beConstructedWith('message', $methodProphecy, 5, array($call1, $call2));
}
示例11:
/**
* @param \Prophecy\Prophecy\MethodProphecy $methodProphecy1
* @param \Prophecy\Prophecy\MethodProphecy $methodProphecy2
* @param \Prophecy\Argument\ArgumentsWildcard $argumentsWildcard1
* @param \Prophecy\Argument\ArgumentsWildcard $argumentsWildcard2
*/
function it_throws_AggregateException_during_checkPredictions_if_predictions_fail($methodProphecy1, $methodProphecy2, $argumentsWildcard1, $argumentsWildcard2)
{
$methodProphecy1->getMethodName()->willReturn('getName');
$methodProphecy1->getArgumentsWildcard()->willReturn($argumentsWildcard1);
$methodProphecy1->checkPrediction()->willThrow('Prophecy\\Exception\\Prediction\\AggregateException');
$methodProphecy2->getMethodName()->willReturn('setName');
$methodProphecy2->getArgumentsWildcard()->willReturn($argumentsWildcard2);
$methodProphecy2->checkPrediction()->willThrow('Prophecy\\Exception\\Prediction\\AggregateException');
$this->addMethodProphecy($methodProphecy1);
$this->addMethodProphecy($methodProphecy2);
$this->shouldThrow('Prophecy\\Exception\\Prediction\\AggregateException')->duringCheckProphecyMethodsPredictions();
}
示例12: 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());
}
}
示例13: addMethodProphecy
/**
* Adds method prophecy to object prophecy.
*
* @param MethodProphecy $methodProphecy
*
* @throws \Prophecy\Exception\Prophecy\MethodProphecyException If method prophecy doesn't
* have arguments wildcard
*/
public function addMethodProphecy(MethodProphecy $methodProphecy)
{
$argumentsWildcard = $methodProphecy->getArgumentsWildcard();
if (null === $argumentsWildcard) {
throw new MethodProphecyException(sprintf("Can not add prophecy for a method `%s::%s()`\n" . "as you did not specify arguments wildcard for it.", get_class($this->reveal()), $methodProphecy->getMethodName()), $methodProphecy);
}
$methodName = $methodProphecy->getMethodName();
if (!isset($this->methodProphecies[$methodName])) {
$this->methodProphecies[$methodName] = array();
}
$this->methodProphecies[$methodName][] = $methodProphecy;
}
示例14: let
function let(ObjectProphecy $objectProphecy, MethodProphecy $methodProphecy)
{
$methodProphecy->getObjectProphecy()->willReturn($objectProphecy);
$this->beConstructedWith('message', $methodProphecy);
}
示例15: __construct
public function __construct($message, MethodProphecy $methodProphecy)
{
parent::__construct($message, $methodProphecy->getObjectProphecy());
$this->methodProphecy = $methodProphecy;
}