Skip to content

Commit f7439a4

Browse files
authored
Merge pull request #77 from carakas/switch-to-github-actions
Switch to GitHub actions
2 parents 8b4f9a5 + b46b178 commit f7439a4

11 files changed

Lines changed: 172 additions & 61 deletions

File tree

.github/workflows/run-tests.yml

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
name: run-tests
2+
3+
on: [push, pull_request]
4+
5+
jobs:
6+
phpunit:
7+
runs-on: ubuntu-latest
8+
strategy:
9+
fail-fast: true
10+
matrix:
11+
php: [7.1, 7.2, 7.3, 7.4]
12+
testsuite: ["unit"]
13+
name: PHPUnit - ${{ matrix.testsuite }} (PHP ${{ matrix.php }})
14+
services:
15+
mysql:
16+
image: mysql:5.7
17+
env:
18+
MYSQL_DATABASE: spoon_tests
19+
MYSQL_ROOT_PASSWORD: "spoon"
20+
ports:
21+
- 3306:3306
22+
options: --health-cmd="mysqladmin ping" --health-interval=10s --health-timeout=5s --health-retries=3
23+
steps:
24+
- name: Checkout code
25+
uses: actions/checkout@v2
26+
27+
- name: Cache dependencies
28+
uses: actions/cache@v2
29+
with:
30+
path: ~/.composer/cache/files
31+
key: dependencies-php-${{ matrix.php }}-composer-${{ hashFiles('composer.json') }}
32+
33+
- name: Setup PHP
34+
uses: shivammathur/setup-php@v2
35+
with:
36+
php-version: ${{ matrix.php }}
37+
extensions: dom, curl, libxml, mbstring, zip, pcntl, pdo, bcmath, intl, gd, exif, iconv, imagick
38+
coverage: xdebug # Switch to PCOV for a speed gain when we can use PHP 7.2 & PHPUnit 8.0.
39+
40+
- name: Install dependencies
41+
env:
42+
FORK_ENV: test
43+
run: composer install -o
44+
45+
- name: Execute tests
46+
run: vendor/bin/simple-phpunit --testsuite=${{ matrix.testsuite}} --coverage-clover=${{ matrix.testsuite}}.clover
47+
48+
- name: Upload Coverage report
49+
uses: codecov/codecov-action@v1
50+
with:
51+
file: ${{ matrix.testsuite}}.clover
52+
flags: ${{ matrix.testsuite}}

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
11
/vendor
2+
spoon/tests/tmp/spoon.zip

.travis.yml

Lines changed: 0 additions & 21 deletions
This file was deleted.

phpunit.xml.dist

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,10 @@
22
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
33
xsi:noNamespaceSchemaLocation="http://schema.phpunit.de/4.1/phpunit.xsd"
44
colors="true"
5+
bootstrap="vendor/autoload.php"
56
>
67
<testsuites>
7-
<testsuite name="Spoon library Test Suite">
8+
<testsuite name="unit">
89
<directory>./spoon/tests/</directory>
910
</testsuite>
1011
</testsuites>

spoon/tests/database/SpoonDatabaseLargeDataSet.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ class SpoonDatabaseLargeDataSet extends TestCase
3535
*/
3636
public function setup()
3737
{
38-
$this->db = new SpoonDatabase('mysql', 'localhost', 'spoon', 'spoon', 'spoon_tests');
38+
$this->db = new SpoonDatabase('mysql', '127.0.0.1', 'root', 'spoon', 'spoon_tests');
3939
}
4040

