Skip to content

Commit

Permalink
build: Update tests workflow
Browse files Browse the repository at this point in the history
  • Loading branch information
DevDavido committed Dec 20, 2023
1 parent dd45590 commit b1a3ac2
Show file tree
Hide file tree
Showing 11 changed files with 93 additions and 71 deletions.
76 changes: 23 additions & 53 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,67 +5,37 @@ on:
paths-ignore:
- '*.md'

env:
PLUGIN_NAME: PerformanceAudit
TEST_SUITE: PluginTests
MYSQL_ADAPTER: PDO_MYSQL

jobs:
phpunit:
tests:
strategy:
fail-fast: false
matrix:
php-versions: ['7.1']
#php-versions: ['7.1', '7.2', '7.3', '7.4', '8.0']
matomo-versions: ['3.12.0', '3.14.0']
node-version: [12.x]
#node-version: [10.x, 12.x]
php: ['7.2', '7.4', '8.0', '8.3']
matomo-target: ['minimum_required_matomo', 'maximum_supported_matomo']
node: ['12.x', '20.x']

runs-on: ubuntu-latest

name: PHPUnit with PHP ${{ matrix.php-versions }}, Node.js ${{ matrix.node-version }} and Matomo ${{ matrix.matomo-versions }}
permissions:
checks: write
pull-requests: write
contents: read

steps:
- uses: actions/checkout@v2
name: Tests w/ PHP ${{ matrix.php }}, Node.js ${{ matrix.node }}, Target Matomo '${{ matrix.matomo-target }}'

- name: Setup PHP
uses: shivammathur/setup-php@v2
steps:
- name: Checkout repository
uses: actions/checkout@v4
with:
php-version: ${{ matrix.php-versions }}
extensions: dom, curl, libxml, mbstring, zip, pcntl, pdo, sqlite, pdo_sqlite, bcmath, intl, gd, iconv
coverage: none
tools: composer, phpunit:7.5.20
lfs: true
persist-credentials: false

- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v1
- name: Run plugin tests
uses: matomo-org/github-action-tests@main
with:
node-version: ${{ matrix.node-version }}

- name: Create database
run: |
sudo /etc/init.d/mysql start
mysql -u root -proot -e 'CREATE DATABASE IF NOT EXISTS matomo_tests;'
- name: Clone Matomo and run plugin Tests
# TODO
run: |
shopt -s extglob
mkdir ${{ env.PLUGIN_NAME }}
cp -R !(${{ env.PLUGIN_NAME }}) ${{ env.PLUGIN_NAME }}
cp -R .git/ ${{ env.PLUGIN_NAME }}/
git clone --config filter.lfs.smudge=true -q https://github.com/matomo-org/matomo.git matomo
cd matomo
git fetch --all
git submodule update
git checkout -f -q tags/${{ matrix.matomo-versions }}
[ -d ./tests/travis/.git ] || sh -c "rm -rf ./tests/travis && git clone https://github.com/matomo-org/travis-scripts.git ./tests/travis"
cd ./tests/travis
git checkout master
cd ../..
[ ! -f ./tests/travis/check_plugin_compatible_with_piwik.php ] || php ./tests/travis/check_plugin_compatible_with_piwik.php "${{ env.PLUGIN_NAME }}"
composer install --no-dev --no-progress
rm -rf plugins/${{ env.PLUGIN_NAME }}
mv ../${{ env.PLUGIN_NAME }} plugins
echo './console tests:run PerformanceAudit'
env:
DB_PASSWORD: root
plugin-name: 'PerformanceAudit'
test-type: 'PluginTests'
php-version: ${{ matrix.php }}
matomo-test-branch: ${{ matrix.matomo-target }}
node-version: ${{ matrix.node }}
mysql-service: true
6 changes: 6 additions & 0 deletions Columns/Metrics/MaxPercent.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

use Piwik\Metrics\Formatter;
use Piwik\Piwik;
use TypeError;

