Skip to content

Commit

Permalink
Merge pull request #77 from carakas/switch-to-github-actions
Browse files Browse the repository at this point in the history
Switch to GitHub actions
  • Loading branch information
carakas committed Dec 9, 2020
2 parents 8b4f9a5 + b46b178 commit f7439a4
Show file tree
Hide file tree
Showing 11 changed files with 172 additions and 61 deletions.
52 changes: 52 additions & 0 deletions .github/workflows/run-tests.yml
@@ -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}}
1 change: 1 addition & 0 deletions .gitignore
@@ -1 +1,2 @@
/vendor
spoon/tests/tmp/spoon.zip
21 changes: 0 additions & 21 deletions .travis.yml

This file was deleted.

3 changes: 2 additions & 1 deletion phpunit.xml.dist
Expand Up @@ -2,9 +2,10 @@
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="http://schema.phpunit.de/4.1/phpunit.xsd"
colors="true"
bootstrap="vendor/autoload.php"
>
<testsuites>
<testsuite name="Spoon library Test Suite">
<testsuite name="unit">
<directory>./spoon/tests/</directory>
</testsuite>
</testsuites>
Expand Down
2 changes: 1 addition & 1 deletion spoon/tests/database/SpoonDatabaseLargeDataSet.php
Expand Up @@ -35,7 +35,7 @@ class SpoonDatabaseLargeDataSet extends TestCase
*/
public function setup()
{
$this->db = new SpoonDatabase('mysql', 'localhost', 'spoon', 'spoon', 'spoon_tests');
$this->db = new SpoonDatabase('mysql', '127.0.0.1', 'root', 'spoon', 'spoon_tests');
}

/**
Expand Down
127 changes: 95 additions & 32 deletions spoon/tests/database/SpoonDatabaseTest.php
Expand Up @@ -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));
}

/**
Expand Down Expand Up @@ -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);
}

/**
Expand All @@ -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);
}

Expand Down Expand Up @@ -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))
);
}

/**
Expand All @@ -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)
)
)
);
}

/**
Expand All @@ -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' => 'erik@bauffman.be', 'developer' => 'Y'), 'id = ?', 2);
$this->db->update(
'users',
array('id' => 1337, 'username' => 'Bauffman', 'email' => 'erik@bauffman.be', '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)
);
}

/**
Expand All @@ -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')));
}

/**
Expand Down Expand Up @@ -261,8 +315,14 @@ public function testGetRecord()
$data['email'] = 'erik@bauffman.be';
$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))
);
}

/**
Expand All @@ -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)))
);
}

/**
Expand Down
4 changes: 2 additions & 2 deletions spoon/tests/datagrid/SpoonDataGridTest.php
Expand Up @@ -21,6 +21,7 @@ public function testMain()

// create datagrid
$dg = new SpoonDatagrid($source);
self::assertInstanceOf(SpoonDataGrid::class, $dg);
}

public function testGetTemplate()
Expand All @@ -37,7 +38,6 @@ public function testGetTemplate()
$dg = new SpoonDatagrid($source);

// fetch instance
if($dg->getTemplate() instanceof SpoonTemplate) { /* do nothing */ }
else throw new SpoonException('getTemplate should return an object of SpoonTemplate.');
self::assertInstanceOf(SpoonTemplate::class, $dg->getTemplate(), 'getTemplate should return an object of SpoonTemplate.');
}
}
1 change: 1 addition & 0 deletions spoon/tests/feed/SpoonFeedRSSTest.php
Expand Up @@ -12,5 +12,6 @@ class SpoonFeedRSSTest extends TestCase
public function testMain()
{
$rss = new SpoonFeedRSS('Spoon Library', 'http://feeds2.feedburner.com/spoonlibrary', 'Spoon Library - RSS feed.');
self::assertInstanceOf(SpoonFeedRSS::class, $rss);
}
}
2 changes: 1 addition & 1 deletion spoon/tests/form/SpoonFormDropdownTest.php
Expand Up @@ -163,7 +163,7 @@ public function testDefaultElement()
*/
public function testParse()
{
$this->ddmDefaultElement->parse();
self::assertTrue(is_string($this->ddmDefaultElement->parse()));
}

public function testRequired()
Expand Down

0 comments on commit f7439a4

Please sign in to comment.