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
2 changes: 2 additions & 0 deletions .github/workflows/composer-require-checker.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,3 +33,5 @@ jobs:
['ubuntu-latest']
php: >-
['8.1', '8.2', '8.3', '8.4']
required-packages: >-
['data']
6 changes: 6 additions & 0 deletions .github/workflows/mssql.yml
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,12 @@ jobs:
- name: Install dependencies with composer
run: composer update --prefer-dist --no-interaction --no-progress --optimize-autoloader --ansi

- name: Install Yii Data
uses: yiisoft/actions/install-packages@master
with:
packages: >-
['data']

- name: Run tests with phpunit
run: vendor/bin/phpunit --testsuite=Mssql --coverage-clover=coverage.xml --colors=always
env:
Expand Down
2 changes: 2 additions & 0 deletions .github/workflows/mutation.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,5 +29,7 @@ jobs:
['ubuntu-latest']
php: >-
['8.3']
required-packages: >-
['data']
secrets:
STRYKER_DASHBOARD_API_KEY: ${{ secrets.STRYKER_DASHBOARD_API_KEY }}
6 changes: 6 additions & 0 deletions .github/workflows/mysql.yml
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,12 @@ jobs:
- name: Install dependencies with composer
run: composer update --prefer-dist --no-interaction --no-progress --optimize-autoloader --ansi

- name: Install Yii Data
uses: yiisoft/actions/install-packages@master
with:
packages: >-
['data']

- name: Run tests with phpunit
run: vendor/bin/phpunit --testsuite Mysql --coverage-clover=coverage.xml --colors=always
env:
Expand Down
6 changes: 6 additions & 0 deletions .github/workflows/oracle.yml
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,12 @@ jobs:
- name: Install dependencies with composer
run: composer update --prefer-dist --no-interaction --no-progress --optimize-autoloader --ansi

- name: Install Yii Data
uses: yiisoft/actions/install-packages@master
with:
packages: >-
['data']

- name: Run tests with phpunit
run: vendor/bin/phpunit --testsuite Oracle --coverage-clover=coverage.xml --colors=always
env:
Expand Down
6 changes: 6 additions & 0 deletions .github/workflows/pgsql.yml
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,12 @@ jobs:
- name: Install dependencies with composer
run: composer update --prefer-dist --no-interaction --no-progress --optimize-autoloader --ansi

- name: Install Yii Data
uses: yiisoft/actions/install-packages@master
with:
packages: >-
['data']

- name: Run tests with phpunit
run: vendor/bin/phpunit --testsuite Pgsql --coverage-clover=coverage.xml --colors=always
env:
Expand Down
2 changes: 2 additions & 0 deletions .github/workflows/rector.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,5 @@ jobs:
['ubuntu-latest']
php: >-
['8.4']
required-packages: >-
['data']
6 changes: 6 additions & 0 deletions .github/workflows/sqlite.yml
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,12 @@ jobs:
- name: Install dependencies with composer.
run: composer update --prefer-dist --no-interaction --no-progress --optimize-autoloader --ansi

- name: Install Yii Data
uses: yiisoft/actions/install-packages@master
with:
packages: >-
['data']

- name: Run tests with phpunit with code coverage.
run: vendor/bin/phpunit --coverage-clover=coverage.xml --colors=always --configuration phpunit.xml.dist

Expand Down
2 changes: 2 additions & 0 deletions .github/workflows/static.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,3 +31,5 @@ jobs:
['ubuntu-latest']
php: >-
['8.1', '8.2', '8.3', '8.4']
required-packages: >-
['data']
49 changes: 38 additions & 11 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,5 +1,29 @@
run:
docker compose run --rm --entrypoint $(CMD) php
.PHONY: help
help: ## Show the list of available commands with description.
@awk 'BEGIN {FS = ":.*?## "} /^[a-zA-Z_-]+:.*?## / {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}' $(MAKEFILE_LIST)
.DEFAULT_GOAL := help

build: ## Build services
docker compose -f docker/docker-compose.yml -f docker/docker-compose.override.yml build
up: ## Start services
docker compose -f docker/docker-compose.yml -f docker/docker-compose.override.yml up -d --remove-orphans
build-up: # Build and start services
docker compose -f docker/docker-compose.yml -f docker/docker-compose.override.yml up -d --remove-orphans --build
ps: ## List running services
docker compose -f docker/docker-compose.yml -f docker/docker-compose.override.yml ps
stop: ## Stop running services
docker compose -f docker/docker-compose.yml -f docker/docker-compose.override.yml stop
down: ## Stop running services and remove all services (not defined services, containers, networks, volumes, images)
docker compose -f docker/docker-compose.yml -f docker/docker-compose.override.yml down \
--remove-orphans \
--volumes \
--rmi all

