Skip to content

Commit 7c09972

Browse files
authored
Merge pull request #92 from iMattPro/updates
Update tests and add code coverage
2 parents 92f5a04 + b28124e commit 7c09972

5 files changed

Lines changed: 112 additions & 4 deletions

File tree

.github/codecov.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
fixes:
2+
- "/phpBB3/phpBB/ext/phpbb/googleanalytics/::"

.github/workflows/tests.yml

Lines changed: 52 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ jobs:
2525
strategy:
2626
matrix:
2727
include:
28-
- php: '7.1'
28+
- php: '7.2'
2929
db: "none"
3030
NOTESTS: 1
3131

@@ -113,6 +113,8 @@ jobs:
113113
db: "mysql:5.7"
114114
- php: '7.2'
115115
db: "mysql:5.7"
116+
COVERAGE: 1
117+
db_alias: "mysql:5.7 with Coverage"
116118
- php: '7.3'
117119
db: "mysql:5.7"
118120
- php: '7.4'
@@ -123,6 +125,8 @@ jobs:
123125
db: "mysql:5.7"
124126
- php: '8.1'
125127
db: "mysql:5.7"
128+
- php: '8.2'
129+
db: "mysql:5.7"
126130

127131
name: PHP ${{ matrix.php }} - ${{ matrix.db_alias != '' && matrix.db_alias || matrix.db }}
128132

@@ -171,12 +175,21 @@ jobs:
171175
echo "::set-output name=db::$db"
172176
173177
- name: Setup PHP
178+
if: ${{ matrix.COVERAGE != 1 }}
174179
uses: shivammathur/setup-php@v2
175180
with:
176181
php-version: ${{ matrix.php }}
177182
extensions: dom, curl, libxml, mbstring, zip, pcntl, pdo, mysqli, sqlite, pdo_sqlite, intl, gd, exif, iconv, sqlsrv, pdo_sqlsrv, ldap
178183
coverage: none
179184

185+
- name: Setup PHP with Coverage
186+
if: ${{ matrix.COVERAGE == 1 }}
187+
uses: shivammathur/setup-php@v2
188+
with:
189+
php-version: ${{ matrix.php }}
190+
extensions: dom, curl, libxml, mbstring, zip, pcntl, pdo, mysqli, sqlite, pdo_sqlite, intl, gd, exif, iconv, sqlsrv, pdo_sqlsrv, ldap
191+
coverage: xdebug
192+
180193
- name: Setup environment for phpBB
181194
env:
182195
DB: ${{steps.database-type.outputs.db}}
@@ -193,14 +206,36 @@ jobs:
193206
working-directory: ./phpBB3
194207

195208
- name: Setup PHPUnit files
196-
run: mkdir -p phpBB/ext/$EXTNAME/.github && cp .github/phpunit* $_
209+
env:
210+
DB: ${{steps.database-type.outputs.db}}
211+
COVERAGE: ${{ matrix.COVERAGE != 1 && '0' || '1' }}
212+
run: |
213+
if [ $COVERAGE == '1' ]
214+
then
215+
sed -n '1h;1!H;${;g;s/<\/php>/<\/php>\n\t<filter>\n\t\t<whitelist>\n\t\t\t<directory>..\/<\/directory>\n\t\t\t<exclude>\n\t\t\t\t<directory>..\/tests\/<\/directory>\n\t\t\t\t<directory>..\/language\/<\/directory>\n\t\t\t\t<directory>..\/migrations\/<\/directory>\n\t\t\t<\/exclude>\n\t\t<\/whitelist>\n\t<\/filter>/g;p;}' .github/phpunit-$DB-github.xml &> phpBB/ext/$EXTNAME/.github/phpunit-$DB-github.xml
216+
else
217+
mkdir -p phpBB/ext/$EXTNAME/.github && cp .github/phpunit* $_
218+
fi
197219
working-directory: ./phpBB3
198220

199221
- name: Run unit tests
200222
env:
201223
DB: ${{steps.database-type.outputs.db}}
202-
run: phpBB/vendor/bin/phpunit --configuration phpBB/ext/$EXTNAME/.github/phpunit-$DB-github.xml --bootstrap ./tests/bootstrap.php
224+
COVERAGE: ${{ matrix.COVERAGE != 1 && '0' || '1' }}
225+
run: |
226+
if [ $COVERAGE == '1' ]
227+
then
228+
phpBB/vendor/bin/phpunit --configuration phpBB/ext/$EXTNAME/.github/phpunit-$DB-github.xml --bootstrap ./tests/bootstrap.php --coverage-clover build/logs/clover.xml
229+
else
230+
phpBB/vendor/bin/phpunit --configuration phpBB/ext/$EXTNAME/.github/phpunit-$DB-github.xml --bootstrap ./tests/bootstrap.php
231+
fi
203232
working-directory: ./phpBB3
233+
234+
- name: Send code coverage
235+
if: ${{ matrix.COVERAGE == 1 }}
236+
uses: codecov/codecov-action@v1
237+
with:
238+
file: ./phpBB3/build/logs/clover.xml
204239
# END MySQL and MariaDB Job
205240

