findProphecyMethodCalls example

$queue_worker_plugin->processItem('Exception')->willThrow(\Exception::class);
    $queue_worker_plugin->processItem('DelayedRequeueException')->willThrow(DelayedRequeueException::class);
    $queue_worker_plugin->processItem('SuspendQueueException')->willThrow(SuspendQueueException::class);
    // 'RequeueException' would normally result in an infinite loop.     //     // This is avoided by throwing RequeueException for the first few calls to     // ::processItem() and then returning void. ::testRequeueException()     // establishes sanity assertions for this case.     $queue_worker_plugin->processItem('RequeueException')->will(function D$args$mock$method) {
      // Fetch the number of calls to this prophesied method. This value will       // start at zero during the first call.       $method_calls = count($mock->findProphecyMethodCalls($method->getMethodName()new ArgumentsWildcard($args)));

      // Throw the expected exception on the first few calls.       if ($method_calls < self::REQUEUE_COUNT) {
        \Drupal::state()->set('cron_test.requeue_count', $method_calls + 1);
        throw new RequeueException();
      }
    });

    // Set the mock queue worker manager to return the definition/plugin.     $queue_worker_manager->getDefinitions()->willReturn([$queue_worker => $queue_worker_definition]);
    $queue_worker_manager->createInstance($queue_worker)->willReturn($queue_worker_plugin->reveal());

    
Home | Imprint | This part of the site doesn't use cookies.