Skip to content

Commit 25ddf07

Browse files
authored
Merge pull request #7 from BaguettePHP/add-php54-ci
Setup CI for PHP 5.4 to 8.1
2 parents 09d6b2a + 552649d commit 25ddf07

File tree

8 files changed

+88
-12
lines changed

8 files changed

+88
-12
lines changed

.github/workflows/test.yml

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
name: Test
2+
on:
3+
workflow_dispatch:
4+
pull_request:
5+
branches:
6+
- master
7+
paths-ignore:
8+
- '**.md'
9+
push:
10+
branches:
11+
- master
12+
paths-ignore:
13+
- '**.md'
14+
jobs:
15+
run:
16+
name: Run
17+
runs-on: ${{ matrix.operating-system }}
18+
strategy:
19+
fail-fast: false
20+
matrix:
21+
operating-system: [ubuntu-20.04]
22+
php-versions: ['5.4', '5.5', '5.6', '7.0', '7.1', '7.2', '7.3', '7.4', '8.0', '8.1']
23+
env:
24+
key: cache-v1
25+
steps:
26+
- name: Checkout
27+
uses: actions/checkout@v3
28+
- name: Setup PHP with tools
29+
uses: shivammathur/setup-php@v2
30+
with:
31+
php-version: ${{ matrix.php-versions }}
32+
extensions: mbstring, intl, opcache, xdebug, xml
33+
tools: composer, cs2pr
34+
- name: Get Composer cache directory
35+
id: composer-cache-dir
36+
run: |
37+
echo "::set-output name=dir::$(composer config cache-files-dir)"
38+
- name: Restore composer cache
39+
id: composer-cache
40+
uses: actions/cache@v3
41+
with:
42+
path: ${{ steps.composer-cache-dir.outputs.dir }}
43+
key: ${{ runner.os }}-composer-${{ hashFiles('composer.lock') }}
44+
restore-keys: |
45+
${{ runner.os }}-composer-
46+
- name: Remove composer.lock
47+
run: rm -f composer.lock
48+
- name: Setup Composer
49+
run: composer install
50+
- name: Run PHPUnit tests
51+
run: vendor/bin/phpunit

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
/composer.lock
66
/phpunit.xml
77
/vendor/*
8+
/.phpunit.result.cache
89
/.idea
910
/*.iml
1011
/tests/db.sq3

README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
TetoSQL
22
=======
33

4+
[![Test](https://github.com/BaguettePHP/TetoSQL/actions/workflows/test.yml/badge.svg)](https://github.com/BaguettePHP/TetoSQL/actions/workflows/test.yml)
5+
[![lang:PHP 8.1](https://img.shields.io/badge/lang-PHP%208.1-brightgreen.svg)](https://php.net/manual/migration82.php)
6+
[![lang:PHP 5.4](https://img.shields.io/badge/lang-PHP%205.4-green.svg)](https://php.net/downloads.php)
7+
48
[PHP Data Objects](http://php.net/manual/book.pdo.php)(PDO) wrapper and SQL Template for PHP
59

610
Features

composer.json

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,13 @@
1414
"keywords": [
1515
"sql"
1616
],
17+
"require": {
18+
"php": ">=5.4"
19+
},
1720
"require-dev": {
18-
"phpunit/phpunit": " ^7.5 || ^4.8",
1921
"php-coveralls/php-coveralls": "^2.1 || ^1.1",
20-
"theseer/phpdox": "^0.12.0"
22+
"phpunit/phpunit": "^8.5 || ^7.5 || ^4.8",
23+
"yoast/phpunit-polyfills": "^1.0"
2124
},
2225
"autoload": {
2326
"psr-4": {
@@ -35,5 +38,8 @@
3538
},
3639
"scripts": {
3740
"test": "phpunit"
41+
},
42+
"config": {
43+
"sort-packages": true
3844
}
3945
}

src/Query.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,8 @@ function ($m) use ($pdo, $params, &$bind_values) {
7272

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

75-
foreach ($bind_values as $key => list($type, $value)) {
75+
foreach ($bind_values as $key => $param) {
76+
list($type, $value) = $param;
7677
$stmt->bindParam($key, $value, $type);
7778
}
7879

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

tests/Query/ReplaceHolderTest.php

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44

55
use Teto\SQL\Query;
66
use Teto\SQL\DummyPDO;
7+
use Yoast\PHPUnitPolyfills\Polyfills\ExpectException;
8+
use Yoast\PHPUnitPolyfills\Polyfills\ExpectPHPException;
79

810
/**
911
* @author USAMI Kenta <[email protected]>
@@ -12,6 +14,9 @@
1214
*/
1315
final class ReplaceHolderTest extends \PHPUnit\Framework\TestCase
1416
{
17+
use ExpectException;
18+
use ExpectPHPException;
19+
1520
/**
1621
* @dataProvider acceptDataProvider
1722
*/
@@ -21,7 +26,7 @@ public function test_accept($type, $input, $expected)
2126

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

2631
$this->assertSame($expected, $actual);
2732
}
@@ -59,12 +64,12 @@ public function test_raise_exception($type, $input, $expected_message)
5964
{
6065
$pdo = new DummyPDO();
6166

62-
$this->expectException(\DomainException::class);
67+
$this->expectException('DomainException');
6368
$this->expectExceptionMessage($expected_message);
6469

6570
call_user_func(\Closure::bind(function () use ($pdo, $type, $input) {
6671
return Query::replaceHolder($pdo, ':key', $type, $input, $bind_values);
67-
}, null, Query::class));
72+
}, null, 'Teto\SQL\Query'));
6873
}
6974