run: ## Run arbitrary command
docker compose -f docker/docker-compose.yml -f docker/docker-compose.override.yml run \
--rm \
--entrypoint $(CMD) \
php

test-all: test-sqlite \
test-mysql \
Expand All @@ -11,31 +35,34 @@ test-mysql: testsuite-Mysql
test-pgsql: testsuite-Pgsql
test-mssql: testsuite-Mssql
test-oracle:
docker compose run \
docker compose -f docker/docker-compose.yml -f docker/docker-compose.override.yml run \
--rm \
--entrypoint 'bash -c -l "vendor/bin/phpunit --testsuite Oracle"' \
--entrypoint "bash -c -l 'vendor/bin/phpunit --testsuite Oracle $(RUN_ARGS)'" \
php

testsuite-%:
docker compose run \
docker compose -f docker/docker-compose.yml -f docker/docker-compose.override.yml run \
--rm \
--entrypoint "vendor/bin/phpunit --testsuite $(subst testsuite-,,$@)" \
--entrypoint "vendor/bin/phpunit --testsuite $(subst testsuite-,,$@) $(RUN_ARGS)" \
php

static-analysis: CMD="vendor/bin/psalm --no-cache"
static-analysis: run
psalm: CMD="vendor/bin/psalm --no-cache" ## Run static analysis using Psalm
psalm: run

mutation: CMD="\
vendor/bin/roave-infection-static-analysis-plugin \
--threads=2 \
--min-msi=0 \
--min-covered-msi=100 \
--ignore-msi-with-no-mutations \
--only-covered"
--only-covered" ## Run mutation tests using Infection
mutation: run

composer-require-checker: CMD="vendor/bin/composer-require-checker"
composer-require-checker: CMD="vendor/bin/composer-require-checker" ## Check dependencies using Composer Require Checker
composer-require-checker: run

shell: CMD="bash"
rector: CMD="vendor/bin/rector" ## Check code style using Rector
rector: run

shell: CMD="bash" ## Open interactive shell
shell: run
1 change: 1 addition & 0 deletions docker/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/docker-compose.override.yml
44 changes: 26 additions & 18 deletions Dockerfile → docker/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
FROM composer/composer:latest-bin AS composer

FROM php:8.3-cli

