Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 40 additions & 7 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,28 +3,61 @@ name: Tests
on: ['push', 'pull_request']

jobs:
ci:
tests:
name: PHP ${{ matrix.php }}${{ matrix.dependencies == 'lowest' && ' (lowest dependencies)' || '' }}
runs-on: ubuntu-latest

strategy:
fail-fast: false
matrix:
php: ['8.2', '8.3', '8.4']
dependencies: ['highest']
include:
- php: '8.2'
dependencies: 'lowest'

steps:
- name: Checkout
uses: actions/checkout@v3
uses: actions/checkout@v4

- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: 8.2
php-version: ${{ matrix.php }}
tools: composer:v2
coverage: xdebug
coverage: none

- name: Install Dependencies
run: composer install --no-interaction --prefer-dist --optimize-autoloader
- name: Install dependencies
run: |
if [ "${{ matrix.dependencies }}" = "lowest" ]; then
composer update --prefer-lowest --prefer-stable --no-interaction --prefer-dist
else
composer install --no-interaction --prefer-dist --optimize-autoloader
fi

- name: Tests
run: ./vendor/bin/pest --exclude-group=docs

- name: Documentation examples
run: ./vendor/bin/pest --group=docs

style:
name: Code style
runs-on: ubuntu-latest

steps:
- name: Checkout
uses: actions/checkout@v4

- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: '8.4'
tools: composer:v2
coverage: none

- name: Install dependencies
run: composer install --no-interaction --prefer-dist --optimize-autoloader

- name: Pint
run: ./vendor/bin/pint
run: ./vendor/bin/pint --test
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -243,6 +243,8 @@ UPDATE_DOCS=1 vendor/bin/pest --group=docs # rewrite the outputs after a chang

When you add a public method, mention it in the page of its class (the test lists the ones that are missing).

