Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 37 additions & 3 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,30 +11,64 @@ jobs:

test:

runs-on: ubuntu-20.04
runs-on: ubuntu-22.04
continue-on-error: ${{ matrix.experimental }}

strategy:
matrix:
include:
- mediawiki_version: '1.35'
php_version: 7.4
database_type: mysql
database_image: "mysql:5.7"
coverage: false
experimental: false
- mediawiki_version: '1.39'
php_version: 8.1
database_type: mysql
database_image: "mysql:8"
coverage: false
experimental: false
- mediawiki_version: '1.43'
php_version: 8.2
database_type: mysql
database_image: "mysql:8"
coverage: false
experimental: false
- mediawiki_version: '1.44'
php_version: 8.3
database_type: mysql
database_image: "mysql:8"
coverage: false
experimental: true

env:
MW_VERSION: ${{ matrix.mediawiki_version }}
PHP_VERSION: ${{ matrix.php_version }}
DB_TYPE: ${{ matrix.database_type }}
DB_IMAGE: ${{ matrix.database_image }}


steps:
- name: Checkout
uses: actions/checkout@v3

uses: actions/checkout@v4
with:
submodules: recursive

- name: Update submodules
run: git submodule update --init --remote

- name: Run tests
run: make ci
if: matrix.coverage == false

- name: Run tests with coverage
run: make ci-coverage
if: matrix.coverage == true