# System packages
Expand Down Expand Up @@ -34,17 +35,24 @@ RUN curl https://packages.microsoft.com/keys/microsoft.asc | apt-key add - \
&& rm -rf /var/lib/apt/lists/*

# Oracle dependencies

RUN cd /tmp && curl -L https://download.oracle.com/otn_software/linux/instantclient/2350000/instantclient-basic-linux.x64-23.5.0.24.07.zip -O
RUN cd /tmp && curl -L https://download.oracle.com/otn_software/linux/instantclient/2350000/instantclient-sdk-linux.x64-23.5.0.24.07.zip -O
RUN cd /tmp && curl -L https://download.oracle.com/otn_software/linux/instantclient/2350000/instantclient-sqlplus-linux.x64-23.5.0.24.07.zip -O

RUN unzip /tmp/instantclient-basic-linux.x64-23.5.0.24.07.zip -d /usr/local/
RUN unzip -o /tmp/instantclient-sdk-linux.x64-23.5.0.24.07.zip -d /usr/local/
RUN unzip -o /tmp/instantclient-sqlplus-linux.x64-23.5.0.24.07.zip -d /usr/local/

RUN ln -s /usr/local/instantclient_23_5 /usr/local/instantclient
# Fixes error "libnnz19.so: cannot open shared object file: No such file or directory"
ARG TARGETARCH
RUN if [ "$TARGETARCH" = "arm64" ] ; then \
cd /tmp && curl -L https://download.oracle.com/otn_software/linux/instantclient/2370000/instantclient-basic-linux.arm64-23.7.0.25.01.zip -O \
&& curl -L https://download.oracle.com/otn_software/linux/instantclient/2370000/instantclient-sdk-linux.arm64-23.7.0.25.01.zip -O \
&& curl -L https://download.oracle.com/otn_software/linux/instantclient/2370000/instantclient-sqlplus-linux.arm64-23.7.0.25.01.zip -O \
&& unzip -o /tmp/instantclient-basic-linux.arm64-23.7.0.25.01.zip -d /usr/local/ \
&& unzip -o /tmp/instantclient-sdk-linux.arm64-23.7.0.25.01.zip -d /usr/local/ \
&& unzip -o /tmp/instantclient-sqlplus-linux.arm64-23.7.0.25.01.zip -d /usr/local/ \
&& ln -s /usr/local/instantclient_23_7 /usr/local/instantclient; \
elif [ "$TARGETARCH" = "amd64" ]; then \
cd /tmp && curl -L https://download.oracle.com/otn_software/linux/instantclient/2350000/instantclient-basic-linux.x64-23.5.0.24.07.zip -O \
&& curl -L https://download.oracle.com/otn_software/linux/instantclient/2350000/instantclient-sdk-linux.x64-23.5.0.24.07.zip -O \
&& curl -L https://download.oracle.com/otn_software/linux/instantclient/2350000/instantclient-sqlplus-linux.x64-23.5.0.24.07.zip -O \
&& unzip /tmp/instantclient-basic-linux.x64-23.5.0.24.07.zip -d /usr/local/ \
&& unzip -o /tmp/instantclient-sdk-linux.x64-23.5.0.24.07.zip -d /usr/local/ \
&& unzip -o /tmp/instantclient-sqlplus-linux.x64-23.5.0.24.07.zip -d /usr/local/ \
&& ln -s /usr/local/instantclient_23_5 /usr/local/instantclient; \
fi
RUN ln -s /usr/local/instantclient/lib* /usr/lib
RUN ln -s /usr/local/instantclient/sqlplus /usr/bin/sqlplus

Expand All @@ -59,18 +67,18 @@ RUN docker-php-ext-install \
# For Psalm, to make use of JIT for a 20%+ performance boost.
opcache

RUN echo 'instantclient,/usr/local/instantclient' | pecl install oci8
RUN echo "extension=oci8.so" > /usr/local/etc/php/conf.d/php-oci8.ini

RUN echo 'instantclient,/usr/local/instantclient' | pecl install pdo_oci
RUN echo "extension=pdo_oci.so" > /usr/local/etc/php/conf.d/php-pdo-oci.ini

RUN pecl install sqlsrv
RUN printf "; priority=20\nextension=sqlsrv.so\n" > /usr/local/etc/php/conf.d/php-sqlsrv.ini

RUN pecl install pdo_sqlsrv
RUN printf "; priority=30\nextension=pdo_sqlsrv.so\n" > /usr/local/etc/php/conf.d/php-pdo-sqlsrv.ini

RUN echo 'instantclient,/usr/local/instantclient' | pecl install oci8
RUN echo "extension=oci8.so" > /usr/local/etc/php/conf.d/php-oci8.ini

RUN echo 'instantclient,/usr/local/instantclient' | pecl install pdo_oci
RUN echo "extension=pdo_oci.so" > /usr/local/etc/php/conf.d/php-pdo-oci.ini

# For code coverage (mutation testing)
RUN pecl install pcov && docker-php-ext-enable pcov

Expand All @@ -85,4 +93,4 @@ WORKDIR /code

# PHP packages

RUN composer install
RUN COMPOSER_ALLOW_SUPERUSER=1 composer install
13 changes: 8 additions & 5 deletions docker-compose.yml → docker/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
services:
php:
build: .
build:
context: ./..
dockerfile: ./docker/Dockerfile
volumes:
- ./src:/code/src
- ./tests:/code/tests
- ./phpunit.xml.dist:/code/phpunit.xml.dist
- ./../src:/code/src
- ./../tests:/code/tests
- ./../phpunit.xml.dist:/code/phpunit.xml.dist
command: tail -F anything
depends_on:
mysql:
Expand Down Expand Up @@ -67,10 +69,11 @@ services:
start_period: 10s
oracle:
build:
context: docker/oracle
context: oracle
ports:
- "1521:1521"
volumes:
- ./oracle/init.sql:/docker-entrypoint-initdb.d/init.sql
- oracle-data:/opt/oracle/oradata
environment:
ORACLE_PASSWORD: sys_user_password
Expand Down
1 change: 1 addition & 0 deletions docker/oracle/init.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
ALTER USER system DEFAULT TABLESPACE USERS;
8 changes: 4 additions & 4 deletions src/FilterHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
namespace Yiisoft\Data\Db;

use LogicException;
use Yiisoft\Data\Db\FilterHandler\AllFilterHandler;
use Yiisoft\Data\Db\FilterHandler\AnyFilterHandler;
use Yiisoft\Data\Db\FilterHandler\AndXFilterHandler;
use Yiisoft\Data\Db\FilterHandler\OrXFilterHandler;
use Yiisoft\Data\Db\FilterHandler\BetweenFilterHandler;
use Yiisoft\Data\Db\FilterHandler\Criteria;
use Yiisoft\Data\Db\FilterHandler\Context;
Expand Down Expand Up @@ -48,8 +48,8 @@ public function __construct(
) {
if (empty($handlers)) {
$handlers = [
new AllFilterHandler(),
new AnyFilterHandler(),
new AndXFilterHandler(),
new OrXFilterHandler(),
new EqualsFilterHandler(),
new GreaterThanFilterHandler(),
new GreaterThanOrEqualFilterHandler(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,33 +4,32 @@

namespace Yiisoft\Data\Db\FilterHandler;

use Yiisoft\Data\Reader\Filter\All;
use Yiisoft\Data\Reader\Filter\AndX;
use Yiisoft\Data\Reader\FilterInterface;

final class AllFilterHandler implements QueryFilterHandlerInterface
final class AndXFilterHandler implements QueryFilterHandlerInterface
{
public function getFilterClass(): string
{
return All::class;
return AndX::class;
}

public function getCriteria(FilterInterface $filter, Context $context): ?Criteria
{
/** @var All $filter */
/** @var AndX $filter */

