diff --git a/core/modules/views/src/ResultRow.php b/core/modules/views/src/ResultRow.php index 81e504b2c3..c98aa6b222 100644 --- a/core/modules/views/src/ResultRow.php +++ b/core/modules/views/src/ResultRow.php @@ -82,7 +82,7 @@ public function __get(string $name): mixed { if (property_exists($this->data, $name)) { return $this->data->$name; } - throw new \RuntimeException("Property {$name} does not exist"); + throw new \UnexpectedValueException("Property {$name} does not exist"); } /** diff --git a/core/modules/views/tests/src/Unit/ResultRowTest.php b/core/modules/views/tests/src/Unit/ResultRowTest.php new file mode 100644 index 0000000000..7002a7baa3 --- /dev/null +++ b/core/modules/views/tests/src/Unit/ResultRowTest.php @@ -0,0 +1,62 @@ +row = new ResultRow([ + 'index' => 1, + 'data' => (object) [ + 'alpha' => 'foo', + 'beta' => 'bar', + ], + ]); + } + + /** + * @covers ::__construct + * @covers ::__set + * @covers ::__get + * @covers ::__isset + * @covers ::__unset + */ + public function testMagic(): void { + $this->assertTrue(isset($this->row->index)); + $this->assertTrue(isset($this->row->alpha)); + $this->assertTrue(isset($this->row->beta)); + $this->assertFalse(isset($this->row->getData()->index)); + $this->assertTrue(isset($this->row->getData()->alpha)); + $this->assertTrue(isset($this->row->getData()->beta)); + $this->assertSame(1, $this->row->index); + $this->assertSame('foo', $this->row->alpha); + $this->assertSame('bar', $this->row->beta); + $this->assertSame('foo', $this->row->getData()->alpha); + $this->assertSame('bar', $this->row->getData()->beta); + unset($this->row->beta); + $this->assertFalse(isset($this->row->beta)); + $this->assertFalse(isset($this->row->getData()->beta)); + $this->row->charlie = 'baz'; + $this->assertTrue(isset($this->row->charlie)); + $this->assertTrue(isset($this->row->getData()->charlie)); + $this->assertSame('baz', $this->row->charlie); + $this->assertSame('baz', $this->row->getData()->charlie); + $this->expectException(\UnexpectedValueException::class); + $this->expectExceptionMessage("Property zulu does not exist"); + $value = $this->row->zulu; + } + +}