Skip to content

Commit

Permalink
Merge pull request #65 from alleyinteractive/love
Browse files Browse the repository at this point in the history
Upgrading plugin to bring inline with standards
  • Loading branch information
srtfisher authored Aug 8, 2024
2 parents b87aa0f + 3058b67 commit 17d370c
Show file tree
Hide file tree
Showing 28 changed files with 134 additions and 144 deletions.
40 changes: 40 additions & 0 deletions .github/workflows/all-pr-tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
name: "All Pull Request Tests"

on:
pull_request:
types: [opened, synchronize, reopened, ready_for_review]

jobs:
# We use a single job to ensure that all steps run in the same environment and
# reduce the number of minutes used.
pr-tests:
# Don't run on draft PRs
if: github.event.pull_request.draft == false
# Timeout after 10 minutes
timeout-minutes: 10
# Define a matrix of PHP/WordPress versions to test against
strategy:
matrix:
php: [8.1, 8.2, 8.3]
wordpress: ["latest"]
runs-on: ubuntu-latest
# Cancel any existing runs of this workflow
concurrency:
group: ${{ github.workflow }}-${{ github.event_name }}-${{ github.event.pull_request.number || github.ref }}-P${{ matrix.php }}-WP${{ matrix.wordpress }}
cancel-in-progress: true
# Name the job in the matrix
name: "PR Tests PHP ${{ matrix.php }} WordPress ${{ matrix.wordpress }}"
steps:
- uses: actions/checkout@v4

- name: Run General Tests
# See https://github.com/alleyinteractive/action-test-general for more options
uses: alleyinteractive/action-test-general@develop

- name: Run PHP Tests
# See https://github.com/alleyinteractive/action-test-php for more options
uses: alleyinteractive/action-test-php@develop
with:
php-version: '${{ matrix.php }}'
wordpress-version: '${{ matrix.wordpress }}'
skip-wordpress-install: 'true'
12 changes: 12 additions & 0 deletions .github/workflows/built-release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
name: Built Release

on:
push:
branches:
- develop
- main
- production

jobs:
built-release:
uses: alleyinteractive/.github/.github/workflows/built-release.yml@main
11 changes: 0 additions & 11 deletions .github/workflows/built-tag.yml

This file was deleted.

13 changes: 0 additions & 13 deletions .github/workflows/coding-standards.yml

This file was deleted.

13 changes: 0 additions & 13 deletions .github/workflows/unit-test.yml

This file was deleted.

20 changes: 0 additions & 20 deletions .github/workflows/upgrade-wordpress-plugin.yml

This file was deleted.

5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@

All notable changes to `Feed Consumer` will be documented in this file.

## 1.0.0 - 2024-08-05

- Stable release.
- Bumps minimum requirement to PHP 8.1.

## 0.1.2 - 2023-05-16

- Require `mantle-framework/http-client`.
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ Contributors: srtfisher

Tags: alleyinteractive, feed-consumer, wordpress-plugin

Stable tag: 0.1.0
Stable tag: 1.0.0

Requires at least: 5.9

