Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

Add Tests #65

Open
wants to merge 22 commits into
base: master
Choose a base branch
from
Open
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
171 changes: 171 additions & 0 deletions .github/workflows/databases.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,171 @@
name: databases

on:
push:
branches:
- master
pull_request:
branches:
- master

jobs:
mysql_57:
runs-on: ubuntu-22.04

services:
mysql:
image: mysql:5.7
env:
MYSQL_ALLOW_EMPTY_PASSWORD: yes
MYSQL_DATABASE: laravel
ports:
- 3306:3306
options: --health-cmd="mysqladmin ping" --health-interval=10s --health-timeout=5s --health-retries=3

strategy:
fail-fast: true

name: MySQL 5.7

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

- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: 8.2
extensions: dom, curl, libxml, mbstring, zip, pcntl, pdo, sqlite, pdo_sqlite, bcmath, soap, intl, gd, exif, iconv, imagick, fileinfo
coverage: none

- name: Install dependencies
run: |
composer require "laravel/framework:11.*" "orchestra/testbench:9.*" --no-interaction --no-update
composer update --prefer-stable --prefer-dist --no-interaction --no-progress

- name: Execute tests
run: vendor/bin/pest

env:
DB_CONNECTION: mysql
DB_COLLATION: utf8mb4_unicode_ci

mysql_8:
runs-on: ubuntu-22.04

services:
mysql:
image: mysql:8
env:
MYSQL_ALLOW_EMPTY_PASSWORD: yes
MYSQL_DATABASE: laravel
ports:
- 3306:3306
options: --health-cmd="mysqladmin ping" --health-interval=10s --health-timeout=5s --health-retries=3

strategy:
fail-fast: true

name: MySQL 8.0

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

- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: 8.2
extensions: dom, curl, libxml, mbstring, zip, pcntl, pdo, sqlite, pdo_sqlite, bcmath, soap, intl, gd, exif, iconv, imagick, fileinfo
coverage: none

- name: Install dependencies
run: |
composer require "laravel/framework:11.*" "orchestra/testbench:9.*" --no-interaction --no-update
composer update --prefer-stable --prefer-dist --no-interaction --no-progress

- name: Execute tests
run: vendor/bin/phpunit tests/Integration/Database
env:
DB_CONNECTION: mysql

mariadb:
runs-on: ubuntu-22.04

services:
mariadb:
image: mariadb:10
env:
MARIADB_ALLOW_EMPTY_ROOT_PASSWORD: yes
MARIADB_DATABASE: laravel
ports:
- 3306:3306
options: --health-cmd="healthcheck.sh --connect --innodb_initialized" --health-interval=10s --health-timeout=5s --health-retries=3

strategy:
fail-fast: true

name: MariaDB 10

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

- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: 8.2
extensions: dom, curl, libxml, mbstring, zip, pcntl, pdo, sqlite, pdo_sqlite, bcmath, soap, intl, gd, exif, iconv, imagick, fileinfo
coverage: none

- name: Install dependencies
run: |
composer require "laravel/framework:11.*" "orchestra/testbench:9.*" --no-interaction --no-update
composer update --prefer-stable --prefer-dist --no-interaction --no-progress

- name: Execute tests
run: vendor/bin/pest
env:
DB_CONNECTION: mariadb

pgsql:
runs-on: ubuntu-22.04

services:
postgresql:
image: postgres:14
env:
POSTGRES_DB: laravel
POSTGRES_USER: forge
POSTGRES_PASSWORD: password
ports:
- 5432:5432
options: --health-cmd=pg_isready --health-interval=10s --health-timeout=5s --health-retries=3

strategy:
fail-fast: true

name: PostgreSQL 14

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

- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: 8.2
extensions: dom, curl, libxml, mbstring, zip, pcntl, pdo, sqlite, pdo_sqlite, bcmath, soap, intl, gd, exif, iconv, imagick, fileinfo
coverage: none

- name: Install dependencies
run: |
composer require "laravel/framework:11.*" "orchestra/testbench:9.*" --no-interaction --no-update
composer update --prefer-stable --prefer-dist --no-interaction --no-progress

- name: Execute tests
run: vendor/bin/pest
env:
DB_CONNECTION: pgsql
DB_USERNAME: forge
DB_PASSWORD: password
14 changes: 7 additions & 7 deletions .github/workflows/run-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@ name: run-tests
on:
push:
branches:
- main
- master
pull_request:
branches:
- main
- master

