Skip to content

Commit eed0ff3

Browse files
authored
Merge pull request #10 from CodinPro/bug-9
Bug 9
2 parents 5628b54 + a26a6d5 commit eed0ff3

3 files changed

Lines changed: 8 additions & 6 deletions

File tree

src/DTOAccessorTrait.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ public function offsetExists($offset)
3939
*/
4040
private function offsetGetScalar($offset)
4141
{
42-
if (isset($this->data[$offset])) {
42+
if (array_key_exists($offset, $this->data)) {
4343
return $this->data[$offset];
4444
}
4545

@@ -54,7 +54,7 @@ private function offsetGetScalar($offset)
5454
*/
5555
private function getDefaultValue($offset)
5656
{
57-
if (isset($this->default[$offset])) {
57+
if (array_key_exists($offset, $this->default)) {
5858
return $this->default[$offset];
5959
}
6060

src/ExampleDTO.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,5 @@ class ExampleDTO extends DTO
77
protected $foo = true;
88
protected $bar = 'string';
99
protected $extra = ['a' => 'b'];
10+
protected $some;
1011
}

tests/ExampleDTOTest.php

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ public function testBuildFromArray()
1111
$this->assertEquals(true, $dto->get('foo'));
1212
$this->assertEquals('string', $dto->get('bar'));
1313
$this->assertEquals(['a' => 'b'], $dto->get('extra'));
14+
$this->assertEquals(null, $dto->get('some'));
1415
}
1516

1617
public function testBuildFromJson()
@@ -77,7 +78,7 @@ public function testCount()
7778
{
7879
$dto = new ExampleDTO();
7980

80-
$this->assertCount(3, $dto);
81+
$this->assertCount(4, $dto);
8182
}
8283

8384
public function testOffsetExists()
@@ -136,22 +137,22 @@ public function testToString()
136137
{
137138
$dto = new ExampleDTO();
138139

139-
$this->assertEquals('{"foo":true,"bar":"string","extra":{"a":"b"}}', (string)$dto);
140+
$this->assertEquals('{"foo":true,"bar":"string","extra":{"a":"b"},"some":null}', (string)$dto);
140141
}
141142

142143
public function testToStringWithCustomSerializer()
143144
{
144145
$dto = new ExampleDTO();
145146
$dto->setSerializer(new CustomSerializer());
146147

147-
$this->assertEquals('a:3:{s:3:"foo";b:1;s:3:"bar";s:6:"string";s:5:"extra";a:1:{s:1:"a";s:1:"b";}}', (string)$dto);
148+
$this->assertEquals('a:4:{s:3:"foo";b:1;s:3:"bar";s:6:"string";s:5:"extra";a:1:{s:1:"a";s:1:"b";}s:4:"some";N;}', (string)$dto);
148149
}
149150

150151
public function testCanIterateDTO()
151152
{
152153
$dto = new ExampleDTO();
153154

154-
$expectedArray = ['foo' => true, 'bar' => 'string', 'extra' => ['a' => 'b']];
155+
$expectedArray = ['foo' => true, 'bar' => 'string', 'extra' => ['a' => 'b'], 'some' => null];
155156
$gotArray = [];
156157

157158
foreach ($dto as $key => $value) {

0 commit comments

Comments
 (0)