Skip to content

Commit

Permalink
fixed tests
Browse files Browse the repository at this point in the history
  • Loading branch information
denisdulici committed Jun 16, 2022
1 parent 4636e94 commit ec950b9
Show file tree
Hide file tree
Showing 6 changed files with 108 additions and 114 deletions.
38 changes: 38 additions & 0 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
name: Tests

on: [push, pull_request]

jobs:
tests:
name: PHP ${{ matrix.php }} - Laravel ${{ matrix.laravel }} - ${{ matrix.stability }}

runs-on: ubuntu-latest

strategy:
matrix:
php: ['8.0', '8.1']
laravel: [8.*, 9.*]
stability: [prefer-lowest, prefer-stable]
include:
- laravel: 8.*
testbench: ^6.6
- laravel: 9.*
testbench: 7.*

steps:
- name: Checkout code
uses: actions/checkout@v3

- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php }}
extensions: bcmath, ctype, dom, fileinfo, intl, gd, json, mbstring, pdo, pdo_sqlite, openssl, sqlite, xml, zip
coverage: none

- name: Install dependencies
run: |
composer require "laravel/framework:${{ matrix.laravel }}" "orchestra/testbench:${{ matrix.testbench }}" --no-interaction --no-update
composer update --${{ matrix.stability }} --prefer-dist --no-interaction
- name: Execute tests
run: vendor/bin/phpunit
6 changes: 3 additions & 3 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,14 @@
}
],
"require": {
"php": ">=8.0",
"php": "^8.0",
"ext-json": "*",
"balping/json-raw-encoder": "^1.0",
"illuminate/support": ">=8.0"
},
"require-dev": {
"phpunit/phpunit": ">=9.0",
"orchestra/testbench": ">=6.0"
"phpunit/phpunit":"^9.5",
"orchestra/testbench": "^6.23|^7.4"
},
"autoload": {
"psr-4": {
Expand Down
14 changes: 14 additions & 0 deletions src/Options/PlotOptions.php
Original file line number Diff line number Diff line change
Expand Up @@ -227,4 +227,18 @@ public function getRadialBar(): array
{
return $this->radialBar;
}

public function setHorizontal(bool $horizontal): Chart
{
$this->setBar([
'horizontal' => $horizontal,
]);

return $this;
}

public function getHorizontal(): bool
{
return $this->getBar()['horizontal'];
}
}
4 changes: 1 addition & 3 deletions src/Types/HorizontalBar.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,7 @@ public function __construct()

$this->setType('bar');

$this->setBar([
'horizontal' => true,
]);
$this->setHorizontal(true);
}

public function addBar(string $name, array|Collection $data): HorizontalBar
Expand Down
105 changes: 52 additions & 53 deletions tests/Feature/ChartsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,96 +14,96 @@ class ChartsTest extends TestCase
public function it_tests_apexcharts_can_render_pie_charts_by_default()
{
$chart = (new Chart)->setTitle('Users Test Chart');
$this->assertEquals('donut', $chart->type());
$this->assertEquals('line', $chart->getType());

$anotherChart = (new Chart)->areaChart();
$this->assertEquals('area', $anotherChart->type());
$anotherChart = (new Chart)->setType('area');
$this->assertEquals('area', $anotherChart->getType());
}

/** @test */
public function it_tests_apexcharts_can_render_pie_chart()
{
$chart = (new Chart)->pieChart()
$chart = (new Chart)->setType('pie')
->setTitle('Posts')
->setSubtitle('From January To March')
->setLabels(['Product One', 'Product Two', 'Product Three'])
->setXAxis(['Jan', 'Feb', 'Mar'])
->setDataset([150, 120]);
->setSeries(['Jan', 'Feb', 'Mar'])
->setDataset('posts', 'pie', [150, 120]);

$this->assertEquals($chart, $chart->script()['chart']);
$this->assertEquals('pie', $chart->type());
$this->assertEquals('pie', $chart->getType());
}

/** @test */
public function it_tests_apexcharts_can_render_donut_chart()
{
$chart = (new Chart)->donutChart()
$chart = (new Chart)->setType('donut')
->setTitle('Posts')
->setXAxis(['Jan', 'Feb', 'Mar'])
->setDataset([150, 120]);
->setSeries(['Jan', 'Feb', 'Mar'])
->setDataset('posts', 'donut', [150, 120]);

$this->assertEquals($chart, $chart->script()['chart']);
$this->assertEquals('donut', $chart->type());
$this->assertEquals('donut', $chart->getType());
}

/** @test */
public function it_tests_larapex_can_render_radial_bar_charts()
{
$chart = (new Chart)->radialChart()
$chart = (new Chart)->setType('radial')
->setTitle('Products with more profit')
->setXAxis(['Jan', 'Feb', 'Mar'])
->setDataset([60, 40, 79]);
->setSeries(['Jan', 'Feb', 'Mar'])
->setDataset('products', 'radial', [60, 40, 79]);

$this->assertEquals($chart, $chart->script()['chart']);
$this->assertEquals('radialBar', $chart->type());
$this->assertEquals('radial', $chart->getType());
}

/** @test */
public function it_tests_apexcharts_can_render_polar_chart()
{
$chart = (new Chart)->polarAreaChart()
$chart = (new Chart)->setType('polarArea')
->setTitle('Products with more profit')
->setXAxis(['Jan', 'Feb', 'Mar'])
->setDataset([60, 40, 79]);
->setSeries(['Jan', 'Feb', 'Mar'])
->setDataset('polarArea', 'radial', [60, 40, 79]);

$this->assertEquals($chart, $chart->script()['chart']);
$this->assertEquals('polarArea', $chart->type());
$this->assertEquals('polarArea', $chart->getType());
}

