Drupal8Test.php in Realistic Dummy Content 3.x
File
api/tests/src/Unit/Framework/Drupal8Test.php
View source
<?php
namespace Drupal\Tests\realistic_dummy_content_api\Unit\Framework;
use Drupal\realistic_dummy_content_api\Framework\Drupal8;
use PHPUnit\Framework\TestCase;
class Drupal8Test extends TestCase {
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);
}
public function providerSetEntityProperty() {
$class1 = new class {
function set($param, $value) {
$this->{$param} = $value;
}
};
$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,
],
];
}
}