Expand Down
19 changes: 10 additions & 9 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,15 @@
],
"homepage": "https://github.com/alleyinteractive/feed-consumer",
"require": {
"php": "^8.0",
"php": "^8.1",
"alleyinteractive/composer-wordpress-autoloader": "^1.0",
"alleyinteractive/wp-block-converter": "^1.0",
"mantle-framework/http-client": "^0.12",
"mantle-framework/support": "^0.12"
"mantle-framework/http-client": "^1.0",
"mantle-framework/support": "^1.0"
},
"require-dev": {
"alleyinteractive/alley-coding-standards": "^1.0",
"mantle-framework/testkit": "^0.12",
"nunomaduro/collision": "^5.0"
"alleyinteractive/alley-coding-standards": "^2.0",
"mantle-framework/testkit": "^1.0"
},
"suggest": {
"alleyinteractive/logger": "Allows for logging of output of feeds when processing"
Expand All @@ -43,12 +42,14 @@
"wordpress-autoloader": {
"autoload": {
"Feed_Consumer\\": "src"
},
"autoload-dev": {
"Feed_Consumer\\Tests\\": "tests"
}
}
},
"autoload-dev": {
"psr-4": {
"Feed_Consumer\\Tests\\": "tests"
}
},
"scripts": {
"phpcbf": "phpcbf .",
"phpcs": "phpcs .",
Expand Down
24 changes: 12 additions & 12 deletions phpunit.xml
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
<?xml version="1.0"?>
<phpunit
bootstrap="tests/bootstrap.php"
backupGlobals="false"
colors="true"
convertErrorsToExceptions="true"
convertNoticesToExceptions="true"
convertWarningsToExceptions="true"
printerClass="NunoMaduro\Collision\Adapters\Phpunit\Printer"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
bootstrap="tests/bootstrap.php"
backupGlobals="false"
colors="true"
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/11.3/phpunit.xsd"
cacheDirectory=".phpunit.result.cache"
>
<testsuites>
<testsuite name="general">
<directory prefix="test-" suffix=".php">tests</directory>
</testsuite>
</testsuites>
<testsuites>
<testsuite name="general">
<directory suffix="Test.php">tests</directory>
</testsuite>
</testsuites>
</phpunit>
4 changes: 2 additions & 2 deletions plugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* Plugin Name: Feed Consumer
* Plugin URI: https://github.com/alleyinteractive/feed-consumer
* Description: Ingest external feeds and other data sources into WordPress
* Version: 0.1.0
* Version: 1.0.0
* Author: Sean Fisher
* Author URI: https://github.com/alleyinteractive/feed-consumer
* Requires at least: 5.9
Expand All @@ -30,7 +30,7 @@
} elseif ( ! class_exists( \Composer\InstalledVersions::class ) ) {
\add_action(
'admin_notices',
function() {
function () {
?>
<div class="notice notice-error">
<p><?php esc_html_e( 'Composer is not installed and feed-consumer cannot load. Try using a `*-built` branch if the plugin is being loaded as a submodule.', 'plugin_domain' ); ?></p>
Expand Down
3 changes: 1 addition & 2 deletions src/class-cli.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,8 @@ class CLI {
* : Feed ID to run.
*
* @param array $args Positional arguments.
* @param array $assoc_args Associative arguments.
*/
public function run( array $args, array $assoc_args ) {
public function run( array $args ) {
[ $feed_id ] = $args;

$feed = get_post( $feed_id );
Expand Down
4 changes: 2 additions & 2 deletions src/class-runner.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,11 +63,11 @@ public static function processor( int $feed_id ): Contracts\Processor {
$processors = Processors::instance()->processors();

if ( empty( $processors[ $settings['processor'] ] ) ) {
throw new RuntimeException( 'Processor not registered: ' . $settings['processor'] );
throw new RuntimeException( esc_html( 'Processor not registered: ' . $settings['processor'] ) );
}

if ( ! class_exists( $processors[ $settings['processor'] ] ) ) {
throw new RuntimeException( 'Processor class not found: ' . $processors[ $settings['processor'] ] );
throw new RuntimeException( esc_html( 'Processor class not found: ' . $processors[ $settings['processor'] ] ) );
}

$processor = new $processors[ $settings['processor'] ]();
Expand Down
5 changes: 4 additions & 1 deletion src/extractor/class-feed-extractor.php
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,10 @@ public function run(): static {
if ( ! $this->response->ok() ) {
$this->handle_error( $this->response );

throw new Extractor_Exception( 'Failed to extract feed: ' . $settings[ static::SETTING_FEED_URL ], $this->response );
throw new Extractor_Exception(
esc_html( 'Failed to extract feed: ' . $settings[ static::SETTING_FEED_URL ] ),
$this->response, // phpcs:ignore WordPress.Security.EscapeOutput.ExceptionNotEscaped
);
}

return $this;
Expand Down
2 changes: 1 addition & 1 deletion src/loader/class-post-loader.php
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ function ( array $postarr ) use ( $loader_settings ) {
}

if ( is_wp_error( $post_id ) ) {
throw new InvalidArgumentException( $post_id->get_error_message() );
throw new InvalidArgumentException( esc_html( $post_id->get_error_message() ) );
}

// Assign the post's featured image if set.
Expand Down
6 changes: 4 additions & 2 deletions src/transformer/class-json-transformer.php
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ public function data(): array {
return array_map(
fn ( array $item ) => [
Post_Loader::BYLINE => $this->extract_by_path( $item, $settings[ static::PATH_BYLINE ] ?? 'author' ),
Post_Loader::CONTENT => empty( $settings[ static::DONT_CONVERT_TO_BLOCKS] )
Post_Loader::CONTENT => empty( $settings[ static::DONT_CONVERT_TO_BLOCKS ] )
? (string) new Block_Converter( $this->extract_by_path( $item, $settings[ static::PATH_CONTENT ] ?? 'description' ) )
: $this->extract_by_path( $item, $settings[ static::PATH_CONTENT ] ?? 'description' ),
Post_Loader::GUID => $this->extract_by_path( $item, $settings[ static::PATH_GUID ] ?? 'guid' ),
Expand Down Expand Up @@ -124,6 +124,8 @@ protected function extract_by_path( array $item, string|array $path ): ?string {
return null;
}

return trim( data_get( $item, $path, null ) );
$result = data_get( $item, $path, null );

return is_null( $result ) ? null : trim( $result );
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,14 @@

use Feed_Consumer\Extractor\Extractor_Exception;
use Feed_Consumer\Extractor\Feed_Extractor;
use Feed_Consumer\Tests\Test_Case;
use Feed_Consumer\Tests\TestCase;
use Mantle\Testing\Mock_Http_Response;
use PHPUnit\Framework\Attributes\Group;

use function Mantle\Support\Helpers\tap;

/**
* @group extractor
*/
class Feed_Extractor_Test extends Test_Case {
#[Group('extractor')]
class FeedExtractorTest extends TestCase {
public function test_extract_feed() {
$this->fake_request(
'https://alley.com/feed/',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,12 @@

use Byline_Manager\Utils;
use Feed_Consumer\Integrations\Byline_Manager;
use Feed_Consumer\Tests\Test_Case;
use Feed_Consumer\Tests\TestCase;
use Mantle\Testing\Concerns\Refresh_Database;
use PHPUnit\Framework\Attributes\Group;

/**
* @group integrations
*/
class Byline_Manager_Test extends Test_Case {
#[Group('integrations')]
class BylineManagerTest extends TestCase {
use Refresh_Database;

public function setUp(): void {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,14 @@
use Feed_Consumer\Loader\Loader;
use Feed_Consumer\Loader\Option_Loader;
use Feed_Consumer\Loader\Post_Loader;
use Feed_Consumer\Tests\Test_Case;
use Feed_Consumer\Tests\TestCase;
use InvalidArgumentException;
use Mantle\Testing\Concerns\Refresh_Database;
use Mantle\Testing\Mock_Http_Response;
use PHPUnit\Framework\Attributes\Group;

/**
* @group loader
*/
class Option_Loader_Test extends Test_Case {
#[Group('loader')]
class OptionLoaderTest extends TestCase {
use Refresh_Database;

public function test_load_from_constructor() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,13 @@

use Feed_Consumer\Loader\Loader;
use Feed_Consumer\Loader\Post_Loader;
use Feed_Consumer\Tests\Test_Case;
use Feed_Consumer\Tests\TestCase;
use Mantle\Testing\Concerns\Refresh_Database;
use Mantle\Testing\Mock_Http_Response;
use PHPUnit\Framework\Attributes\Group;

/**
* @group loader
*/
class Post_Loader_Test extends Test_Case {
#[Group('loader')]
class PostLoaderTest extends TestCase {
use Refresh_Database;

public function test_load_posts_as_drafts() {
Expand Down
2 changes: 1 addition & 1 deletion tests/test-post-type.php → tests/PostTypeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

use Feed_Consumer\Settings;

class Post_Type_Test extends Test_Case {
class PostTypeTest extends TestCase {
public function test_post_type_exists() {
$this->assertTrue( post_type_exists( Settings::POST_TYPE ) );
}
Expand Down
17 changes: 5 additions & 12 deletions tests/processor/test-cursor.php → tests/Processor/CursorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,11 @@

namespace Feed_Consumer\Tests\Processor;

use Feed_Consumer\Loader\Post_Loader;
use Feed_Consumer\Processor\RSS_Processor;
use Feed_Consumer\Runner;
use Feed_Consumer\Settings;
use Feed_Consumer\Tests\Test_Case;
use Mantle\Testing\Concerns\Refresh_Database;
use Mantle\Testing\Mock_Http_Response;

/**
* @group processor
*/
class Cursor_Test extends Test_Case {
use Feed_Consumer\Tests\TestCase;
use PHPUnit\Framework\Attributes\Group;

#[Group('processor')]
class CursorTest extends TestCase {
public function get_default_cursor() {
$processor = $this->make_processor();

Expand Down
Loading

0 comments on commit 17d370c

Please sign in to comment.