4141
/**

spoon/tests/database/SpoonDatabaseTest.php

Lines changed: 95 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -17,49 +17,59 @@ class SpoonDatabaseTest extends TestCase
1717
public function setup()
1818
{
1919
// create database object
20-
$this->db = new SpoonDatabase('mysql', 'localhost', 'spoon', 'spoon', 'spoon_tests');
20+
$this->db = new SpoonDatabase('mysql', '127.0.0.1', 'root', 'spoon', 'spoon_tests');
2121
}
2222

2323
public function testExecute()
2424
{
2525
// create database
26-
try { $this->db->execute('CREATE DATABASE IF NOT EXISTS spoon_tests'); }
27-
catch (SpoondatabaseException $e)
28-
{
26+
try {
27+
$this->db->execute('CREATE DATABASE IF NOT EXISTS spoon_tests');
28+
} catch (SpoondatabaseException $e) {
2929
$this->fail('You should manually create a database "spoon_tests"');
3030
}
3131

3232
// clear all tables
33-
if(count($this->db->getTables()) != 0) $this->db->drop($this->db->getTables());
33+
if (count($this->db->getTables()) != 0) {
34+
$this->db->drop($this->db->getTables());
35+
}
3436

3537
// create table users
36-
$this->db->execute("
38+
$this->db->execute(
39+
"
3740
CREATE TABLE `users` (
3841
`id` INT( 11 ) NOT NULL AUTO_INCREMENT PRIMARY KEY ,
3942
`username` VARCHAR( 255 ) NOT NULL ,
4043
`email` VARCHAR( 255 ) NOT NULL ,
4144
`developer` ENUM( 'Y', 'N' ) NOT NULL
42-
) ENGINE = MYISAM;");
45+
) ENGINE = MYISAM;"
46+
);
4347

4448
// create dummy table
45-
$this->db->execute("
49+
$this->db->execute(
50+
"
4651
CREATE TABLE `test` (
4752
`id` int(11) NOT NULL auto_increment,
4853
`value` varchar(255) NOT NULL,
4954
PRIMARY KEY (`id`)
50-
) ENGINE=MyISAM;");
55+
) ENGINE=MyISAM;"
56+
);
5157

5258
// create table with datetime
53-
$this->db->execute("
59+
$this->db->execute(
60+
"
5461
CREATE TABLE `date_test` (
5562
`id` int(11) NOT NULL auto_increment,
5663
`date` DATETIME NOT NULL,
5764
PRIMARY KEY (`id`)
58-
) ENGINE=MyISAM;");
65+
) ENGINE=MyISAM;"
66+
);
5967

6068
// do nothing
6169
$this->db->execute('SELECT * FROM users LIMIT ?', 10);
6270
$this->db->execute('SELECT * FROM users limit :limit', array(':limit' => 10));
71+
$this->expectException(PDOException::class);
72+
$this->db->execute('SELECT * FROM non_existing limit :limit', array(':limit' => 10));
6373
}
6474

6575
/**
@@ -113,8 +123,13 @@ public function testInsert()
113123
$this->db->insert('users', $aData);
114124

115125
// insert 1000 records
116-
for($i = 0; $i < 1000; $i++) $array[$i] = $aData;
126+
for ($i = 0; $i < 1000; $i++) {
127+
$array[$i] = $aData;
128+
}
117129
$this->db->insert('users', $array);
130+
$aData['id'] = 1;
131+
$this->expectException(PDOException::class);
132+
$this->db->insert('users', $aData);
118133
}
119134

120135
/**
@@ -127,14 +142,20 @@ public function testInsertDate()
127142
$this->db->insert('date_test', $aData);
128143

129144
// multiple rows data
130-
$aData = array(
131-
array(
145+
$aData = [
146+
[
132147
'date' => new DateTime(),
133-
),
134-
array(
148+
],
149+
[
135150
'date' => new DateTime(),
136-
),
137-
);
151+
],
152+
];
153+
$this->db->insert('date_test', $aData);
154+
$this->expectException(PDOException::class);
155+
$aData = [
156+
'id' => 1,
157+
'date' => new DateTime(),
158+
];
138159
$this->db->insert('date_test', $aData);
139160
}
140161

@@ -165,11 +186,17 @@ public function testGetVar()
165186
{
166187
$this->assertEquals('1001', $this->db->getVar('SELECT COUNT(id) FROM users'));
167188
$this->assertEquals('1001', $this->db->getVar('SELECT COUNT(id) FROM users WHERE id != ?', 1337));
168-
$this->assertEquals('1001', $this->db->getVar('SELECT COUNT(id) FROM users WHERE id != :id', array(':id' => 1337)));
189+
$this->assertEquals(
190+
'1001',
191+
$this->db->getVar('SELECT COUNT(id) FROM users WHERE id != :id', array(':id' => 1337))
192+
);
169193
$this->assertEquals('1', $this->db->getVar('SELECT id FROM users ORDER BY id ASC LIMIT 1'));
170194
$this->assertEquals('1', $this->db->getVar('SELECT id FROM users ORDER BY id ASC LIMIT ?', 1));
171195
$this->assertEquals('1', $this->db->getVar('SELECT id FROM users ORDER BY id ASC LIMIT ?', array(1)));
172-
$this->assertEquals('1', $this->db->getVar('SELECT id FROM users ORDER BY id ASC LIMIT :limit', array(':limit' => 1)));
196+
$this->assertEquals(
197+
'1',
198+
$this->db->getVar('SELECT id FROM users ORDER BY id ASC LIMIT :limit', array(':limit' => 1))
199+
);
173200
}
174201

175202
/**
@@ -178,10 +205,27 @@ public function testGetVar()
178205
public function testGetPairs()
179206
{
180207
$this->assertEquals(10, count($this->db->getPairs('SELECT id, username FROM users LIMIT 10;')));
181-
$this->assertEquals(10, count($this->db->getPairs('SELECT id, username FROM users WHERE id != ? LIMIT 10', 1337)));
182-
$this->assertEquals(10, count($this->db->getPairs('SELECT id, username FROM users WHERE id != ? LIMIT ?', array(1337, 10))));
183-
$this->assertEquals(10, count($this->db->getPairs('SELECT id, username FROM users WHERE id != :id LIMIT 10', array(':id' => 1337))));
184-
$this->assertEquals(10, count($this->db->getPairs('SELECT id, username FROM users WHERE id != :id LIMIT :limit', array(':id' => 1337, ':limit' => 10))));
208+
$this->assertEquals(
209+
10,
210+
count($this->db->getPairs('SELECT id, username FROM users WHERE id != ? LIMIT 10', 1337))
211+
);
212+
$this->assertEquals(
213+
10,
214+
count($this->db->getPairs('SELECT id, username FROM users WHERE id != ? LIMIT ?', array(1337, 10)))
215+
);
216+
$this->assertEquals(
217+
10,
218+
count($this->db->getPairs('SELECT id, username FROM users WHERE id != :id LIMIT 10', array(':id' => 1337)))
219+
);
220+
$this->assertEquals(
221+
10,
222+
count(
223+
$this->db->getPairs(
224+
'SELECT id, username FROM users WHERE id != :id LIMIT :limit',
225+
array(':id' => 1337, ':limit' => 10)
226+
)
227+
)
228+
);
185229
}
186230

187231
/**
@@ -206,13 +250,23 @@ public function testUpdate()
206250
$this->assertEquals(0, $this->db->getNumRows('SELECT id FROM users WHERE id = ?', 1337));
207251

208252
// update record
209-
$this->db->update('users', array('id' => 1337, 'username' => 'Bauffman', 'email' => 'erik@bauffman.be', 'developer' => 'Y'), 'id = ?', 2);
253+
$this->db->update(
254+
'users',
255+
array('id' => 1337, 'username' => 'Bauffman', 'email' => 'erik@bauffman.be', 'developer' => 'Y'),
256+
'id = ?',
257+
2
258+
);
210259

211260
// 1 record with id 1337
212261
$this->assertEquals(1, $this->db->getNumRows('SELECT id FROM users WHERE id = ?', 1337));
213262

214263
// update record
215-
$this->db->update('users', array('id' => 1337), 'id = :leet AND id != :bauffman', array(':leet' => 1337, ':bauffman' => 291));
264+
$this->db->update(
265+
'users',
266+
array('id' => 1337),
267+
'id = :leet AND id != :bauffman',
268+
array(':leet' => 1337, ':bauffman' => 291)
269+
);
216270
}
217271

218272
/**
@@ -222,16 +276,16 @@ public function testUpdateDate()
222276
{
223277
// data
224278
$aData['date'] = new DateTime();
225-
$this->db->update('date_test', $aData);
279+
self::assertTrue(is_int($this->db->update('date_test', $aData)));
226280
}
227281

228282
/**
229283
* @depends testExecute
230284
*/
231285
public function testOptimize()
232286
{
233-
$this->db->optimize('users');
234-
$this->db->optimize(array('users'));
287+
self::assertArraySubset([], $this->db->optimize('users'));
288+
self::assertArraySubset([], $this->db->optimize(array('users')));
235289
}
236290