jobs:
test:
Expand All @@ -15,10 +15,10 @@ jobs:
strategy:
fail-fast: true
matrix:
os: [ubuntu-latest, windows-latest]
php: [8.0, 8.1, '8.2']
laravel: ['9.*', '10.*', '11.0', ^8.71]
stability: [prefer-lowest, prefer-stable]
os: [ ubuntu-latest, windows-latest ]
php: [ 8.0, 8.1, '8.2' ]
laravel: [ '9.*', '10.*', '11.*', ^8.71 ]
stability: [ prefer-lowest, prefer-stable ]
include:
- laravel: 10.*
testbench: 8.*
Expand All @@ -38,7 +38,7 @@ jobs:

steps:
- name: Checkout code
uses: actions/checkout@v2
uses: actions/checkout@v4

- name: Setup PHP
uses: shivammathur/setup-php@v2
Expand Down
66 changes: 66 additions & 0 deletions tests/AdapterTests/MySqlAdapterTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
<?php

use Flowframe\Trend\Adapters\MySqlAdapter;

it('formats column for minute interval', function () {
$adapter = resolve(MySqlAdapter::class);
$column = 'created_at';
$interval = 'minute';
$expectedFormat = "date_format(created_at, '%Y-%m-%d %H:%i:00')";

$result = $adapter->format($column, $interval);

expect($result)->toBe($expectedFormat);
});

it('formats column for hour interval', function () {
$adapter = resolve(MySqlAdapter::class);
$column = 'created_at';
$interval = 'hour';
$expectedFormat = "date_format(created_at, '%Y-%m-%d %H:00')";

$result = $adapter->format($column, $interval);

expect($result)->toBe($expectedFormat);
});

it('formats column for day interval', function () {
$adapter = resolve(MySqlAdapter::class);
$column = 'created_at';
$interval = 'day';
$expectedFormat = "date_format(created_at, '%Y-%m-%d')";

$result = $adapter->format($column, $interval);

expect($result)->toBe($expectedFormat);
});

it('formats column for month interval', function () {
$adapter = resolve(MySqlAdapter::class);
$column = 'created_at';
$interval = 'month';
$expectedFormat = "date_format(created_at, '%Y-%m')";

$result = $adapter->format($column, $interval);

expect($result)->toBe($expectedFormat);
});

it('formats column for year interval', function () {
$adapter = resolve(MySqlAdapter::class);
$column = 'created_at';
$interval = 'year';
$expectedFormat = "date_format(created_at, '%Y')";

$result = $adapter->format($column, $interval);

expect($result)->toBe($expectedFormat);
});

it('throws error for invalid interval', function () {
$adapter = resolve(MySqlAdapter::class);
$column = 'created_at';
$interval = 'invalid_interval';

expect(fn () => $adapter->format($column, $interval))->toThrow(Error::class);
});
66 changes: 66 additions & 0 deletions tests/AdapterTests/PgsqlAdapterTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
<?php

use Flowframe\Trend\Adapters\PgsqlAdapter;

it('formats column for minute interval', function () {
$adapter = resolve(PgsqlAdapter::class);
$column = 'created_at';
$interval = 'minute';
$expectedFormat = "to_char(created_at, 'YYYY-MM-DD HH24:MI:00')";

$result = $adapter->format($column, $interval);

expect($result)->toBe($expectedFormat);
});

it('formats column for hour interval', function () {
$adapter = resolve(PgsqlAdapter::class);
$column = 'created_at';
$interval = 'hour';
$expectedFormat = "to_char(created_at, 'YYYY-MM-DD HH24:00:00')";

$result = $adapter->format($column, $interval);

expect($result)->toBe($expectedFormat);
});

it('formats column for day interval', function () {
$adapter = resolve(PgsqlAdapter::class);
$column = 'created_at';
$interval = 'day';
$expectedFormat = "to_char(created_at, 'YYYY-MM-DD')";

$result = $adapter->format($column, $interval);

expect($result)->toBe($expectedFormat);
});

it('formats column for month interval', function () {
$adapter = resolve(PgsqlAdapter::class);
$column = 'created_at';
$interval = 'month';
$expectedFormat = "to_char(created_at, 'YYYY-MM')";

$result = $adapter->format($column, $interval);

expect($result)->toBe($expectedFormat);
});

it('formats column for year interval', function () {
$adapter = resolve(PgsqlAdapter::class);
$column = 'created_at';
$interval = 'year';
$expectedFormat = "to_char(created_at, 'YYYY')";

$result = $adapter->format($column, $interval);

expect($result)->toBe($expectedFormat);
});

it('throws error for invalid interval', function () {
$adapter = resolve(PgsqlAdapter::class);
$column = 'created_at';
$interval = 'invalid_interval';

expect(fn () => $adapter->format($column, $interval))->toThrow(Error::class);
});
Loading