Commit dffc7d7d authored by Tim Rohaly's avatar Tim Rohaly Committed by Tim Rohaly
Browse files

Issue #3265360 by TR: [D10] Test failure

parent d1531c94
Loading
Loading
Loading
Loading
+23 −91
Changes for tests/src/Unit/TestSession.php: 23 added lines, 91 removed lines.
Original line number Diff line number Diff line
@@ -2,37 +2,21 @@

namespace Drupal\Tests\rules\Unit;

use Symfony\Component\HttpFoundation\Session\SessionBagInterface;
use Symfony\Component\HttpFoundation\Session\SessionInterface;
// Symfony 6, which is used by Drupal 10, requires PHP 8 features that
// are not available in PHP 7. Specifically, the 'mixed' return type hint.
// @todo Remove this hack when Drupal 9 is no longer supported.
// @see https://www.drupal.org/project/rules/issues/3265360
if (version_compare(\Drupal::VERSION, '10') >= 0) {

  /**
   * Implements just the methods we need for the Rules unit tests.
   */
class TestSession implements SessionInterface {

  /**
   * Simulated session storage.
   *
   * @var array
   */
  protected $logs = [];

  /**
   * {@inheritdoc}
   */
  public function all() {
  }

  /**
   * {@inheritdoc}
   */
  public function clear() {
  }
  class TestSession extends TestSessionBase {

    /**
     * {@inheritdoc}
     */
  public function get($key, $default = NULL) {
    public function get(string $key, mixed $default = NULL): mixed {
      if (isset($this->logs[$key])) {
        return $this->logs[$key];
      }
@@ -44,55 +28,38 @@ class TestSession implements SessionInterface {
    /**
     * {@inheritdoc}
     */
  public function getBag($name) {
    public function remove(string $key): mixed {
      if (isset($this->logs[$key])) {
        $return = $this->logs[$key];
        unset($this->logs[$key]);
        return $return;
      }

  /**
   * {@inheritdoc}
   */
  public function getId() {
      else {
        return NULL;
      }

  /**
   * {@inheritdoc}
   */
  public function getMetadataBag() {
    }

  /**
   * {@inheritdoc}
   */
  public function getName() {
  }

  /**
   * {@inheritdoc}
   */
  public function has($name) {
}
// Otherwise use the PHP 7 compatible version of TestSession.
else {

  /**
   * {@inheritdoc}
   * Implements just the methods we need for the Rules unit tests.
   */
  public function invalidate($lifetime = NULL) {
  }
  class TestSession extends TestSessionBase {

    /**
     * {@inheritdoc}
     */
  public function isStarted() {
    public function get($key, $default = NULL) {
      if (isset($this->logs[$key])) {
        return $this->logs[$key];
      }

  /**
   * {@inheritdoc}
   */
  public function migrate($destroy = FALSE, $lifetime = NULL) {
      else {
        return $default;
      }

  /**
   * {@inheritdoc}
   */
  public function registerBag(SessionBagInterface $bag) {
    }

    /**
@@ -109,41 +76,6 @@ class TestSession implements SessionInterface {
      }
    }

  /**
   * {@inheritdoc}
   */
  public function replace(array $attributes) {
  }

  /**
   * {@inheritdoc}
   */
  public function save() {
  }

  /**
   * {@inheritdoc}
   */
  public function set($key, $value) {
    $this->logs[$key] = $value;
  }

  /**
   * {@inheritdoc}
   */
  public function setId($id) {
  }

  /**
   * {@inheritdoc}
   */
  public function setName($name) {
  }

  /**
   * {@inheritdoc}
   */
  public function start() {
  }

}
+124 −0
Changes for tests/src/Unit/TestSessionBase.php: 124 added lines, 0 removed lines.
Original line number Diff line number Diff line
<?php

namespace Drupal\Tests\rules\Unit;

use Symfony\Component\HttpFoundation\Session\SessionBagInterface;
use Symfony\Component\HttpFoundation\Session\SessionInterface;
use Symfony\Component\HttpFoundation\Session\Storage\MetadataBag;

/**
 * Implements just the methods we need for the Rules unit tests.
 */
abstract class TestSessionBase implements SessionInterface {

  /**
   * Simulated session storage.
   *
   * @var array
   */
  protected $logs = [];

  /**
   * {@inheritdoc}
   */
  public function all(): array {
  }

  /**
   * {@inheritdoc}
   */
  public function clear() {
  }

  /**
   * {@inheritdoc}
   */
  public function getBag($name): SessionBagInterface {
  }

  /**
   * {@inheritdoc}
   */
  public function getId(): string {
  }

  /**
   * {@inheritdoc}
   */
  public function getMetadataBag(): MetadataBag {
  }

  /**
   * {@inheritdoc}
   */
  public function getName(): string {
  }

  /**
   * {@inheritdoc}
   */
  public function has($name): bool {
  }

  /**
   * {@inheritdoc}
   */
  public function invalidate($lifetime = NULL): bool {
  }

  /**
   * {@inheritdoc}
   */
  public function isStarted(): bool {
  }

  /**
   * {@inheritdoc}
   */
  public function migrate($destroy = FALSE, $lifetime = NULL): bool {
  }

  /**
   * {@inheritdoc}
   */
  public function registerBag(SessionBagInterface $bag) {
  }

  /**
   * {@inheritdoc}
   */
  public function replace(array $attributes) {
  }

  /**
   * {@inheritdoc}
   */
  public function save() {
  }

  /**
   * {@inheritdoc}
   */
  public function set($key, $value) {
    $this->logs[$key] = $value;
  }

  /**
   * {@inheritdoc}
   */
  public function setId($id) {
  }

  /**
   * {@inheritdoc}
   */
  public function setName($name) {
  }

  /**
   * {@inheritdoc}
   */
  public function start(): bool {
  }

}