Skip to content

Bug: $data->datasets[] = $dataset->data; PHP error #34

New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Merged
merged 2 commits into from
Jul 31, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/php.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ jobs:
- name: Setup PHP with PECL extension
uses: shivammathur/setup-php@v2
with:
php-version: '8.2'
php-version: '8.3'

- name: Validate composer.json and composer.lock
run: composer validate --strict
Expand Down
4 changes: 2 additions & 2 deletions src/Config/Config.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public function __construct(array $attributes = [])
* @param string $name
* @return mixed
*/
public function __get($name)
public function &__get($name)
{
return $this->attributes[$name];
}
Expand All @@ -29,7 +29,7 @@ public function __get($name)
* @param mixed $value
* @return $this
*/
public function __set($name, $value)
public function &__set($name, $value)
{
$this->attributes[$name] = $value;

Expand Down
27 changes: 27 additions & 0 deletions tests/ChartTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -302,4 +302,31 @@ public function test_can_create_mixed_chart_types()

$this->assertEquals($expected, $this->chart->get());
}

/**
* Test if the chart dataset can be set as an array without using a method.
*/
public function test_can_set_dataset_as_an_array()
{
$this->chart->type = 'bar';

$data = new Data;
$dataset = new Dataset();
$dataset->data = [5, 10, 20];
$data->datasets[] = $dataset->data;

$this->chart->data($data);

$expected = [
'type' => 'bar',
'data' => [
'datasets' => [
[5, 10, 20],
],
],
'options' => []
];

$this->assertEquals($expected, $this->chart->get());
}
}
Loading