The code style is checked with [Pint](https://laravel.com/docs/pint): run `vendor/bin/pint` to fix it, `vendor/bin/pint --test` to only check it (this is what CI runs). The tests run on PHP 8.2, 8.3 and 8.4, with the highest and the lowest versions of the dependencies.

## Contributing

Contributions are welcome: see the [contributing guide](https://github.com/Pollora/.github/blob/main/CONTRIBUTING.md). Report security issues privately, as described in the [security policy](https://github.com/Pollora/.github/blob/main/SECURITY.md).
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
"pollora/wordpress-args": "^1.1"
},
"require-dev": {
"laravel/pint": "^1.13",
"laravel/pint": "^1.30",
"pestphp/pest": "^2.19",
"rector/rector": "^0.18.4",
"nunomaduro/phpinsights": "^2.8"
Expand Down
14 changes: 7 additions & 7 deletions src/QueryBuilder/TaxQueryBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,15 +45,15 @@ class TaxQueryBuilder extends SubQuery
private bool $includeChildren = true;

/**
* @var array<string>|null
* Variable that stores an array of terms used for searching.
* The terms the query looks for.
*
* @var array<string|int>|null
*/
private ?array $terms = null;

public function __construct(
private readonly string $taxonomy
) {
}
) {}

/**
* Sets the operator to "NOT EXISTS".
Expand Down Expand Up @@ -82,7 +82,7 @@ public function exists(): self
/**
* Sets the field to be used in the query.
*
* @param string $field The field to be used in the query.
* @param string $field The field to be used in the query.
* @return self Returns the current instance of the object.
*
* @throws QueryException If an invalid tax field type is supplied.
Expand All @@ -104,7 +104,7 @@ public function field(string $field): self
/**
* Sets the terms to be used in the query and sets the operator to "IN".
*
* @param array<string|int> $terms The terms to be used in the query.
* @param array<string|int> $terms The terms to be used in the query.
* @return self Returns the current instance of the object.
*/
public function contains(array $terms): self
Expand All @@ -131,7 +131,7 @@ public function containsAll(array $terms): self
/**
* Sets the terms to exclude from the search.
*
* @param array<string|int> $terms The terms to exclude.
* @param array<string|int> $terms The terms to exclude.
*/
public function notContains(array $terms): self
{
Expand Down
4 changes: 1 addition & 3 deletions src/QueryException.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,4 @@

use Exception;

class QueryException extends Exception
{
}
class QueryException extends Exception {}
28 changes: 16 additions & 12 deletions tests/Feature/ValueTypeTest.php
Original file line number Diff line number Diff line change
@@ -1,20 +1,24 @@
<?php

use Pollora\Query\Utils\Types\BooleanType;
use Pollora\Query\Utils\Types\CharType;
use Pollora\Query\Utils\Types\DatetimeType;
use Pollora\Query\Utils\Types\NumberType;
use Pollora\Query\Utils\ValueTypeDetector;

$dataProvider = [
['value' => null, 'expected' => \Pollora\Query\Utils\Types\CharType::CHAR, 'message' => 'with null value'],
['value' => -5, 'expected' => \Pollora\Query\Utils\Types\NumberType::SIGNED, 'message' => 'with negative integer value'],
['value' => 5, 'expected' => \Pollora\Query\Utils\Types\NumberType::UNSIGNED, 'message' => 'with positive integer value'],
['value' => 0, 'expected' => \Pollora\Query\Utils\Types\BooleanType::BINARY, 'message' => 'with negative binary value'],
['value' => 1, 'expected' => \Pollora\Query\Utils\Types\BooleanType::BINARY, 'message' => 'with positive binary value'],
['value' => 5.5, 'expected' => \Pollora\Query\Utils\Types\NumberType::DECIMAL, 'message' => 'with float value'],
['value' => '5', 'expected' => \Pollora\Query\Utils\Types\NumberType::NUMERIC, 'message' => 'with numeric string value'],
['value' => '2021-01-01', 'expected' => \Pollora\Query\Utils\Types\DatetimeType::DATE, 'message' => 'with date value'],
['value' => '12:34:56', 'expected' => \Pollora\Query\Utils\Types\DatetimeType::TIME, 'message' => 'with time value'],
['value' => '2021-01-01 12:34:56', 'expected' => \Pollora\Query\Utils\Types\DatetimeType::DATETIME, 'message' => 'with datetime value'],
['value' => 'SomeString', 'expected' => \Pollora\Query\Utils\Types\CharType::CHAR, 'message' => 'with other string value'],
['value' => 'SomeString', 'type' => 'DATETIME', 'expected' => \Pollora\Query\Utils\Types\DatetimeType::DATETIME, 'message' => 'with forced type'],
['value' => null, 'expected' => CharType::CHAR, 'message' => 'with null value'],
['value' => -5, 'expected' => NumberType::SIGNED, 'message' => 'with negative integer value'],
['value' => 5, 'expected' => NumberType::UNSIGNED, 'message' => 'with positive integer value'],
['value' => 0, 'expected' => BooleanType::BINARY, 'message' => 'with negative binary value'],
['value' => 1, 'expected' => BooleanType::BINARY, 'message' => 'with positive binary value'],
['value' => 5.5, 'expected' => NumberType::DECIMAL, 'message' => 'with float value'],
['value' => '5', 'expected' => NumberType::NUMERIC, 'message' => 'with numeric string value'],
['value' => '2021-01-01', 'expected' => DatetimeType::DATE, 'message' => 'with date value'],
['value' => '12:34:56', 'expected' => DatetimeType::TIME, 'message' => 'with time value'],
['value' => '2021-01-01 12:34:56', 'expected' => DatetimeType::DATETIME, 'message' => 'with datetime value'],
['value' => 'SomeString', 'expected' => CharType::CHAR, 'message' => 'with other string value'],
['value' => 'SomeString', 'type' => 'DATETIME', 'expected' => DatetimeType::DATETIME, 'message' => 'with forced type'],
];

foreach ($dataProvider as $data) {
Expand Down
11 changes: 6 additions & 5 deletions tests/helpers/wp.php
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
<?php

/**
* Parses a string into variables to be stored in an array.
*
* @since 2.2.1
*
* @param string $input_string The string to be parsed.
* @param array $result Variables will be stored in this array.
* @param string $input_string The string to be parsed.
* @param array $result Variables will be stored in this array.
*/
function wp_parse_str(string $input_string, array &$result): void
{
Expand All @@ -21,9 +22,9 @@ function wp_parse_str(string $input_string, array &$result): void
* @since 2.2.0
* @since 2.3.0 `$args` can now also be an object.
*
* @param string|array|object $args Value to merge with $defaults.
* @param array $defaults Optional. Array that serves as the defaults.
* Default empty array.
* @param string|array|object $args Value to merge with $defaults.
* @param array $defaults Optional. Array that serves as the defaults.
* Default empty array.
* @return array Merged user defined values with defaults.
*/
function wp_parse_args(string|array|object $args, array $defaults = []): array
Expand Down
Loading