/** @test */
public function larapex_can_render_line_charts()
{
$chart = (new Chart)->lineChart()
$chart = (new Chart)->setType('line')
->setTitle('Total Users Monthly')
->setSubtitle('From January to March')
->setXAxis([
->setSeries([
'Jan', 'Feb', 'Mar'
])
->setDataset([
->setDataset('line', 'users', [
[
'name' => 'Active Users',
'data' => [250, 700, 1200]
]
])
->setHeight(250)
->setGrid(true)
->setStroke(1);
->setGridShow(true)
->setStrokeShow(true);

$this->assertEquals($chart->id(), $chart->container()['id']);
$this->assertEquals($chart->getId(), $chart->container()['chart']->getId());
$this->assertEquals($chart, $chart->script()['chart']);
$this->assertEquals('line', $chart->type());
$this->assertEquals('line', $chart->getType());
}

/** @test */
public function it_tests_apexcharts_can_create_an_area_chart()
{
$chart = (new Chart)->areaChart()
$chart = (new Chart)->setType('area')
->setTitle('Total Users Monthly')
->setSubtitle('From January to March')
->setXAxis([
->setSeries([
'Jan', 'Feb', 'Mar'
])
->setDataset([
->setDataset('area', 'users', [
[
'name' => 'Active Users',
'data' => [250, 700, 1200]
Expand All @@ -114,18 +114,18 @@ public function it_tests_apexcharts_can_create_an_area_chart()
]
]);

$this->assertEquals($chart->id(), $chart->container()['id']);
$this->assertEquals($chart->getId(), $chart->container()['chart']->getId());
$this->assertEquals($chart, $chart->script()['chart']);
$this->assertEquals('area', $chart->type());
$this->assertEquals('area', $chart->getType());
}

/** @test */
public function it_tests_apexcharts_can_render_bar_charts()
{
$chart = (new Chart)->barChart()
$chart = (new Chart)->setType('bar')
->setTitle('Net Profit')
->setXAxis(['Jan', 'Feb', 'Mar'])
->setDataset([
->setSeries(['Jan', 'Feb', 'Mar'])
->setDataset('bar', 'profit', [
[
'name' => 'Company A',
'data' => [500, 1000, 1900]
Expand All @@ -152,19 +152,19 @@ public function it_tests_apexcharts_can_render_bar_charts()
]
]);

$this->assertEquals($chart->id(), $chart->container()['id']);
$this->assertEquals($chart->getId(), $chart->container()['chart']->getId());
$this->assertEquals($chart, $chart->script()['chart']);
$this->assertEquals('bar', $chart->type());
$this->assertEquals('bar', $chart->getType());
}

/** @test */
public function it_tests_apexcharts_can_render_horizontal_bar_chart()
{
$chart = (new Chart)->barChart()
$chart = (new Chart)->setType('bar')
->setTitle('Net Profit')
->setHorizontal(true)
->setXAxis(['Jan', 'Feb', 'Mar'])
->setDataset([
->setSeries(['Jan', 'Feb', 'Mar'])
->setDataset('bar', 'profit', [
[
'name' => 'Company A',
'data' => [500, 1000, 1900]
Expand All @@ -179,22 +179,21 @@ public function it_tests_apexcharts_can_render_horizontal_bar_chart()
]
]);

$this->assertEquals($chart->id(), $chart->container()['id']);
$this->assertEquals($chart->getId(), $chart->container()['chart']->getId());
$this->assertEquals($chart, $chart->script()['chart']);
$this->assertEquals('bar', $chart->type());
$chartHorizontalOrientation = json_decode($chart->horizontal(), 1)['horizontal'];
$this->assertTrue($chartHorizontalOrientation);
$this->assertEquals('bar', $chart->getType());
$this->assertTrue($chart->getHorizontal());
}

/** @test */
public function it_tests_apexcharts_can_render_heatmap_chart()
{
$chart = (new Chart)->heatMapChart()
$chart = (new Chart)->setType('heatmap')
->setTitle('Total Users')
->setXAxis([
->setSeries([
'Jan', 'Feb', 'Mar'
])
->setDataset([
->setDataset('heatmap', 'users', [
[
'name' => 'Users of Basic Plan',
'data' => [250, 700, 1200]
Expand All @@ -205,20 +204,20 @@ public function it_tests_apexcharts_can_render_heatmap_chart()
]
]);

$this->assertEquals($chart->id(), $chart->container()['id']);
$this->assertEquals($chart->getId(), $chart->container()['chart']->getId());
$this->assertEquals($chart, $chart->script()['chart']);
$this->assertEquals('heatmap', $chart->type());
$this->assertEquals('heatmap', $chart->getType());
}

/** @test */
public function it_tests_apexcharts_can_render_radar_chart()
{
$chart = (new Chart)->radarChart()
$chart = (new Chart)->setType('radar')
->setTitle('Total Users')
->setXAxis([
->setSeries([
'Jan', 'Feb', 'Mar'
])
->setDataset([
->setDataset('radar', 'users', [
[
'name' => 'Users of Basic Plan',
'data' => [250, 700, 1200]
Expand All @@ -229,8 +228,8 @@ public function it_tests_apexcharts_can_render_radar_chart()
]
]);

$this->assertEquals($chart->id(), $chart->container()['id']);
$this->assertEquals($chart->getId(), $chart->container()['chart']->getId());
$this->assertEquals($chart, $chart->script()['chart']);
$this->assertEquals('radar', $chart->type());
$this->assertEquals('radar', $chart->getType());
}
}
55 changes: 0 additions & 55 deletions tests/Unit/ChartsTest.php

This file was deleted.

0 comments on commit ec950b9

Please sign in to comment.