diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index d2c44ae..6fe0c6f 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -11,26 +11,53 @@ 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 @@ -38,3 +65,10 @@ jobs: - 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 \ No newline at end of file diff --git a/.gitmodules b/.gitmodules new file mode 100644 index 0000000..2d846d0 --- /dev/null +++ b/.gitmodules @@ -0,0 +1,3 @@ +[submodule "build"] + path = build + url = https://github.com/gesinn-it-pub/docker-compose-ci.git diff --git a/.phpcs.xml b/.phpcs.xml index ba94844..2322368 100644 --- a/.phpcs.xml +++ b/.phpcs.xml @@ -1,7 +1,9 @@ - + . - lib/ - vendor/ - + /(vendor|conf)/ + extensions/* + + + \ No newline at end of file diff --git a/Makefile b/Makefile index 98daee9..e1a4e8d 100644 --- a/Makefile +++ b/Makefile @@ -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 \ No newline at end of file diff --git a/build b/build new file mode 160000 index 0000000..3c2344c --- /dev/null +++ b/build @@ -0,0 +1 @@ +Subproject commit 3c2344c631a9023b228fd9970c8daf0583b333e1 diff --git a/composer.json b/composer.json index 2f4072d..3742fb0 100644 --- a/composer.json +++ b/composer.json @@ -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 } } diff --git a/phpunit.xml.dist b/phpunit.xml.dist new file mode 100644 index 0000000..3894fc2 --- /dev/null +++ b/phpunit.xml.dist @@ -0,0 +1,12 @@ + + + + tests/phpunit/Unit + + + + + src + + + \ No newline at end of file diff --git a/tests/phpunit/Unit/.gitkeep b/tests/phpunit/Unit/.gitkeep new file mode 100644 index 0000000..e69de29 diff --git a/tests/phpunit/Unit/QRLiteFunctionsTest.php b/tests/phpunit/Unit/QRLiteFunctionsTest.php new file mode 100644 index 0000000..dd878f3 --- /dev/null +++ b/tests/phpunit/Unit/QRLiteFunctionsTest.php @@ -0,0 +1,44 @@ + 'TestSVG', + 'format' => 'svg', + ]; + + $html = QRLiteFunctions::generateQRCode( $params ); + + $this->assertStringContainsString( 'assertStringContainsString( ' 'TestPNG', + 'format' => 'png', + ]; + + $html = QRLiteFunctions::generateQRCode( $params ); + + // Ovde očekujemo tag, ne + $this->assertStringContainsString( 'assertStringContainsString( 'src="data:image/png;base64', $html ); + $this->assertStringContainsString( 'title="TestPNG"', $html ); + } +}