Skip to content

Commit 23af1a1

Browse files
authored
Bug: $data->datasets[] = $dataset->data; PHP error (#34)
* #32 address the dataset error * Update GitHub Actions to run php8.3
1 parent 165c5ea commit 23af1a1

File tree

3 files changed

+30
-3
lines changed

3 files changed

+30
-3
lines changed

.github/workflows/php.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ jobs:
2020
- name: Setup PHP with PECL extension
2121
uses: shivammathur/setup-php@v2
2222
with:
23-
php-version: '8.2'
23+
php-version: '8.3'
2424

2525
- name: Validate composer.json and composer.lock
2626
run: composer validate --strict

src/Config/Config.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ public function __construct(array $attributes = [])
1717
* @param string $name
1818
* @return mixed
1919
*/
20-
public function __get($name)
20+
public function &__get($name)
2121
{
2222
return $this->attributes[$name];
2323
}
@@ -29,7 +29,7 @@ public function __get($name)
2929
* @param mixed $value
3030
* @return $this
3131
*/
32-
public function __set($name, $value)
32+
public function &__set($name, $value)
3333
{
3434
$this->attributes[$name] = $value;
3535

tests/ChartTest.php

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -302,4 +302,31 @@ public function test_can_create_mixed_chart_types()
302302

303303
$this->assertEquals($expected, $this->chart->get());
304304
}
305+
306+
/**
307+
* Test if the chart dataset can be set as an array without using a method.
308+
*/
309+
public function test_can_set_dataset_as_an_array()
310+
{
311+
$this->chart->type = 'bar';
312+
313+
$data = new Data;
314+
$dataset = new Dataset();
315+
$dataset->data = [5, 10, 20];
316+
$data->datasets[] = $dataset->data;
317+
318+
$this->chart->data($data);
319+
320+
$expected = [
321+
'type' => 'bar',
322+
'data' => [
323+
'datasets' => [
324+
[5, 10, 20],
325+
],
326+
],
327+
'options' => []
328+
];
329+
330+
$this->assertEquals($expected, $this->chart->get());
331+
}
305332
}

0 commit comments

Comments
 (0)