Skip to content

Commit

Permalink
Merge pull request #7 from BaguettePHP/add-php54-ci
Browse files Browse the repository at this point in the history
Setup CI for PHP 5.4 to 8.1
  • Loading branch information
zonuexe authored Apr 19, 2022
2 parents 09d6b2a + 552649d commit 25ddf07
Show file tree
Hide file tree
Showing 8 changed files with 88 additions and 12 deletions.
51 changes: 51 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
name: Test
on:
workflow_dispatch:
pull_request:
branches:
- master
paths-ignore:
- '**.md'
push:
branches:
- master
paths-ignore:
- '**.md'
jobs:
run:
name: Run
runs-on: ${{ matrix.operating-system }}
strategy:
fail-fast: false
matrix:
operating-system: [ubuntu-20.04]
php-versions: ['5.4', '5.5', '5.6', '7.0', '7.1', '7.2', '7.3', '7.4', '8.0', '8.1']
env:
key: cache-v1
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Setup PHP with tools
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php-versions }}
extensions: mbstring, intl, opcache, xdebug, xml
tools: composer, cs2pr
- name: Get Composer cache directory
id: composer-cache-dir
run: |
echo "::set-output name=dir::$(composer config cache-files-dir)"
- name: Restore composer cache
id: composer-cache
uses: actions/cache@v3
with:
path: ${{ steps.composer-cache-dir.outputs.dir }}
key: ${{ runner.os }}-composer-${{ hashFiles('composer.lock') }}
restore-keys: |
${{ runner.os }}-composer-
- name: Remove composer.lock
run: rm -f composer.lock
- name: Setup Composer
run: composer install
- name: Run PHPUnit tests
run: vendor/bin/phpunit
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
/composer.lock
/phpunit.xml
/vendor/*
/.phpunit.result.cache
/.idea
/*.iml
/tests/db.sq3
Expand Down
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
TetoSQL
=======

[![Test](https://github.com/BaguettePHP/TetoSQL/actions/workflows/test.yml/badge.svg)](https://github.com/BaguettePHP/TetoSQL/actions/workflows/test.yml)
[![lang:PHP 8.1](https://img.shields.io/badge/lang-PHP%208.1-brightgreen.svg)](https://php.net/manual/migration82.php)
[![lang:PHP 5.4](https://img.shields.io/badge/lang-PHP%205.4-green.svg)](https://php.net/downloads.php)

[PHP Data Objects](http://php.net/manual/book.pdo.php)(PDO) wrapper and SQL Template for PHP

Features
Expand Down
10 changes: 8 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,13 @@
"keywords": [
"sql"
],
"require": {
"php": ">=5.4"
},
"require-dev": {
"phpunit/phpunit": " ^7.5 || ^4.8",
"php-coveralls/php-coveralls": "^2.1 || ^1.1",
"theseer/phpdox": "^0.12.0"
"phpunit/phpunit": "^8.5 || ^7.5 || ^4.8",
"yoast/phpunit-polyfills": "^1.0"
},
"autoload": {
"psr-4": {
Expand All @@ -35,5 +38,8 @@
},
"scripts": {
"test": "phpunit"
},
"config": {
"sort-packages": true
}
}
5 changes: 3 additions & 2 deletions src/Query.php
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,8 @@ function ($m) use ($pdo, $params, &$bind_values) {

$stmt = $pdo->prepare($sql);

foreach ($bind_values as $key => list($type, $value)) {
foreach ($bind_values as $key => $param) {
list($type, $value) = $param;
$stmt->bindParam($key, $value, $type);
}

Expand Down Expand Up @@ -120,7 +121,7 @@ protected static function replaceHolder($pdo, $key, $type, $value, &$bind_values
foreach ($value as $i => $item) {
$s = (string)$item;
if ($s < self::INT64_MIN || self::INT64_MAX < $s) {
throw new \DomainException(sprintf('param "%s[%i]" is integer out of range.', $key, $i));
throw new \DomainException(sprintf('param "%s[%d]" is integer out of range.', $key, $i));
}
}

Expand Down
13 changes: 9 additions & 4 deletions tests/Query/ReplaceHolderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

use Teto\SQL\Query;
use Teto\SQL\DummyPDO;
use Yoast\PHPUnitPolyfills\Polyfills\ExpectException;
use Yoast\PHPUnitPolyfills\Polyfills\ExpectPHPException;

/**
* @author USAMI Kenta <[email protected]>
Expand All @@ -12,6 +14,9 @@
*/
final class ReplaceHolderTest extends \PHPUnit\Framework\TestCase
{
use ExpectException;
use ExpectPHPException;

/**
* @dataProvider acceptDataProvider
*/
Expand All @@ -21,7 +26,7 @@ public function test_accept($type, $input, $expected)

$actual = call_user_func(\Closure::bind(function () use ($pdo, $type, $input) {
return Query::replaceHolder($pdo, ':key', "@{$type}", $input, $bind_values);
}, null, Query::class));
}, null, 'Teto\SQL\Query'));

