Skip to content

Commit b0cb2e3

Browse files
committed
Initial commit
0 parents  commit b0cb2e3

File tree

7 files changed

+253
-0
lines changed

7 files changed

+253
-0
lines changed

.github/workflows/main.yml

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
on: [push]
2+
3+
jobs:
4+
mediawiki-extension-action:
5+
runs-on: ubuntu-latest
6+
name: Dummy extension test
7+
steps:
8+
# check out the repository
9+
- name: Checkout
10+
uses: actions/checkout@v3
11+
- name: Test dummy extension
12+
uses: ./ # Uses an action in the root directory
13+
id: extension-test
14+
with:
15+
php: 7.4
16+
mwbranch: REL1_35
17+
extension: DummyExtension
18+
testgroup: extension-DummyExtension

DummyExtension.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<?php
2+
3+
namespace DummyExtension;
4+
5+
class DummyExtension {
6+
7+
public function testMe( $a, $b ) {
8+
return $a + $b;
9+
}
10+
11+
}

README.md

Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
# Mediawiki Extension PHPUnit Runner
2+
3+
The action is a [composite action](https://docs.github.com/en/actions/creating-actions/creating-a-composite-action)
4+
that uses the following actions to install an ephemeral MediaWiki instance with Composer and PHP on board and run
5+
PHPUnit tests for your extension repo:
6+
7+
* [shivammathur/setup-php](https://github.com/shivammathur/setup-php)
8+
* [actions/cache](https://github.com/actions/cache)
9+
* [actions/checkout](https://github.com/actions/checkout)
10+
11+
# Usage
12+
13+
```yaml
14+
- uses: actions/mediawiki-phpunit@v1
15+
with:
16+
php: 7.4
17+
mwbranch: REL1_35
18+
extension: DummyExtension
19+
testgroup: extension-DummyExtension
20+
```
21+
22+
# Inputs
23+
24+
* `php` - version of PHP to install
25+
* `mwbranch` - MediaWiki branch to install
26+
* `extension` - extension name to test (this should match the desired extension directory)
27+
* `testgroup` - @group of tests to run (this should match your extension group defined on unit tests)
28+
29+
# Example
30+
31+
The below is an example of how to setup your GitHub Actions workflow on extension repository:
32+
33+
`.github/workflows/main.yml`
34+
35+
```yaml
36+
name: Example
37+
38+
on:
39+
push:
40+
branches: [ master ]
41+
pull_request:
42+
branches: [ "*" ]
43+
44+
jobs:
45+
test:
46+
name: "PHPUnit: MW ${{ matrix.mw }}, PHP ${{ matrix.php }}"
47+
strategy:
48+
matrix:
49+
include:
50+
- mw: 'REL1_35'
51+
php: 7.4
52+
- mw: 'REL1_36'
53+
php: 7.4
54+
- mw: 'REL1_37'
55+
php: 7.4
56+
- mw: 'master'
57+
php: 7.4
58+
runs-on: ubuntu-latest
59+
steps:
60+
# check out the extension repository
61+
- name: Checkout
62+
uses: actions/checkout@v3
63+
# run the action to install MediaWiki, PHP, Composer
64+
# and run PHPUnit tests for the extension
65+
- name: Mediawiki PHPUnit
66+
uses: actions/mediawiki-phpunit@v1
67+
with:
68+
php: ${{ matrix.php }}
69+
mwbranch: ${{ matrix.mw }}
70+
extension: MyExtension
71+
testgroup: extension-MyExtension
72+
```
73+
74+
Example of adding a group to your extension tests:
75+
76+
`MyExtension/tests/phpunit/MyExtensionTest.php`
77+
78+
```php
79+
/**
80+
* @group extension-MyExtension
81+
*/
82+
class MyExtensionTest extends MediaWikiTestCase {
83+
// ...
84+
}
85+
```

action.yml

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
name: 'Mediawiki Extension PHPUnit Runner'
2+
description: 'Setups MediaWiki and runs PHPUnit test for an extension'
3+
author: 'WikiTeq'
4+
branding:
5+
color: yellow
6+
icon: book-open
7+
inputs:
8+
php:
9+
description: 'PHP version'
10+
required: true
11+
mwbranch:
12+
description: 'Mediawiki branch to test against'
13+
required: true
14+
extension:
15+
description: 'Extension name to test'
16+
required: true
17+
testgroup:
18+
description: 'Extension tests @group'
19+
required: true
20+
runs:
21+
using: 'composite'
22+
steps:
23+
- name: Setup PHP
24+
uses: shivammathur/setup-php@v2
25+
with:
26+
php-version: ${{ inputs.php }}
27+
extensions: mbstring, intl
28+
tools: composer:2.1.14
29+
30+
- name: Cache Composer cache
31+
uses: actions/cache@v2
32+
with:
33+
path: ~/.composer/cache
34+
key: composer-php${{ inputs.php }}
35+
36+
- name: Install MediaWiki
37+
run: bash $GITHUB_ACTION_PATH/install.sh ${{ inputs.mwbranch }} ${{ inputs.extension }}
38+
shell: bash
39+
40+
- uses: actions/checkout@v2
41+
with:
42+
path: mediawiki/extensions/${{ inputs.extension }}
43+
44+
- name: Composer update
45+
working-directory: mediawiki
46+
run: composer update
47+
shell: bash
48+
49+
- name: Run PHPUnit
50+
working-directory: mediawiki
51+
run: php tests/phpunit/phpunit.php --group ${{ inputs.testgroup }}
52+
shell: bash

extension.json

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
{
2+
"name": "DummyExtension",
3+
"version": "1.0",
4+
"author": [
5+
"Anonymous"
6+
],
7+
"url": "https://www.mediawiki.org/wiki/Extension:DummyExtension",
8+
"descriptionmsg": "dummyextension-desc",
9+
"type": "extension",
10+
"requires": {
11+
"MediaWiki": ">= 1.35.0"
12+
},
13+
"license-name": "GPL-2.0-or-later",
14+
"AutoloadClasses": {
15+
"DummyExtension\\DummyExtension": "DummyExtension.php"
16+
},
17+
"manifest_version": 2
18+
}

install.sh

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
#!/bin/sh -l
2+
3+
set -o pipefail
4+
5+
MW_BRANCH=$1
6+
EXTENSION_NAME=$2
7+
8+
wget https://github.com/wikimedia/mediawiki/archive/$MW_BRANCH.tar.gz -nv -q
9+
10+
tar -zxf $MW_BRANCH.tar.gz
11+
mv mediawiki-$MW_BRANCH mediawiki
12+
13+
cd mediawiki
14+
15+
composer -q install
16+
php maintenance/install.php --dbtype sqlite --dbuser root --dbname mw --dbpath $(pwd) --pass AdminPassword WikiName AdminUser > /dev/null
17+
18+
# echo 'error_reporting(E_ALL| E_STRICT);' >> LocalSettings.php
19+
# echo 'ini_set("display_errors", 1);' >> LocalSettings.php
20+
echo '$wgShowExceptionDetails = true;' >> LocalSettings.php
21+
echo '$wgShowDBErrorBacktrace = true;' >> LocalSettings.php
22+
echo '$wgDevelopmentWarnings = true;' >> LocalSettings.php
23+
24+
echo "wfLoadExtension( '$EXTENSION_NAME' );" >> LocalSettings.php
25+
26+
cat <<EOT >> composer.local.json
27+
{
28+
"require": {
29+
30+
},
31+
"extra": {
32+
"merge-plugin": {
33+
"merge-dev": true,
34+
"include": [
35+
"extensions/*/composer.json"
36+
]
37+
}
38+
}
39+
}
40+
EOT
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
<?php
2+
3+
use DummyExtension\DummyExtension;
4+
5+
/**
6+
* Class DummyExtensionTest
7+
* @group extension-DummyExtension
8+
*/
9+
class DummyExtensionTest extends MediaWikiLangTestCase {
10+
11+
public function setUp(): void {
12+
$this->setMwGlobals(
13+
[
14+
'wgDummyExtensionTestSetting' => false
15+
]
16+
);
17+
}
18+
19+
/**
20+
* @throws MWException
21+
* @covers \DummyExtension\DummyExtension::testMe
22+
*/
23+
public function testDummyTestMe() {
24+
$dummy = new DummyExtension();
25+
$result = $dummy->testMe( 5, 10 );
26+
$this->assertTrue( $result === 15 );
27+
}
28+
29+
}

0 commit comments

Comments
 (0)