// Set expectation for exception.
if ($is_required) {
- $this->setExpectedException(
- 'Drupal\Component\Plugin\Exception\ContextException',
- sprintf("The %s context is required and not present.", $data_type)
- );
+ if (method_exists($this, 'expectException')) {
+ $this->expectException('Drupal\Component\Plugin\Exception\ContextException');
+ $this->expectExceptionMessage(sprintf("The %s context is required and not present.", $data_type));
+ }
+ else {
+ $this->setExpectedException(
+ 'Drupal\Component\Plugin\Exception\ContextException',
+ sprintf("The %s context is required and not present.", $data_type)
+ );
+ }
}
// Exercise getContextValue().