Skip to content

Commit

Permalink
chore: enable phpstan, use flarum/testing
Browse files Browse the repository at this point in the history
  • Loading branch information
imorland committed Nov 12, 2023
1 parent b04f7ca commit bfefef0
Show file tree
Hide file tree
Showing 13 changed files with 131 additions and 31 deletions.
12 changes: 12 additions & 0 deletions .github/workflows/backend.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
name: FoF Amazon Affiliation PHP

on: [workflow_dispatch, push, pull_request]

jobs:
run:
uses: flarum/framework/.github/workflows/REUSABLE_backend.yml@main
with:
enable_backend_testing: true
enable_phpstan: true

backend_directory: .
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: Javascript
name: FoF Amazon Affiliation JS

on: [workflow_dispatch, push, pull_request]

Expand All @@ -8,7 +8,7 @@ jobs:
with:
enable_bundlewatch: false
enable_prettier: true
enable_typescript: false
enable_typescript: true

frontend_directory: ./js
backend_directory: .
Expand Down
34 changes: 32 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@
"flarum/core": "^1.2.0"
},
"require-dev": {
"phpunit/phpunit": "^8.3.3"
"flarum/phpstan": "*",
"flarum/testing": "^1.0.0"
},
"replace": {
"flagrow/amazon-affiliation": "*"
Expand Down Expand Up @@ -60,11 +61,40 @@
"color": "#fff"
},
"optional-dependencies": [
"fof/formatting"
"fof/formatting"
]
},
"flagrow": {
"discuss": "https://discuss.flarum.org/d/12389"
},
"flarum-cli": {
"modules": {
"githubActions": true,
"backendTesting": true
}
}
},
"scripts": {
"analyse:phpstan": "phpstan analyse",
"clear-cache:phpstan": "phpstan clear-result-cache",
"test": [
"@test:unit",
"@test:integration"
],
"test:unit": "phpunit -c tests/phpunit.unit.xml",
"test:integration": "phpunit -c tests/phpunit.integration.xml",
"test:setup": "@php tests/integration/setup.php"
},
"scripts-descriptions": {
"analyse:phpstan": "Run static analysis",
"test": "Runs all tests.",
"test:unit": "Runs all unit tests.",
"test:integration": "Runs all integration tests.",
"test:setup": "Sets up a database for use with integration tests. Execute this only once."
},
"autoload-dev": {
"psr-4": {
"FoF\\AmazonAffiliation\\Tests\\": "tests/"
}
}
}
2 changes: 1 addition & 1 deletion extend.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,6 @@
// $params['AMAZON_ASSOCIATE_TAG_MX'] = $settings->get($prefix.'com.mx', '');
// $params['AMAZON_ASSOCIATE_TAG_AU'] = $settings->get($prefix.'com.au', '');

extract($configurator->finalize());
//extract($configurator->finalize());
}),
];
14 changes: 14 additions & 0 deletions phpstan.neon
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
includes:
- vendor/flarum/phpstan/extension.neon

parameters:
# The level will be increased in Flarum 2.0
level: 5
paths:
- extend.php
- src
excludePaths:
- *.blade.php
checkMissingIterableValueType: false
databaseMigrationsPath: ['migrations']

24 changes: 0 additions & 24 deletions phpunit.xml

This file was deleted.

2 changes: 1 addition & 1 deletion src/AmazonLinkManipulator.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public function process(UriInterface $uri)
$matches = [];

if (preg_match('~^(?:www\.)?(amazon\.((?:[a-z]{2,3}\.)?[a-z]{2,3}))$~', $uri->getHost(), $matches) !== 1) {
return;
return null;
}

$amazonDomain = $matches[1];
Expand Down
Empty file added tests/fixtures/.gitkeep
Empty file.
16 changes: 16 additions & 0 deletions tests/integration/setup.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?php

/*
* This file is part of Flarum.
*
* For detailed copyright and license information, please view the
* LICENSE file that was distributed with this source code.
*/

use Flarum\Testing\integration\Setup\SetupScript;

require __DIR__.'/../../vendor/autoload.php';

$setup = new SetupScript();

$setup->run();
25 changes: 25 additions & 0 deletions tests/phpunit.integration.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.3/phpunit.xsd"
backupGlobals="false"
backupStaticAttributes="false"
colors="true"
convertErrorsToExceptions="true"
convertNoticesToExceptions="true"
convertWarningsToExceptions="true"
processIsolation="true"
stopOnFailure="false"
>
<coverage processUncoveredFiles="true">
<include>
<directory suffix=".php">../src/</directory>
</include>
</coverage>
<testsuites>
<testsuite name="Flarum Integration Tests">
<directory suffix="Test.php">./integration</directory>
<exclude>./integration/tmp</exclude>
</testsuite>
</testsuites>
</phpunit>
27 changes: 27 additions & 0 deletions tests/phpunit.unit.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.3/phpunit.xsd"
backupGlobals="false"
backupStaticAttributes="false"
colors="true"
convertErrorsToExceptions="true"
convertNoticesToExceptions="true"
convertWarningsToExceptions="true"
processIsolation="false"
stopOnFailure="false"
>
<coverage processUncoveredFiles="true">
<include>
<directory suffix=".php">../src/</directory>
</include>
</coverage>
<testsuites>
<testsuite name="Flarum Unit Tests">
<directory suffix="Test.php">./unit</directory>
</testsuite>
</testsuites>
<listeners>
<listener class="\Mockery\Adapter\Phpunit\TestListener" />
</listeners>
</phpunit>
Empty file added tests/unit/.gitkeep
Empty file.
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@

namespace FoF\AmazonAffiliation\Tests;

use Flarum\Testing\unit\TestCase;
use FoF\AmazonAffiliation\AmazonLinkManipulator;
use Laminas\Diactoros\Uri;
use PHPUnit\Framework\TestCase;

class AmazonLinkManipulatorTest extends TestCase
{
Expand Down

0 comments on commit bfefef0

Please sign in to comment.