- name: Upload code coverage
uses: codecov/codecov-action@v4
with:
token: ${{ secrets.CODECOV_TOKEN }}
files: coverage/php/coverage.xml
if: matrix.coverage == true
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[submodule "build"]
path = build
url = https://github.com/gesinn-it-pub/docker-compose-ci.git
10 changes: 6 additions & 4 deletions .phpcs.xml
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
<?xml version="1.0"?>
<ruleset>
<rule ref="./vendor/mediawiki/mediawiki-codesniffer/MediaWiki" />
<rule ref="./vendor/mediawiki/mediawiki-codesniffer/MediaWiki"></rule>
<file>.</file>
<exclude-pattern>lib/</exclude-pattern>
<exclude-pattern>vendor/</exclude-pattern>
</ruleset>
<exclude-pattern>/(vendor|conf)/</exclude-pattern>
<exclude-pattern type="relative">extensions/*</exclude-pattern>
<arg name="extensions" value="php"/>
<arg name="encoding" value="UTF-8"/>
</ruleset>
70 changes: 25 additions & 45 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,54 +1,34 @@
EXTENSION := QRLite
export

MW_VERSION ?= 1.35
# setup for docker-compose-ci build directory
# delete "build" directory to update docker-compose-ci

EXTENSION_FOLDER := /var/www/html/extensions/$(EXTENSION)
IMAGE_NAME := $(shell echo $(EXTENSION) | tr A-Z a-z}):test-$(MW_VERSION)-$(SMW_VERSION)
PWD := $(shell bash -c "pwd -W 2>/dev/null || pwd")# this way it works on Windows and Linux
DOCKER_RUN_ARGS := --rm -v $(PWD)/coverage:$(EXTENSION_FOLDER)/coverage -w $(EXTENSION_FOLDER) $(IMAGE_NAME)
docker_run := docker run $(DOCKER_RUN_ARGS)
ifeq (,$(wildcard ./build/Makefile))
$(shell git submodule update --init --remote)
endif

.PHONY: all
all:
EXTENSION=qrlite

# ======== CI ========
# docker images
MW_VERSION?=1.35
PHP_VERSION?=7.4
DB_TYPE?=mysql
DB_IMAGE?="mysql:5.7"

.PHONY: ci
ci: build test
# extensions
# Enables installation of apt packages for gd extension
OS_PACKAGES?="zlib1g-dev libpng-dev"

.PHONY: ci-coverage
ci-coverage: build test-coverage
# Enables installation of gd extension
PHP_EXTENSIONS?=gd

.PHONY: build
build:
docker build --tag $(IMAGE_NAME) \
--build-arg=MW_VERSION=$(MW_VERSION) \
.
# composer
# Enables "composer update" inside of extension
COMPOSER_EXT?=true

.PHONY: test
test: composer-test npm-test
# nodejs
# Enables node.js related tests and "npm install"
# NODE_JS?=true

.PHONY: test-coverage
test-coverage: composer-test-coverage

.PHONY: composer-test
composer-test:
$(docker_run) composer test

.PHONY: npm-test
npm-test:
$(docker_run) npm run test

.PHONY: composer-test-coverage
composer-test-coverage:
$(docker_run) composer test-coverage

.PHONY: bash
bash:
docker run -it -v $(PWD):/src $(DOCKER_RUN_ARGS) bash

.PHONY: dev-bash
dev-bash:
docker run -it --rm \
-v $(PWD):$(EXTENSION_FOLDER) -v $(EXTENSION_FOLDER)/node_modules -v $(EXTENSION_FOLDER)/vendor \
-w $(EXTENSION_FOLDER) $(IMAGE_NAME) bash
# check for build dir and git submodule init if it does not exist
include build/Makefile
1 change: 1 addition & 0 deletions build
Submodule build added at 3c2344
32 changes: 23 additions & 9 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,24 +17,38 @@
"endroid/qr-code": "^4.6"
},
"require-dev": {
"php-parallel-lint/php-parallel-lint": "1.3.2",
"mediawiki/mediawiki-codesniffer": "41.0.0",
"mediawiki/mediawiki-codesniffer": "43.0.0",
"mediawiki/mediawiki-phan-config": "0.14.0",
"mediawiki/minus-x": "1.1.3",
"php-parallel-lint/php-console-highlighter": "1.0.0",
"mediawiki/minus-x": "1.1.1"
"php-parallel-lint/php-parallel-lint": "1.4.0"
},
"scripts": {
"test": [
"parallel-lint . --exclude vendor --exclude node_modules",
"phpcs -p -s",
"minus-x check ."
"@analyze",
"@phpunit"
],
"test-coverage": [
"@analyze",
"@phpunit-coverage"
],
"analyze": [
"@lint",
"@phpcs"
],
"fix": [
"minus-x fix .",
"phpcbf"
]
"@phpcs-fix"
],
"lint": "parallel-lint . --exclude vendor --exclude node_modules",
"phpcs": "phpcs -ps",
"phpcs-fix": "phpcbf -p",
"phpunit": "php ../../tests/phpunit/phpunit.php -c phpunit.xml.dist --testdox",
"phpunit-coverage": "php ../../tests/phpunit/phpunit.php -c phpunit.xml.dist --testdox --coverage-text --coverage-html coverage/php --coverage-clover coverage/php/coverage.xml",
"minus-x": "minus-x check ."
},
"config": {
"allow-plugins": {
"dealerdirect/phpcodesniffer-composer-installer": true,
"composer/installers": true
}
}
Expand Down
12 changes: 12 additions & 0 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<phpunit colors="true">
<testsuites>
<testsuite name="Unit">
<directory>tests/phpunit/Unit</directory>
</testsuite>
</testsuites>
<filter>
<whitelist addUncoveredFilesFromWhitelist="true">
<directory>src</directory>
</whitelist>
</filter>
</phpunit>
Empty file added tests/phpunit/Unit/.gitkeep
Empty file.
44 changes: 44 additions & 0 deletions tests/phpunit/Unit/QRLiteFunctionsTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
<?php

namespace MediaWiki\Extension\QRLite\Tests\Unit;

use MediaWiki\Extension\QRLite\QRLiteFunctions;
use MediaWikiIntegrationTestCase;

class QRLiteFunctionsTest extends MediaWikiIntegrationTestCase {

/**
* Test the generateQRCode function with SVG format.
* @covers \MediaWiki\Extension\QRLite\QRLiteFunctions::generateQRCode
* @return string HTML for display of the QR code.
*/
public function testGenerateSvgQRCode() {
$params = [
'prefix' => 'TestSVG',
'format' => 'svg',
];

$html = QRLiteFunctions::generateQRCode( $params );

$this->assertStringContainsString( '<span class="svg-container"', $html );
$this->assertStringContainsString( '<svg', $html );
}

/**
* Test the generateQRCode function with PNG format (default).
* @covers \MediaWiki\Extension\QRLite\QRLiteFunctions::generateQRCode
*/
public function testGeneratePngQRCode() {
$params = [
'prefix' => 'TestPNG',
'format' => 'png',
];

$html = QRLiteFunctions::generateQRCode( $params );

// Ovde očekujemo <img> tag, ne <svg>
$this->assertStringContainsString( '<img', $html );
$this->assertStringContainsString( 'src="data:image/png;base64', $html );
$this->assertStringContainsString( 'title="TestPNG"', $html );
}
}
Loading