forked from spoon/library
-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #77 from carakas/switch-to-github-actions
Switch to GitHub actions
- Loading branch information
Showing
11 changed files
with
172 additions
and
61 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
name: run-tests | ||
|
||
on: [push, pull_request] | ||
|
||
jobs: | ||
phpunit: | ||
runs-on: ubuntu-latest | ||
strategy: | ||
fail-fast: true | ||
matrix: | ||
php: [7.1, 7.2, 7.3, 7.4] | ||
testsuite: ["unit"] | ||
name: PHPUnit - ${{ matrix.testsuite }} (PHP ${{ matrix.php }}) | ||
services: | ||
mysql: | ||
image: mysql:5.7 | ||
env: | ||
MYSQL_DATABASE: spoon_tests | ||
MYSQL_ROOT_PASSWORD: "spoon" | ||
ports: | ||
- 3306:3306 | ||
options: --health-cmd="mysqladmin ping" --health-interval=10s --health-timeout=5s --health-retries=3 | ||
steps: | ||
- name: Checkout code | ||
uses: actions/checkout@v2 | ||
|
||
- name: Cache dependencies | ||
uses: actions/cache@v2 | ||
with: | ||
path: ~/.composer/cache/files | ||
key: dependencies-php-${{ matrix.php }}-composer-${{ hashFiles('composer.json') }} | ||
|
||
- name: Setup PHP | ||
uses: shivammathur/setup-php@v2 | ||
with: | ||
php-version: ${{ matrix.php }} | ||
extensions: dom, curl, libxml, mbstring, zip, pcntl, pdo, bcmath, intl, gd, exif, iconv, imagick | ||
coverage: xdebug # Switch to PCOV for a speed gain when we can use PHP 7.2 & PHPUnit 8.0. | ||
|
||
- name: Install dependencies | ||
env: | ||
FORK_ENV: test | ||
run: composer install -o | ||
|
||
- name: Execute tests | ||
run: vendor/bin/simple-phpunit --testsuite=${{ matrix.testsuite}} --coverage-clover=${{ matrix.testsuite}}.clover | ||
|
||
- name: Upload Coverage report | ||
uses: codecov/codecov-action@v1 | ||
with: | ||
file: ${{ matrix.testsuite}}.clover | ||
flags: ${{ matrix.testsuite}} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,2 @@ | ||
/vendor | ||
spoon/tests/tmp/spoon.zip |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -17,49 +17,59 @@ class SpoonDatabaseTest extends TestCase | |
public function setup() | ||
{ | ||
// create database object | ||
$this->db = new SpoonDatabase('mysql', 'localhost', 'spoon', 'spoon', 'spoon_tests'); | ||
$this->db = new SpoonDatabase('mysql', '127.0.0.1', 'root', 'spoon', 'spoon_tests'); | ||
} | ||
|
||
public function testExecute() | ||
{ | ||
// create database | ||
try { $this->db->execute('CREATE DATABASE IF NOT EXISTS spoon_tests'); } | ||
catch (SpoondatabaseException $e) | ||
{ | ||
try { | ||
$this->db->execute('CREATE DATABASE IF NOT EXISTS spoon_tests'); | ||
} catch (SpoondatabaseException $e) { | ||
$this->fail('You should manually create a database "spoon_tests"'); | ||
} | ||
|
||
// clear all tables | ||
if(count($this->db->getTables()) != 0) $this->db->drop($this->db->getTables()); | ||
if (count($this->db->getTables()) != 0) { | ||
$this->db->drop($this->db->getTables()); | ||
} | ||
|
||
// create table users | ||
$this->db->execute(" | ||
$this->db->execute( | ||
" | ||
CREATE TABLE `users` ( | ||
`id` INT( 11 ) NOT NULL AUTO_INCREMENT PRIMARY KEY , | ||
`username` VARCHAR( 255 ) NOT NULL , | ||
`email` VARCHAR( 255 ) NOT NULL , | ||
`developer` ENUM( 'Y', 'N' ) NOT NULL | ||
) ENGINE = MYISAM;"); | ||
) ENGINE = MYISAM;" | ||
); | ||
|
||
// create dummy table | ||
$this->db->execute(" | ||
$this->db->execute( | ||
" | ||
CREATE TABLE `test` ( | ||
`id` int(11) NOT NULL auto_increment, | ||
`value` varchar(255) NOT NULL, | ||
PRIMARY KEY (`id`) | ||
) ENGINE=MyISAM;"); | ||
) ENGINE=MyISAM;" | ||
); | ||
|
||
// create table with datetime | ||
$this->db->execute(" | ||
$this->db->execute( | ||
" | ||
CREATE TABLE `date_test` ( | ||
`id` int(11) NOT NULL auto_increment, | ||
`date` DATETIME NOT NULL, | ||
PRIMARY KEY (`id`) | ||
) ENGINE=MyISAM;"); | ||
) ENGINE=MyISAM;" | ||
); | ||
|
||
// do nothing | ||
$this->db->execute('SELECT * FROM users LIMIT ?', 10); | ||
$this->db->execute('SELECT * FROM users limit :limit', array(':limit' => 10)); | ||
$this->expectException(PDOException::class); | ||
$this->db->execute('SELECT * FROM non_existing limit :limit', array(':limit' => 10)); | ||
} | ||
|
||
/** | ||
|
@@ -113,8 +123,13 @@ public function testInsert() | |
$this->db->insert('users', $aData); | ||
|
||
// insert 1000 records | ||
for($i = 0; $i < 1000; $i++) $array[$i] = $aData; | ||
for ($i = 0; $i < 1000; $i++) { | ||
$array[$i] = $aData; | ||
} | ||
$this->db->insert('users', $array); | ||
$aData['id'] = 1; | ||
$this->expectException(PDOException::class); | ||
$this->db->insert('users', $aData); | ||
} | ||
|
||
/** | ||
|
@@ -127,14 +142,20 @@ public function testInsertDate() | |
$this->db->insert('date_test', $aData); | ||
|
||
// multiple rows data | ||
$aData = array( | ||
array( | ||
$aData = [ | ||
[ | ||
'date' => new DateTime(), | ||
), | ||
array( | ||
], | ||
[ | ||
'date' => new DateTime(), | ||
), | ||
); | ||
], | ||
]; | ||
$this->db->insert('date_test', $aData); | ||
$this->expectException(PDOException::class); | ||
$aData = [ | ||
'id' => 1, | ||
'date' => new DateTime(), | ||
]; | ||
$this->db->insert('date_test', $aData); | ||
} | ||
|
||
|
@@ -165,11 +186,17 @@ public function testGetVar() | |
{ | ||
$this->assertEquals('1001', $this->db->getVar('SELECT COUNT(id) FROM users')); | ||
$this->assertEquals('1001', $this->db->getVar('SELECT COUNT(id) FROM users WHERE id != ?', 1337)); | ||
$this->assertEquals('1001', $this->db->getVar('SELECT COUNT(id) FROM users WHERE id != :id', array(':id' => 1337))); | ||
$this->assertEquals( | ||
'1001', | ||
$this->db->getVar('SELECT COUNT(id) FROM users WHERE id != :id', array(':id' => 1337)) | ||
); | ||
$this->assertEquals('1', $this->db->getVar('SELECT id FROM users ORDER BY id ASC LIMIT 1')); | ||
$this->assertEquals('1', $this->db->getVar('SELECT id FROM users ORDER BY id ASC LIMIT ?', 1)); | ||
$this->assertEquals('1', $this->db->getVar('SELECT id FROM users ORDER BY id ASC LIMIT ?', array(1))); | ||
$this->assertEquals('1', $this->db->getVar('SELECT id FROM users ORDER BY id ASC LIMIT :limit', array(':limit' => 1))); | ||
$this->assertEquals( | ||
'1', | ||
$this->db->getVar('SELECT id FROM users ORDER BY id ASC LIMIT :limit', array(':limit' => 1)) | ||
); | ||
} | ||
|
||
/** | ||
|
@@ -178,10 +205,27 @@ public function testGetVar() | |
public function testGetPairs() | ||
{ | ||
$this->assertEquals(10, count($this->db->getPairs('SELECT id, username FROM users LIMIT 10;'))); | ||
$this->assertEquals(10, count($this->db->getPairs('SELECT id, username FROM users WHERE id != ? LIMIT 10', 1337))); | ||
$this->assertEquals(10, count($this->db->getPairs('SELECT id, username FROM users WHERE id != ? LIMIT ?', array(1337, 10)))); | ||
$this->assertEquals(10, count($this->db->getPairs('SELECT id, username FROM users WHERE id != :id LIMIT 10', array(':id' => 1337)))); | ||
$this->assertEquals(10, count($this->db->getPairs('SELECT id, username FROM users WHERE id != :id LIMIT :limit', array(':id' => 1337, ':limit' => 10)))); | ||
$this->assertEquals( | ||
10, | ||
count($this->db->getPairs('SELECT id, username FROM users WHERE id != ? LIMIT 10', 1337)) | ||
); | ||
$this->assertEquals( | ||
10, | ||
count($this->db->getPairs('SELECT id, username FROM users WHERE id != ? LIMIT ?', array(1337, 10))) | ||
); | ||
$this->assertEquals( | ||
10, | ||
count($this->db->getPairs('SELECT id, username FROM users WHERE id != :id LIMIT 10', array(':id' => 1337))) | ||
); | ||
$this->assertEquals( | ||
10, | ||
count( | ||
$this->db->getPairs( | ||
'SELECT id, username FROM users WHERE id != :id LIMIT :limit', | ||
array(':id' => 1337, ':limit' => 10) | ||
) | ||
) | ||
); | ||
} | ||
|
||
/** | ||
|
@@ -206,13 +250,23 @@ public function testUpdate() | |
$this->assertEquals(0, $this->db->getNumRows('SELECT id FROM users WHERE id = ?', 1337)); | ||
|
||
// update record | ||
$this->db->update('users', array('id' => 1337, 'username' => 'Bauffman', 'email' => '[email protected]', 'developer' => 'Y'), 'id = ?', 2); | ||
$this->db->update( | ||
'users', | ||
array('id' => 1337, 'username' => 'Bauffman', 'email' => '[email protected]', 'developer' => 'Y'), | ||
'id = ?', | ||
2 | ||
); | ||
|
||
// 1 record with id 1337 | ||
$this->assertEquals(1, $this->db->getNumRows('SELECT id FROM users WHERE id = ?', 1337)); | ||
|
||
// update record | ||
$this->db->update('users', array('id' => 1337), 'id = :leet AND id != :bauffman', array(':leet' => 1337, ':bauffman' => 291)); | ||
$this->db->update( | ||
'users', | ||
array('id' => 1337), | ||
'id = :leet AND id != :bauffman', | ||
array(':leet' => 1337, ':bauffman' => 291) | ||
); | ||
} | ||
|
||
/** | ||
|
@@ -222,16 +276,16 @@ public function testUpdateDate() | |
{ | ||
// data | ||
$aData['date'] = new DateTime(); | ||
$this->db->update('date_test', $aData); | ||
self::assertTrue(is_int($this->db->update('date_test', $aData))); | ||
} | ||
|
||
/** | ||
* @depends testExecute | ||
*/ | ||
public function testOptimize() | ||
{ | ||
$this->db->optimize('users'); | ||
$this->db->optimize(array('users')); | ||
self::assertArraySubset([], $this->db->optimize('users')); | ||
self::assertArraySubset([], $this->db->optimize(array('users'))); | ||
} | ||
|
||
/** | ||
|
@@ -261,8 +315,14 @@ public function testGetRecord() | |
$data['email'] = '[email protected]'; | ||
$data['developer'] = 'Y'; | ||
|
||
$this->assertEquals($data, $this->db->getRecord('SELECT username, email, developer FROM users WHERE id = ?', 1337)); | ||
$this->assertEquals($data, $this->db->getRecord('SELECT username, email, developer FROM users WHERE id = :id', array(':id' => 1337))); | ||
$this->assertEquals( | ||
$data, | ||
$this->db->getRecord('SELECT username, email, developer FROM users WHERE id = ?', 1337) | ||
); | ||
$this->assertEquals( | ||
$data, | ||
$this->db->getRecord('SELECT username, email, developer FROM users WHERE id = :id', array(':id' => 1337)) | ||
); | ||
} | ||
|
||
/** | ||
|
@@ -271,7 +331,10 @@ public function testGetRecord() | |
public function testGetRecords() | ||
{ | ||
$this->assertEquals(100, count($this->db->getRecords('SELECT * FROM users WHERE id != ? LIMIT 100', 1337))); | ||
$this->assertEquals(100, count($this->db->getRecords('SELECT * FROM users WHERE id != :id LIMIT 100', array(':id' => 1337)))); | ||
$this->assertEquals( | ||
100, | ||
count($this->db->getRecords('SELECT * FROM users WHERE id != :id LIMIT 100', array(':id' => 1337))) | ||
); | ||
} | ||
|
||
/** | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.