diff --git a/core/modules/system/tests/src/Functional/Database/FakeRecord.php b/core/modules/system/tests/src/Functional/Database/FakeRecord.php index aa3a5fe35b..7d09bc1995 100644 --- a/core/modules/system/tests/src/Functional/Database/FakeRecord.php +++ b/core/modules/system/tests/src/Functional/Database/FakeRecord.php @@ -9,4 +9,22 @@ * rather than just a stdClass or array. This class is for testing that * functionality. (See testQueryFetchClass() below) */ -class FakeRecord {} +class FakeRecord { + + /** + * A class variable. + * + * @var integer + */ + public $fakeArg; + + /** + * Constructs a FakeRecord object with an optional constructor argument. + * + * @param integer $fakeArg + * A class variable. + */ + public function __construct($fakeArg = 0) { + $this->fakeArg = $fakeArg; + } +} diff --git a/core/tests/Drupal/KernelTests/Core/Database/FetchTest.php b/core/tests/Drupal/KernelTests/Core/Database/FetchTest.php index 9299e79a01..863f815785 100644 --- a/core/tests/Drupal/KernelTests/Core/Database/FetchTest.php +++ b/core/tests/Drupal/KernelTests/Core/Database/FetchTest.php @@ -88,10 +88,11 @@ public function testQueryFetchClass() { public function testQueryFetchObjectClass() { $records = 0; $query = $this->connection->query('SELECT [name] FROM {test} WHERE [age] = :age', [':age' => 25]); - while ($result = $query->fetchObject(FakeRecord::class)) { + while ($result = $query->fetchObject(FakeRecord::class, [1])) { $records += 1; $this->assertInstanceOf(FakeRecord::class, $result); $this->assertSame('John', $result->name, '25 year old is John.'); + $this->assertTrue($result->fakeArg == 1, "The record has received an argument through its constructor."); } $this->assertSame(1, $records, 'There is only one record.'); }