Skip to content

Commit

Permalink
Bug: $data->datasets[] = $dataset->data; PHP error (#34)
Browse files Browse the repository at this point in the history
* #32 address the dataset error

* Update GitHub Actions to run php8.3
  • Loading branch information
bbsnly authored Jul 31, 2024
1 parent 165c5ea commit 23af1a1
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 3 deletions.
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());
}
}

0 comments on commit 23af1a1

Please # to comment.