class MaxPercent extends Max
{
Expand Down Expand Up @@ -35,9 +36,14 @@ public function getDocumentation()
* @param mixed $value
* @param Formatter $formatter
* @return mixed $value
* @throws TypeError
*/
public function format($value, Formatter $formatter)
{
if (!is_numeric($value)) {
throw new TypeError("A non-numeric value encountered");
}

return mb_substr($formatter->getPrettyPercentFromQuotient($value / 100), 0, -1);
}
}
6 changes: 6 additions & 0 deletions Columns/Metrics/MaxSeconds.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

use Piwik\Metrics\Formatter;
use Piwik\Piwik;
use TypeError;

class MaxSeconds extends Max
{
Expand Down Expand Up @@ -35,9 +36,14 @@ public function getDocumentation()
* @param mixed $value
* @param Formatter $formatter
* @return mixed $value
* @throws TypeError
*/
public function format($value, Formatter $formatter)
{
if (!is_numeric($value)) {
throw new TypeError("A non-numeric value encountered");
}

if ($value == 0) {
return '0.000';
}
Expand Down
6 changes: 6 additions & 0 deletions Columns/Metrics/MedianPercent.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

use Piwik\Metrics\Formatter;
use Piwik\Piwik;
use TypeError;

class MedianPercent extends Median
{
Expand Down Expand Up @@ -35,9 +36,14 @@ public function getDocumentation()
* @param mixed $value
* @param Formatter $formatter
* @return mixed $value
* @throws TypeError
*/
public function format($value, Formatter $formatter)
{
if (!is_numeric($value)) {
throw new TypeError("A non-numeric value encountered");
}

return mb_substr($formatter->getPrettyPercentFromQuotient($value / 100), 0, -1);
}
}
6 changes: 6 additions & 0 deletions Columns/Metrics/MedianSeconds.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

use Piwik\Metrics\Formatter;
use Piwik\Piwik;
use TypeError;

class MedianSeconds extends Median
{
Expand Down Expand Up @@ -35,9 +36,14 @@ public function getDocumentation()
* @param mixed $value
* @param Formatter $formatter
* @return mixed $value
* @throws TypeError
*/
public function format($value, Formatter $formatter)
{
if (!is_numeric($value)) {
throw new TypeError("A non-numeric value encountered");
}

if ($value == 0) {
return '0.000';
}
Expand Down
6 changes: 6 additions & 0 deletions Columns/Metrics/MinPercent.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

use Piwik\Metrics\Formatter;
use Piwik\Piwik;
use TypeError;

class MinPercent extends Min
{
Expand Down Expand Up @@ -35,9 +36,14 @@ public function getDocumentation()
* @param mixed $value
* @param Formatter $formatter
* @return mixed $value
* @throws TypeError
*/
public function format($value, Formatter $formatter)
{
if (!is_numeric($value)) {
throw new TypeError("A non-numeric value encountered");
}

return mb_substr($formatter->getPrettyPercentFromQuotient($value / 100), 0, -1);
}
}
6 changes: 6 additions & 0 deletions Columns/Metrics/MinSeconds.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

use Piwik\Metrics\Formatter;
use Piwik\Piwik;
use TypeError;

class MinSeconds extends Min
{
Expand Down Expand Up @@ -35,9 +36,14 @@ public function getDocumentation()
* @param mixed $value
* @param Formatter $formatter
* @return mixed $value
* @throws TypeError
*/
public function format($value, Formatter $formatter)
{
if (!is_numeric($value)) {
throw new TypeError("A non-numeric value encountered");
}

if ($value == 0) {
return '0.000';
}
Expand Down
13 changes: 7 additions & 6 deletions tests/Integration/ApiTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,14 @@
use Piwik\ArchiveProcessor\Rules;
use Piwik\DataTable;
use Piwik\Date;
use Piwik\Translate;
use Piwik\Tests\Framework\Fixture;

/**
* @group ApiTest
* @group PerformanceAudit
* @group Plugins
*/
class ApiTest extends PerformanceAuditIntegrationTest
class ApiTest extends PerformanceAuditIntegrationPreparation
{
/**
* @var Date
Expand All @@ -29,15 +29,16 @@ public function setUp(): void

$this->date = Date::factory('2020-06-15');

Translate::loadAllTranslations();
Fixture::loadAllTranslations();
Rules::setBrowserTriggerArchiving(true);

$this->markTestSkipped('Plugin API integration test contains SQL error and must be revisited: https://github.com/DevDavido/performance-audit-plugin/issues/47');
}

public function tearDown()
public function tearDown(): void
{
Fixture::resetTranslations();
parent::tearDown();

//Translate::reset();
}

// Site 1
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
use Piwik\Tests\Framework\Fixture;
use Piwik\Tests\Framework\TestCase\IntegrationTestCase;

abstract class PerformanceAuditIntegrationTest extends IntegrationTestCase
abstract class PerformanceAuditIntegrationPreparation extends IntegrationTestCase
{
const SERVER_HOST_NAME = 'localhost';
const SERVER_PORT = 80;
Expand All @@ -43,9 +43,10 @@ public function setUp(): void

// Create user
$this->addPreexistingSuperUser();
$this->superUserTokenAuth = UsersManagerAPI::getInstance()->getTokenAuth(
$this->superUserTokenAuth = UsersManagerAPI::getInstance()->createAppSpecificTokenAuth(
self::TEST_SUPERUSER_LOGIN,
md5(self::TEST_SUPERUSER_PASS)
self::TEST_SUPERUSER_PASS,
"app-specific-pwd-description"
);

// Create sites
Expand Down
13 changes: 6 additions & 7 deletions tests/Unit/Metric/PercentTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@
require PIWIK_INCLUDE_PATH . '/plugins/PerformanceAudit/vendor/autoload.php';

use PHPUnit\Framework\TestCase;
use PHPUnit_Framework_Error_Warning;
use Piwik\Metrics\Formatter;
use Piwik\Plugins\PerformanceAudit\Columns\Metrics\MaxPercent;
use Piwik\Plugins\PerformanceAudit\Columns\Metrics\MedianPercent;
use Piwik\Plugins\PerformanceAudit\Columns\Metrics\MinPercent;
use TypeError;

/**
* @group Metric
Expand All @@ -22,7 +22,7 @@ class PercentTest extends TestCase
/** @var Formatter */
private $formatter;

public function setUp()
public function setUp(): void
{
parent::setUp();

Expand All @@ -45,19 +45,18 @@ public function test_max_median_min_percent_format_as_expected()
}
}

/**
* @expectedException PHPUnit_Framework_Error_Warning
*/
public function test_max_median_min_percent_format_with_warning()
public function test_max_median_min_percent_format_with_exception()
{
$this->expectException(TypeError::class);

$objs = [
new MaxPercent(),
new MedianPercent(),
new MinPercent()
];

foreach ($objs as $obj) {
$this->assertSame('', $obj->format('test', $this->formatter));
$obj->format('test', $this->formatter);
}
}
}
19 changes: 17 additions & 2 deletions tests/Unit/Metric/SecondsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
use Piwik\Plugins\PerformanceAudit\Columns\Metrics\MaxSeconds;
use Piwik\Plugins\PerformanceAudit\Columns\Metrics\MedianSeconds;
use Piwik\Plugins\PerformanceAudit\Columns\Metrics\MinSeconds;
use TypeError;

/**
* @group Metric
Expand All @@ -21,7 +22,7 @@ class SecondsTest extends TestCase
/** @var Formatter */
private $formatter;

public function setUp()
public function setUp(): void
{
parent::setUp();

Expand All @@ -42,7 +43,21 @@ public function test_max_median_min_seconds_format_as_expected()
$this->assertSame('50.125', $obj->format(50125, $this->formatter));
$this->assertSame('100', $obj->format(100000, $this->formatter));
$this->assertSame('-100.55', $obj->format(-100550, $this->formatter));
$this->assertSame('0.000', $obj->format('test', $this->formatter));
}
}

public function test_max_median_min_seconds_format_with_exception()
{
$this->expectException(TypeError::class);

$objs = [
new MaxSeconds(),
new MedianSeconds(),
new MinSeconds()
];

foreach ($objs as $obj) {
$obj->format('test', $this->formatter);
}
}
}

0 comments on commit b1a3ac2

Please sign in to comment.