X-Git-Url: http://www.aleph1.co.uk/gitweb/?p=yaffs-website;a=blobdiff_plain;f=web%2Fcore%2Ftests%2FDrupal%2FTests%2FPhpunitCompatibilityTrait.php;fp=web%2Fcore%2Ftests%2FDrupal%2FTests%2FPhpunitCompatibilityTrait.php;h=e0a5f72846039a8216f792e8594f73788dc4e552;hp=5cf020a8df6b999663a06aa624779f200eea6f46;hb=af6d1fb995500ae68849458ee10d66abbdcfb252;hpb=680c79a86e3ed402f263faeac92e89fb6d9edcc0 diff --git a/web/core/tests/Drupal/Tests/PhpunitCompatibilityTrait.php b/web/core/tests/Drupal/Tests/PhpunitCompatibilityTrait.php index 5cf020a8d..e0a5f7284 100644 --- a/web/core/tests/Drupal/Tests/PhpunitCompatibilityTrait.php +++ b/web/core/tests/Drupal/Tests/PhpunitCompatibilityTrait.php @@ -48,7 +48,7 @@ trait PhpunitCompatibilityTrait { * * @see https://www.drupal.org/node/2907725 */ - public function getMock($originalClassName, $methods = array(), array $arguments = array(), $mockClassName = '', $callOriginalConstructor = TRUE, $callOriginalClone = TRUE, $callAutoload = TRUE, $cloneArguments = FALSE, $callOriginalMethods = FALSE, $proxyTarget = NULL) { + public function getMock($originalClassName, $methods = [], array $arguments = [], $mockClassName = '', $callOriginalConstructor = TRUE, $callOriginalClone = TRUE, $callAutoload = TRUE, $cloneArguments = FALSE, $callOriginalMethods = FALSE, $proxyTarget = NULL) { if (!$this->supports('getMock')) { $mock = $this->getMockBuilder($originalClassName) ->setMethods($methods) @@ -116,6 +116,31 @@ trait PhpunitCompatibilityTrait { } } + /** + * Compatibility layer for PHPUnit 6 to support PHPUnit 4 code. + * + * @param mixed $class + * The expected exception class. + * @param string $message + * The expected exception message. + * @param int $exception_code + * The expected exception code. + */ + public function setExpectedException($class, $message = '', $exception_code = NULL) { + if (method_exists($this, 'expectException')) { + $this->expectException($class); + if (!empty($message)) { + $this->expectExceptionMessage($message); + } + if ($exception_code !== NULL) { + $this->expectExceptionCode($exception_code); + } + } + else { + parent::setExpectedException($class, $message, $exception_code); + } + } + /** * Checks if the trait is used in a class that has a method. *