Skip to content

Commit fc1d967

Browse files
committed
Data receiver tests
1 parent 78194be commit fc1d967

File tree

2 files changed

+32
-14
lines changed

2 files changed

+32
-14
lines changed

src/Core/DataReceiver.php

Lines changed: 3 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,9 @@ public function __construct(Endpoint $endpoint, $id = null)
4848
*/
4949
public function fill(array $data)
5050
{
51-
$this->data = $data;
51+
foreach ($data as $key => $value) {
52+
$this->data->{$key} = $value;
53+
}
5254

5355
return $this;
5456
}
@@ -107,17 +109,4 @@ public function __get($name)
107109
{
108110
return $this->data->{$name};
109111
}
110-
111-
/**
112-
* Set a attribute with array values.
113-
*
114-
* @param string $method
115-
* @param array $args
116-
*
117-
* @return stdClass
118-
*/
119-
public function __call($method, $args)
120-
{
121-
return $this->data->{$method} = (object) $args[0];
122-
}
123112
}

tests/DataReceiverTest.php

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
<?php
2+
3+
namespace JulianoBailao\DomusApi\Tests;
4+
5+
use JulianoBailao\DomusApi\Client;
6+
use JulianoBailao\DomusApi\Core\DataReceiver;
7+
use JulianoBailao\DomusApi\Endpoints\Lines;
8+
9+
class DataReceiverTest extends TestCase
10+
{
11+
public function testGlobal()
12+
{
13+
$client = new Client('foo.bar', '8080', 'username', 'password');
14+
$lines = new Lines($client);
15+
$data = new DataReceiver($lines);
16+
$data->fill([
17+
'foo' => 'bar',
18+
]);
19+
$data->bar = 'foo';
20+
21+
$this->assertEquals($data->bar, 'foo');
22+
$this->assertEquals($data->foo, 'bar');
23+
$this->assertEquals($data->toArray(), [
24+
'foo' => 'bar',
25+
'bar' => 'foo',
26+
'id' => null,
27+
]);
28+
}
29+
}

0 commit comments

Comments
 (0)