From 23af1a1ec169ffdb978f5365448532a383f57af7 Mon Sep 17 00:00:00 2001 From: Anatoliy Babushka Date: Wed, 31 Jul 2024 20:22:44 +0200 Subject: [PATCH] Bug: $data->datasets[] = $dataset->data; PHP error (#34) * #32 address the dataset error * Update GitHub Actions to run php8.3 --- .github/workflows/php.yml | 2 +- src/Config/Config.php | 4 ++-- tests/ChartTest.php | 27 +++++++++++++++++++++++++++ 3 files changed, 30 insertions(+), 3 deletions(-) diff --git a/.github/workflows/php.yml b/.github/workflows/php.yml index 3a9b9f1..29a25b2 100644 --- a/.github/workflows/php.yml +++ b/.github/workflows/php.yml @@ -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 diff --git a/src/Config/Config.php b/src/Config/Config.php index cb167c3..2244799 100644 --- a/src/Config/Config.php +++ b/src/Config/Config.php @@ -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]; } @@ -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; diff --git a/tests/ChartTest.php b/tests/ChartTest.php index c99cac4..3430b06 100644 --- a/tests/ChartTest.php +++ b/tests/ChartTest.php @@ -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()); + } }