206241
# START PostgreSQL Job
@@ -221,6 +256,20 @@ jobs:
221256
db: "postgres:12"
222257
- php: '7.1'
223258
db: "postgres:13"
259+
- php: '7.2'
260+
db: "postgres:13"
261+
- php: '7.3'
262+
db: "postgres:13"
263+
- php: '7.4'
264+
db: "postgres:13"
265+
- php: '8.0'
266+
db: "postgres:12"
267+
- php: '8.0'
268+
db: "postgres:13"
269+
- php: '8.1'
270+
db: "postgres:14"
271+
- php: '8.2'
272+
db: "postgres:14"
224273

225274
name: PHP ${{ matrix.php }} - ${{ matrix.db }}
226275

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
A phpBB official extension that allows administrators to easily add Google Analytics to their forums.
44

55
[![Build Status](https://github.com/phpbb-extensions/googleanalytics/workflows/Tests/badge.svg)](https://github.com/phpbb-extensions/googleanalytics/actions)
6+
[![codecov](https://codecov.io/gh/phpbb-extensions/googleanalytics/branch/master/graph/badge.svg?token=1HQh953sBs)](https://codecov.io/gh/phpbb-extensions/googleanalytics)
67
[![Scrutinizer Code Quality](https://scrutinizer-ci.com/g/phpbb-extensions/googleanalytics/badges/quality-score.png?b=master)](https://scrutinizer-ci.com/g/phpbb-extensions/googleanalytics/?branch=master)
78

89
## Install

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"name": "phpbb/googleanalytics",
33
"type": "phpbb-extension",
44
"description": "A phpBB official extension that allows administrators to easily add Google Analytics to their forums.",
5-
"homepage": "https://www.phpbb.com",
5+
"homepage": "https://www.phpbb.com/customise/db/extension/googleanalytics/",
66
"version": "1.1.0-dev",
77
"keywords": ["phpbb", "extension", "google", "analytics"],
88
"license": "GPL-2.0-only",

tests/ext_test.php

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
<?php
2+
/**
3+
*
4+
* Google Analytics extension for the phpBB Forum Software package.
5+
*
6+
* @copyright (c) 2014, 2022 phpBB Limited <https://www.phpbb.com>
7+
* @license GNU General Public License, version 2 (GPL-2.0)
8+
*
9+
*/
10+
11+
namespace phpbb\googleanalytics\tests\system;
12+
13+
class ext_test extends \phpbb_test_case
14+
{
15+
/** @var \PHPUnit\Framework\MockObject\MockObject|\Symfony\Component\DependencyInjection\ContainerInterface */
16+
protected $container;
17+
18+
/** @var \PHPUnit\Framework\MockObject\MockObject|\phpbb\finder */
19+
protected $extension_finder;
20+
21+
/** @var \PHPUnit\Framework\MockObject\MockObject|\phpbb\db\migrator */
22+
protected $migrator;
23+
24+
/**
25+
* @inheritdoc
26+
*/
27+
protected function setUp(): void
28+
{
29+
parent::setUp();
30+
31+
// Stub the container
32+
$this->container = $this->getMockBuilder('\Symfony\Component\DependencyInjection\ContainerInterface')
33+
->disableOriginalConstructor()
34+
->getMock();
35+
36+
// Stub the ext finder and disable its constructor
37+
$this->extension_finder = $this->getMockBuilder('\phpbb\finder')
38+
->disableOriginalConstructor()
39+
->getMock();
40+
41+
// Stub the migrator and disable its constructor
42+
$this->migrator = $this->getMockBuilder('\phpbb\db\migrator')
43+
->disableOriginalConstructor()
44+
->getMock();
45+
}
46+
47+
/**
48+
* Test the extension will be enabled with a compatible version of phpBB
49+
*/
50+
public function test_enable()
51+
{
52+
$ext = new \phpbb\googleanalytics\ext($this->container, $this->extension_finder, $this->migrator, 'phpbb/googleanalytics', '');
53+
54+
self::assertTrue($ext->is_enableable());
55+
}
56+
}

0 commit comments

Comments
 (0)