You are here

class Drupal8Test in Realistic Dummy Content 3.x

Tests for \Drupal\realistic_dummy_content_api\Framework\Drupal8.

@group realistic_dummy_content

Hierarchy

  • class \Drupal\Tests\realistic_dummy_content_api\Unit\Framework\Drupal8Test extends \PHPUnit\Framework\TestCase

Expanded class hierarchy of Drupal8Test

File

api/tests/src/Unit/Framework/Drupal8Test.php, line 13

Namespace

Drupal\Tests\realistic_dummy_content_api\Unit\Framework
View source
class Drupal8Test extends TestCase {

  /**
   * Test for setEntityProperty().
   *
   * @param string $message
   *   The test message.
   * @param mixed $entity
   *   The mock entity.
   * @param mixed $property
   *   The mock property.
   * @param mixed $value
   *   The mock value.
   * @param mixed $expected
   *   The expected resulting entity.
   *
   * @cover ::setEntityProperty
   * @dataProvider providerSetEntityProperty
   */
  public function testSetEntityProperty(string $message, $entity, $property, $value, $expected) {
    $object = $this
      ->getMockBuilder(Drupal8::class)
      ->setMethods(NULL)
      ->disableOriginalConstructor()
      ->getMock();
    $output = $entity;
    $object
      ->setEntityProperty($output, $property, $value);
    if ($output != $expected) {
      print_r([
        'output' => $output,
        'expected' => $expected,
      ]);
    }
    $this
      ->assertTrue($output == $expected, $message);
  }

  /**
   * Provider for testSetEntityProperty().
   */
  public function providerSetEntityProperty() {

    // @codingStandardsIgnoreStart
    $class1 = new class {
      function set($param, $value) {
        $this->{$param} = $value;
      }

    };

    // @codingStandardsIgnoreEnd
    $class2 = $class1;
    $class2->whatever = "Hello World";
    return [
      [
        'message' => 'Base case',
        'entity' => $class1,
        'property' => 'whatever',
        'value' => 'Hello World',
        'expected' => $class2,
      ],
      [
        'message' => 'Value has "set" property',
        'entity' => $class1,
        'property' => 'whatever',
        'value' => [
          'set' => 'Hello World',
        ],
        'expected' => $class2,
      ],
    ];
  }

}

Members

Namesort descending Modifiers Type Description Overrides
Drupal8Test::providerSetEntityProperty public function Provider for testSetEntityProperty().
Drupal8Test::testSetEntityProperty public function Test for setEntityProperty().