$this->assertSame($expected, $actual);
}
Expand Down Expand Up @@ -59,12 +64,12 @@ public function test_raise_exception($type, $input, $expected_message)
{
$pdo = new DummyPDO();

$this->expectException(\DomainException::class);
$this->expectException('DomainException');
$this->expectExceptionMessage($expected_message);

call_user_func(\Closure::bind(function () use ($pdo, $type, $input) {
return Query::replaceHolder($pdo, ':key', $type, $input, $bind_values);
}, null, Query::class));
}, null, 'Teto\SQL\Query'));
}

public function rejeceptDataProvider()
Expand All @@ -79,7 +84,7 @@ public function rejeceptDataProvider()
['@int', '-9223372036854775809', 'param ":key" is integer out of range.'],
['@int[]', 0, 'param ":key" must be int array'],
['@int[]', [], 'param ":key" must be not empty int array'],
['@int[]', ['1', 'a', '3'], 'param ":key[]" is integer out of range.'],
['@int[]', ['1', 'a', '3'], 'param ":key[1]" is integer out of range.'],
['@string', [], 'param ":key" must be string or numeric'],
['@string[]', '', 'param ":key" must be string array'],
['@string[]', [], 'param ":key" must be not empty string array'],
Expand Down
5 changes: 4 additions & 1 deletion tests/QueryTest.php
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
<?php

namespace Teto\SQL;

use Yoast\PHPUnitPolyfills\TestCases\TestCase;

/**
* @author USAMI Kenta <[email protected]>
* @copyright 2016 USAMI Kenta
* @license https://github.com/BaguettePHP/TetoSQL/blob/master/LICENSE MPL-2.0
*/
final class QueryTest extends \PHPUnit\Framework\TestCase
final class QueryTest extends TestCase
{
public function test()
{
Expand Down
11 changes: 8 additions & 3 deletions tests/SQLite/QueryTest.php
Original file line number Diff line number Diff line change
@@ -1,14 +1,19 @@
<?php

namespace Teto\SQL\SQLite;

use Teto\SQL\Query;
use Yoast\PHPUnitPolyfills\TestCases\TestCase;

final class QueryTest extends \PHPUnit\Framework\TestCase
final class QueryTest extends TestCase
{
/** @var \PDO */
private $pdo;

public function setUp()
public function set_up()
{
parent::set_up();

$pdo = $this->getPDO();
$pdo->exec(self::DROP_TABLE);
$pdo->exec(self::CREATE_TABLE);
Expand Down Expand Up @@ -49,7 +54,7 @@ public function test()
':id' => $id,
])->fetch(\PDO::FETCH_ASSOC);

$this->assertSame($id, $actual['id']);
$this->assertEquals($id, $actual['id']);
$this->assertSame('Thirty-six Views of Mount Fuji', $actual['name']);

$blob = file_get_contents($img_file);
Expand Down

0 comments on commit 25ddf07

Please sign in to comment.