237291
/**
@@ -261,8 +315,14 @@ public function testGetRecord()
261315
$data['email'] = 'erik@bauffman.be';
262316
$data['developer'] = 'Y';
263317

264-
$this->assertEquals($data, $this->db->getRecord('SELECT username, email, developer FROM users WHERE id = ?', 1337));
265-
$this->assertEquals($data, $this->db->getRecord('SELECT username, email, developer FROM users WHERE id = :id', array(':id' => 1337)));
318+
$this->assertEquals(
319+
$data,
320+
$this->db->getRecord('SELECT username, email, developer FROM users WHERE id = ?', 1337)
321+
);
322+
$this->assertEquals(
323+
$data,
324+
$this->db->getRecord('SELECT username, email, developer FROM users WHERE id = :id', array(':id' => 1337))
325+
);
266326
}
267327

268328
/**
@@ -271,7 +331,10 @@ public function testGetRecord()
271331
public function testGetRecords()
272332
{
273333
$this->assertEquals(100, count($this->db->getRecords('SELECT * FROM users WHERE id != ? LIMIT 100', 1337)));
274-
$this->assertEquals(100, count($this->db->getRecords('SELECT * FROM users WHERE id != :id LIMIT 100', array(':id' => 1337))));
334+
$this->assertEquals(
335+
100,
336+
count($this->db->getRecords('SELECT * FROM users WHERE id != :id LIMIT 100', array(':id' => 1337)))
337+
);
275338
}
276339

277340
/**

spoon/tests/datagrid/SpoonDataGridTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ public function testMain()
2121

2222
// create datagrid
2323
$dg = new SpoonDatagrid($source);
24+
self::assertInstanceOf(SpoonDataGrid::class, $dg);
2425
}
2526

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

3940
// fetch instance
40-
if($dg->getTemplate() instanceof SpoonTemplate) { /* do nothing */ }
41-
else throw new SpoonException('getTemplate should return an object of SpoonTemplate.');
41+
self::assertInstanceOf(SpoonTemplate::class, $dg->getTemplate(), 'getTemplate should return an object of SpoonTemplate.');
4242
}
4343
}

spoon/tests/feed/SpoonFeedRSSTest.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,5 +12,6 @@ class SpoonFeedRSSTest extends TestCase
1212
public function testMain()
1313
{
1414
$rss = new SpoonFeedRSS('Spoon Library', 'http://feeds2.feedburner.com/spoonlibrary', 'Spoon Library - RSS feed.');
15+
self::assertInstanceOf(SpoonFeedRSS::class, $rss);
1516
}
1617
}

spoon/tests/form/SpoonFormDropdownTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,7 @@ public function testDefaultElement()
163163
*/
164164
public function testParse()
165165
{
166-
$this->ddmDefaultElement->parse();
166+
self::assertTrue(is_string($this->ddmDefaultElement->parse()));
167167
}
168168

169169
public function testRequired()

0 commit comments

Comments
 (0)