7075
public function rejeceptDataProvider()
@@ -79,7 +84,7 @@ public function rejeceptDataProvider()
7984
['@int', '-9223372036854775809', 'param ":key" is integer out of range.'],
8085
['@int[]', 0, 'param ":key" must be int array'],
8186
['@int[]', [], 'param ":key" must be not empty int array'],
82-
['@int[]', ['1', 'a', '3'], 'param ":key[]" is integer out of range.'],
87+
['@int[]', ['1', 'a', '3'], 'param ":key[1]" is integer out of range.'],
8388
['@string', [], 'param ":key" must be string or numeric'],
8489
['@string[]', '', 'param ":key" must be string array'],
8590
['@string[]', [], 'param ":key" must be not empty string array'],

tests/QueryTest.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,15 @@
11
<?php
2+
23
namespace Teto\SQL;
34

5+
use Yoast\PHPUnitPolyfills\TestCases\TestCase;
6+
47
/**
58
* @author USAMI Kenta <[email protected]>
69
* @copyright 2016 USAMI Kenta
710
* @license https://github.com/BaguettePHP/TetoSQL/blob/master/LICENSE MPL-2.0
811
*/
9-
final class QueryTest extends \PHPUnit\Framework\TestCase
12+
final class QueryTest extends TestCase
1013
{
1114
public function test()
1215
{

tests/SQLite/QueryTest.php

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,19 @@
11
<?php
2+
23
namespace Teto\SQL\SQLite;
4+
35
use Teto\SQL\Query;
6+
use Yoast\PHPUnitPolyfills\TestCases\TestCase;
47

5-
final class QueryTest extends \PHPUnit\Framework\TestCase
8+
final class QueryTest extends TestCase
69
{
710
/** @var \PDO */
811
private $pdo;
912

10-
public function setUp()
13+
public function set_up()
1114
{
15+
parent::set_up();
16+
1217
$pdo = $this->getPDO();
1318
$pdo->exec(self::DROP_TABLE);
1419
$pdo->exec(self::CREATE_TABLE);
@@ -49,7 +54,7 @@ public function test()
4954
':id' => $id,
5055
])->fetch(\PDO::FETCH_ASSOC);
5156

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

5560
$blob = file_get_contents($img_file);

0 commit comments

Comments
 (0)