Updated to Drupal 8.5. Core Media not yet in use.
[yaffs-website] / web / core / tests / Drupal / Tests / PhpunitCompatibilityTrait.php
index 5cf020a8df6b999663a06aa624779f200eea6f46..e0a5f72846039a8216f792e8594f73788dc4e552 100644 (file)
@@ -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.
    *