diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index b42bae3..dc5af16 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -3,22 +3,37 @@ 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 @@ -26,5 +41,23 @@ jobs: - 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 diff --git a/README.md b/README.md index c069af1..b69b44e 100644 --- a/README.md +++ b/README.md @@ -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). diff --git a/composer.json b/composer.json index 7126ec2..0a2ceb4 100644 --- a/composer.json +++ b/composer.json @@ -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" diff --git a/src/QueryBuilder/TaxQueryBuilder.php b/src/QueryBuilder/TaxQueryBuilder.php index 46eb362..2d828df 100644 --- a/src/QueryBuilder/TaxQueryBuilder.php +++ b/src/QueryBuilder/TaxQueryBuilder.php @@ -45,15 +45,15 @@ class TaxQueryBuilder extends SubQuery private bool $includeChildren = true; /** - * @var array|null - * Variable that stores an array of terms used for searching. + * The terms the query looks for. + * + * @var array|null */ private ?array $terms = null; public function __construct( private readonly string $taxonomy - ) { - } + ) {} /** * Sets the operator to "NOT EXISTS". @@ -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. @@ -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 $terms The terms to be used in the query. + * @param array $terms The terms to be used in the query. * @return self Returns the current instance of the object. */ public function contains(array $terms): self @@ -131,7 +131,7 @@ public function containsAll(array $terms): self /** * Sets the terms to exclude from the search. * - * @param array $terms The terms to exclude. + * @param array $terms The terms to exclude. */ public function notContains(array $terms): self { diff --git a/src/QueryException.php b/src/QueryException.php index 2fc2296..b6c7bc8 100644 --- a/src/QueryException.php +++ b/src/QueryException.php @@ -6,6 +6,4 @@ use Exception; -class QueryException extends Exception -{ -} +class QueryException extends Exception {} diff --git a/tests/Feature/ValueTypeTest.php b/tests/Feature/ValueTypeTest.php index e2bf267..8962dce 100644 --- a/tests/Feature/ValueTypeTest.php +++ b/tests/Feature/ValueTypeTest.php @@ -1,20 +1,24 @@ 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) { diff --git a/tests/helpers/wp.php b/tests/helpers/wp.php index 06ec8fc..d2bed35 100644 --- a/tests/helpers/wp.php +++ b/tests/helpers/wp.php @@ -1,11 +1,12 @@