diff --git a/.github/codecov.yml b/.github/codecov.yml new file mode 100644 index 0000000..7a5e8d6 --- /dev/null +++ b/.github/codecov.yml @@ -0,0 +1,2 @@ +fixes: + - "/phpBB3/phpBB/ext/cube/matomoanalytics/::" diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 7b7ed3e..33bec3b 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -21,11 +21,11 @@ on: jobs: # START Basic Checks Job (EPV, code sniffer, images check, etc.) basic-checks: - runs-on: ubuntu-18.04 + runs-on: ubuntu-20.04 strategy: matrix: include: - - php: '7.1' + - php: '7.2' db: "none" NOTESTS: 1 @@ -33,14 +33,14 @@ jobs: steps: - name: Checkout phpBB - uses: actions/checkout@v2 + uses: actions/checkout@v3 with: repository: phpbb/phpbb ref: ${{ env.PHPBB_BRANCH }} path: phpBB3 - name: Checkout extension - uses: actions/checkout@v2 + uses: actions/checkout@v3 with: path: phpBB3/phpBB/ext/${{ env.EXTNAME }} @@ -89,7 +89,7 @@ jobs: # START MySQL and MariaDB Job mysql-tests: - runs-on: ubuntu-18.04 + runs-on: ubuntu-20.04 strategy: matrix: include: @@ -113,6 +113,8 @@ jobs: db: "mysql:5.7" - php: '7.2' db: "mysql:5.7" + COVERAGE: 1 + db_alias: "mysql:5.7 with Coverage" - php: '7.3' db: "mysql:5.7" - php: '7.4' @@ -123,6 +125,8 @@ jobs: db: "mysql:5.7" - php: '8.1' db: "mysql:5.7" + - php: '8.2' + db: "mysql:5.7" name: PHP ${{ matrix.php }} - ${{ matrix.db_alias != '' && matrix.db_alias || matrix.db }} @@ -152,14 +156,14 @@ jobs: steps: - name: Checkout phpBB - uses: actions/checkout@v2 + uses: actions/checkout@v3 with: repository: phpbb/phpbb ref: ${{ env.PHPBB_BRANCH }} path: phpBB3 - name: Checkout extension - uses: actions/checkout@v2 + uses: actions/checkout@v3 with: path: phpBB3/phpBB/ext/${{ env.EXTNAME }} @@ -168,15 +172,24 @@ jobs: MATRIX_DB: ${{ matrix.db }} run: | db=$(echo "${MATRIX_DB%%:*}") - echo "::set-output name=db::$db" + echo "db=$db" >> $GITHUB_OUTPUT - name: Setup PHP + if: ${{ matrix.COVERAGE != 1 }} uses: shivammathur/setup-php@v2 with: php-version: ${{ matrix.php }} extensions: dom, curl, libxml, mbstring, zip, pcntl, pdo, mysqli, sqlite, pdo_sqlite, intl, gd, exif, iconv, sqlsrv, pdo_sqlsrv, ldap coverage: none + - name: Setup PHP with Coverage + if: ${{ matrix.COVERAGE == 1 }} + uses: shivammathur/setup-php@v2 + with: + php-version: ${{ matrix.php }} + extensions: dom, curl, libxml, mbstring, zip, pcntl, pdo, mysqli, sqlite, pdo_sqlite, intl, gd, exif, iconv, sqlsrv, pdo_sqlsrv, ldap + coverage: xdebug + - name: Setup environment for phpBB env: DB: ${{steps.database-type.outputs.db}} @@ -193,19 +206,41 @@ jobs: working-directory: ./phpBB3 - name: Setup PHPUnit files - run: mkdir -p phpBB/ext/$EXTNAME/.github && cp .github/phpunit* $_ + env: + DB: ${{steps.database-type.outputs.db}} + COVERAGE: ${{ matrix.COVERAGE != 1 && '0' || '1' }} + run: | + if [ $COVERAGE == '1' ] + then + sed -n '1h;1!H;${;g;s/<\/php>/<\/php>\n\t\n\t\t\n\t\t\t..\/<\/directory>\n\t\t\t\n\t\t\t\t..\/tests\/<\/directory>\n\t\t\t\t..\/language\/<\/directory>\n\t\t\t\t..\/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 + else + mkdir -p phpBB/ext/$EXTNAME/.github && cp .github/phpunit* $_ + fi working-directory: ./phpBB3 - name: Run unit tests env: DB: ${{steps.database-type.outputs.db}} - run: phpBB/vendor/bin/phpunit --configuration phpBB/ext/$EXTNAME/.github/phpunit-$DB-github.xml --bootstrap ./tests/bootstrap.php + COVERAGE: ${{ matrix.COVERAGE != 1 && '0' || '1' }} + run: | + if [ $COVERAGE == '1' ] + then + phpBB/vendor/bin/phpunit --configuration phpBB/ext/$EXTNAME/.github/phpunit-$DB-github.xml --bootstrap ./tests/bootstrap.php --coverage-clover build/logs/clover.xml + else + phpBB/vendor/bin/phpunit --configuration phpBB/ext/$EXTNAME/.github/phpunit-$DB-github.xml --bootstrap ./tests/bootstrap.php + fi working-directory: ./phpBB3 + + - name: Send code coverage + if: ${{ matrix.COVERAGE == 1 }} + uses: codecov/codecov-action@v3 + with: + files: ./phpBB3/build/logs/clover.xml # END MySQL and MariaDB Job # START PostgreSQL Job postgres-tests: - runs-on: ubuntu-18.04 + runs-on: ubuntu-20.04 strategy: matrix: include: @@ -221,6 +256,20 @@ jobs: db: "postgres:12" - php: '7.1' db: "postgres:13" + - php: '7.2' + db: "postgres:13" + - php: '7.3' + db: "postgres:13" + - php: '7.4' + db: "postgres:13" + - php: '8.0' + db: "postgres:12" + - php: '8.0' + db: "postgres:13" + - php: '8.1' + db: "postgres:14" + - php: '8.2' + db: "postgres:14" name: PHP ${{ matrix.php }} - ${{ matrix.db }} @@ -252,14 +301,14 @@ jobs: steps: - name: Checkout phpBB - uses: actions/checkout@v2 + uses: actions/checkout@v3 with: repository: phpbb/phpbb ref: ${{ env.PHPBB_BRANCH }} path: phpBB3 - name: Checkout extension - uses: actions/checkout@v2 + uses: actions/checkout@v3 with: path: phpBB3/phpBB/ext/${{ env.EXTNAME }} @@ -268,7 +317,7 @@ jobs: MATRIX_DB: ${{ matrix.db }} run: | db=$(echo "${MATRIX_DB%%:*}") - echo "::set-output name=db::$db" + echo "db=$db" >> $GITHUB_OUTPUT - name: Setup PHP uses: shivammathur/setup-php@v2 @@ -305,7 +354,7 @@ jobs: # START Other Tests Job (SQLite 3 and mssql) other-tests: - runs-on: ubuntu-18.04 + runs-on: ubuntu-20.04 strategy: matrix: include: @@ -347,14 +396,14 @@ jobs: steps: - name: Checkout phpBB - uses: actions/checkout@v2 + uses: actions/checkout@v3 with: repository: phpbb/phpbb ref: ${{ env.PHPBB_BRANCH }} path: phpBB3 - name: Checkout extension - uses: actions/checkout@v2 + uses: actions/checkout@v3 with: path: phpBB3/phpBB/ext/${{ env.EXTNAME }} @@ -368,7 +417,7 @@ jobs: else db=$(echo "${MATRIX_DB%%:*}") fi - echo "::set-output name=db::$db" + echo "db=$db" >> $GITHUB_OUTPUT - name: Setup PHP uses: shivammathur/setup-php@v2 diff --git a/README.md b/README.md index 577b7a6..aa27cb2 100644 --- a/README.md +++ b/README.md @@ -1,9 +1,10 @@ # Matomo Analytics Extension A phpBB extension that allows administrators to easily add Matomo Analytics to their forums. This is a fork of the official phpbb-googleanalytics -extention. +extention. [![Build Status](https://github.com/Cube707/phpbb-matomoanalytics/workflows/Tests/badge.svg)](https://github.com/Cube707/phpbb-matomoanalytics/actions) +[![codecov](https://codecov.io/gh/Cube707/phpbb-matomoanalytics/branch/master/graph/badge.svg?token=1HQh953sBs)](https://codecov.io/gh/Cube707/phpbb-matomoanalytics) ## Install @@ -20,4 +21,4 @@ extention. 3. To permanently uninstall, click `Delete Data` and then delete the `/ext/cube/matomoanalytics` directory. ## License -[GNU General Public License v2](http://opensource.org/licenses/GPL-2.0) +[GNU General Public License v2](https://opensource.org/licenses/GPL-2.0) diff --git a/tests/ext_test.php b/tests/ext_test.php new file mode 100644 index 0000000..f439f1f --- /dev/null +++ b/tests/ext_test.php @@ -0,0 +1,56 @@ + + * @license GNU General Public License, version 2 (GPL-2.0) + * + */ + +namespace cube\matomoanalytics\tests\system; + +class ext_test extends \phpbb_test_case +{ + /** @var \PHPUnit\Framework\MockObject\MockObject|\Symfony\Component\DependencyInjection\ContainerInterface */ + protected $container; + + /** @var \PHPUnit\Framework\MockObject\MockObject|\phpbb\finder */ + protected $extension_finder; + + /** @var \PHPUnit\Framework\MockObject\MockObject|\phpbb\db\migrator */ + protected $migrator; + + /** + * @inheritdoc + */ + protected function setUp(): void + { + parent::setUp(); + + // Stub the container + $this->container = $this->getMockBuilder('\Symfony\Component\DependencyInjection\ContainerInterface') + ->disableOriginalConstructor() + ->getMock(); + + // Stub the ext finder and disable its constructor + $this->extension_finder = $this->getMockBuilder('\phpbb\finder') + ->disableOriginalConstructor() + ->getMock(); + + // Stub the migrator and disable its constructor + $this->migrator = $this->getMockBuilder('\phpbb\db\migrator') + ->disableOriginalConstructor() + ->getMock(); + } + + /** + * Test the extension will be enabled with a compatible version of phpBB + */ + public function test_enable() + { + $ext = new \cube\matomoanalytics\ext($this->container, $this->extension_finder, $this->migrator, 'cube/matomoanalytics', ''); + + self::assertTrue($ext->is_enableable()); + } +}