Skip to content

Commit ad48f17

Browse files
committed
Merge branch 'trunk' into try/adding-transform
2 parents 25f7318 + b5f2577 commit ad48f17

File tree

9 files changed

+77
-9
lines changed

9 files changed

+77
-9
lines changed

.github/workflows/phpunit.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
name: PHP Composer
1+
name: PHPUnit
22

33
on:
44
push:

composer.json

+3
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,9 @@
3434
"phpunit/phpunit": "^8.5",
3535
"yoast/phpunit-polyfills": "^2.0"
3636
},
37+
"require": {
38+
"php": ">=7.4"
39+
},
3740
"config": {
3841
"allow-plugins": {
3942
"dealerdirect/phpcodesniffer-composer-installer": true,

includes/Query_Params_Generator.php

+6-4
Original file line numberDiff line numberDiff line change
@@ -57,9 +57,9 @@ class Query_Params_Generator {
5757
* @param array $default_params Default values from the default block.
5858
* @param array $custom_params Custom values from AQL.
5959
*/
60-
public function __construct( array $default_params, array $custom_params ) {
61-
$this->default_params = $default_params;
62-
$this->custom_params = $custom_params;
60+
public function __construct( $default_params, $custom_params ) {
61+
$this->default_params = is_array( $default_params ) ? $default_params : [];
62+
$this->custom_params = is_array( $custom_params ) ? $custom_params : [];
6363
}
6464

6565
/**
@@ -76,9 +76,11 @@ public function has_custom_param( string $param_name ): bool {
7676
*
7777
* @param string $name The param to retrieve.
7878
*
79+
* @todo Return mixed type hint for 8.0
80+
*
7981
* @return mixed
8082
*/
81-
public function get_custom_param( string $name ): mixed {
83+
public function get_custom_param( string $name ) {
8284
if ( $this->has_custom_param( $name ) ) {
8385
return $this->custom_params[ $name ];
8486
}

includes/query-loop.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ function ( $pre_render, $parsed_block ) {
5858
'query_loop_block_query_vars',
5959
function ( $default_query, $block ) {
6060
// Retrieve the query from the passed block context.
61-
$block_query = $block->context['query'];
61+
$block_query = $block->context['query'] ?? [];
6262

6363
// Process all of the params
6464
$qpg = new Query_Params_Generator( $default_query, $block_query );

index.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
* Plugin Name: Advanced Query Loop
44
* Description: Query loop block variations to create custom queries.
55
* Plugin URI: https://github.com/ryanwelcher/advanced-query-loop/
6-
* Version: 3.0.0
6+
* Version: 3.0.1
77
* Requires at least: 6.2
88
* Requires PHP: 7.4
99
* Author: Ryan Welcher

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "advanced-query-loop",
3-
"version": "3.0.0",
3+
"version": "3.0.1",
44
"description": "Query loop block variations to create custom queries.",
55
"main": "index.js",
66
"scripts": {

readme.md

+2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
# Advanced Query Loop
22

3+
![Unit Tests](https://github.com/ryanwelcher/advanced-query-loop/actions/workflows/phpunit.yml/badge.svg?branch=trunk)
4+
35
## Description
46

57
This plugin introduces a Query Loop block variation that will empower users to be able to do much more complicated queries with the Query Loop block, such number of posts to display and post meta

readme.txt

+4-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ Contributors: welcher
33
Tags: Query Loop, Custom Queries
44
Requires at least: 6.2
55
Tested up to: 6.5.2
6-
Stable tag: 3.0.0
6+
Stable tag: 3.0.1
77
Requires PHP: 7.4
88
License: GPL v2 or later
99
License URI: https://www.gnu.org/licenses/gpl-2.0.html
@@ -65,6 +65,9 @@ Sort in ascending or descending order by:
6565
3. Query posts before a date, after a date or between two dates.
6666

6767
== Changelog ==
68+
= 3.0.1 =
69+
* Addresses some PHP fatal errors caused by type hinting.
70+
6871
= 3.0.0 =
6972
* Add Sorting by Included Posts IDs.
7073
* Add sorting by Comment Count.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
<?php
2+
/**
3+
* Tests for the Query_Params_Generator class functions
4+
*/
5+
6+
namespace AdvancedQueryLoop\UnitTests;
7+
8+
use AdvancedQueryLoop\Query_Params_Generator;
9+
use PHPUnit\Framework\TestCase;
10+
11+
/**
12+
* Test the generator class
13+
*/
14+
class Query_Params_Generator_Tests extends TestCase {
15+
16+
/**
17+
* Data provider for the empty array tests
18+
*
19+
* @return array
20+
*/
21+
public function data_empty_null_passed_constructor() {
22+
return array(
23+
array(
24+
null,
25+
null,
26+
),
27+
array(
28+
array(),
29+
null,
30+
),
31+
array(
32+
null,
33+
array(),
34+
),
35+
array(
36+
array(),
37+
array(),
38+
),
39+
);
40+
}
41+
42+
/**
43+
* All of these tests will return empty arrays
44+
*
45+
* @param null|array $default_data The params coming from the default block.
46+
* @param null|array $custom_data The params coming from AQL.
47+
*
48+
* @dataProvider data_empty_null_passed_constructor
49+
*/
50+
public function test_empty_null_passed_constructor( $default_data, $custom_data ) {
51+
52+
$qpg = new Query_Params_Generator( $default_data, $custom_data, );
53+
$qpg->process_all();
54+
55+
// Empty arrays return empty.
56+
$this->assertEmpty( $qpg->get_query_args() );
57+
}
58+
}

0 commit comments

Comments
 (0)