$filters = $filter->getFilters();
if (empty($filters)) {
if (empty($filter->filters)) {
return null;
}

$condition = ['AND'];
$params = [];

foreach ($filters as $subFilter) {
foreach ($filter->filters as $subFilter) {
$criteria = $context->handleFilter($subFilter);
if ($criteria !== null) {
$condition[] = $criteria->condition;
$params = array_merge($params, $criteria->params);

Check warning on line 32 in src/FilterHandler/AndXFilterHandler.php

View workflow job for this annotation

GitHub Actions / mutation / PHP 8.3-ubuntu-latest

Escaped Mutant for Mutator "UnwrapArrayMerge": @@ @@ $criteria = $context->handleFilter($subFilter); if ($criteria !== null) { $condition[] = $criteria->condition; - $params = array_merge($params, $criteria->params); + $params = $params; } } return new Criteria($condition, $params); } }

Check warning on line 32 in src/FilterHandler/AndXFilterHandler.php

View workflow job for this annotation

GitHub Actions / mutation / PHP 8.3-ubuntu-latest

Escaped Mutant for Mutator "UnwrapArrayMerge": @@ @@ $criteria = $context->handleFilter($subFilter); if ($criteria !== null) { $condition[] = $criteria->condition; - $params = array_merge($params, $criteria->params); + $params = $criteria->params; } } return new Criteria($condition, $params); } }
}
}
return new Criteria($condition, $params);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,33 +4,32 @@

namespace Yiisoft\Data\Db\FilterHandler;

use Yiisoft\Data\Reader\Filter\Any;
use Yiisoft\Data\Reader\Filter\OrX;
use Yiisoft\Data\Reader\FilterInterface;

final class AnyFilterHandler implements QueryFilterHandlerInterface
final class OrXFilterHandler implements QueryFilterHandlerInterface
{
public function getFilterClass(): string
{
return Any::class;
return OrX::class;
}

public function getCriteria(FilterInterface $filter, Context $context): ?Criteria
{
/** @var Any $filter */
/** @var OrX $filter */

$filters = $filter->getFilters();
if (empty($filters)) {
if (empty($filter->filters)) {
return null;
}

$condition = ['OR'];
$params = [];

foreach ($filters as $subFilter) {
foreach ($filter->filters as $subFilter) {
$criteria = $context->handleFilter($subFilter);
if ($criteria !== null) {
$condition[] = $criteria->condition;
$params = array_merge($params, $criteria->params);

Check warning on line 32 in src/FilterHandler/OrXFilterHandler.php

View workflow job for this annotation

GitHub Actions / mutation / PHP 8.3-ubuntu-latest

Escaped Mutant for Mutator "UnwrapArrayMerge": @@ @@ $criteria = $context->handleFilter($subFilter); if ($criteria !== null) { $condition[] = $criteria->condition; - $params = array_merge($params, $criteria->params); + $params = $criteria->params; } } return new Criteria($condition, $params); } }

Check warning on line 32 in src/FilterHandler/OrXFilterHandler.php

View workflow job for this annotation

GitHub Actions / mutation / PHP 8.3-ubuntu-latest

Escaped Mutant for Mutator "UnwrapArrayMerge": @@ @@ $criteria = $context->handleFilter($subFilter); if ($criteria !== null) { $condition[] = $criteria->condition; - $params = array_merge($params, $criteria->params); + $params = $params; } } return new Criteria($condition, $params); } }
}
}
return new Criteria($condition, $params);
Expand Down
Loading
Loading