|
| 1 | +<?php |
| 2 | + |
| 3 | +namespace Neo4j\QueryAPI\Tests\Unit\Results; |
| 4 | + |
| 5 | +use Neo4j\QueryAPI\Results\ResultRow; |
| 6 | +use PHPUnit\Framework\TestCase; |
| 7 | +use OutOfBoundsException; |
| 8 | +use BadMethodCallException; |
| 9 | + |
| 10 | +class ResultRowUnitTest extends TestCase |
| 11 | +{ |
| 12 | + public function testOffsetGetReturnsValue(): void |
| 13 | + { |
| 14 | + $data = ['name' => 'Alice', 'age' => 25]; |
| 15 | + $row = new ResultRow($data); |
| 16 | + |
| 17 | + $this->assertEquals('Alice', $row->offsetGet('name')); |
| 18 | + $this->assertEquals(25, $row->offsetGet('age')); |
| 19 | + } |
| 20 | + |
| 21 | + public function testOffsetGetThrowsExceptionForInvalidKey(): void |
| 22 | + { |
| 23 | + $this->expectException(OutOfBoundsException::class); |
| 24 | + $this->expectExceptionMessage("Column invalid_key not found."); |
| 25 | + |
| 26 | + $data = ['name' => 'Alice']; |
| 27 | + $row = new ResultRow($data); |
| 28 | + |
| 29 | + $row->offsetGet('invalid_key'); |
| 30 | + } |
| 31 | + |
| 32 | + public function testOffsetExists(): void |
| 33 | + { |
| 34 | + $data = ['name' => 'Alice', 'age' => 25]; |
| 35 | + $row = new ResultRow($data); |
| 36 | + |
| 37 | + $this->assertTrue($row->offsetExists('name')); |
| 38 | + $this->assertTrue($row->offsetExists('age')); |
| 39 | + $this->assertFalse($row->offsetExists('invalid_key')); |
| 40 | + } |
| 41 | + |
| 42 | + public function testOffsetSetThrowsException(): void |
| 43 | + { |
| 44 | + $this->expectException(BadMethodCallException::class); |
| 45 | + $this->expectExceptionMessage("You can't set the value of column new_key."); |
| 46 | + |
| 47 | + $data = ['name' => 'Alice']; |
| 48 | + $row = new ResultRow($data); |
| 49 | + |
| 50 | + $row->offsetSet('new_key', 'value'); |
| 51 | + } |
| 52 | + |
| 53 | + public function testOffsetUnsetThrowsException(): void |
| 54 | + { |
| 55 | + $this->expectException(BadMethodCallException::class); |
| 56 | + $this->expectExceptionMessage("You can't Unset name."); |
| 57 | + |
| 58 | + $data = ['name' => 'Alice']; |
| 59 | + $row = new ResultRow($data); |
| 60 | + |
| 61 | + $row->offsetUnset('name'); |
| 62 | + } |
| 63 | + |
| 64 | + public function testGetReturnsValue(): void |
| 65 | + { |
| 66 | + $data = ['name' => 'Alice', 'age' => 25]; |
| 67 | + $row = new ResultRow($data); |
| 68 | + |
| 69 | + $this->assertEquals('Alice', $row->get('name')); |
| 70 | + $this->assertEquals(25, $row->get('age')); |
| 71 | + } |
| 72 | + |
| 73 | + public function testCount(): void |
| 74 | + { |
| 75 | + $data = ['name' => 'Alice', 'age' => 25]; |
| 76 | + $row = new ResultRow($data); |
| 77 | + |
| 78 | + $this->assertCount(2, $row); |
| 79 | + } |
| 80 | + |
| 81 | + public function testIterator(): void |
| 82 | + { |
| 83 | + $data = ['name' => 'Alice', 'age' => 25]; |
| 84 | + $row = new ResultRow($data); |
| 85 | + |
| 86 | + $values = []; |
| 87 | + foreach ($row as $key => $value) { |
| 88 | + $values[$key] = $value; |
| 89 | + } |
| 90 | + |
| 91 | + $this->assertEquals($data, $values); |
| 92 | + } |
| 93 | +} |
0 commit comments