Skip to content

Commit

Permalink
Merge pull request #1578 from tarlepp/chore(env)/php-update
Browse files Browse the repository at this point in the history
Chore(env) - PHP 8.1 upgrade
  • Loading branch information
tarlepp committed Dec 12, 2021
2 parents 4d20145 + 6ae14a0 commit 51d49f9
Show file tree
Hide file tree
Showing 27 changed files with 808 additions and 1,343 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/main.yml
Expand Up @@ -21,7 +21,7 @@ jobs:
strategy:
fail-fast: false
matrix:
php-versions: ['8.0']
php-versions: ['8.1']
steps:
- name: Checkout
uses: actions/checkout@v2
Expand Down Expand Up @@ -120,7 +120,7 @@ jobs:
strategy:
fail-fast: false
matrix:
php-versions: ['8.0']
php-versions: ['8.1']
steps:
- name: Checkout
uses: actions/checkout@v2
Expand Down
7 changes: 4 additions & 3 deletions .idea/php.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

20 changes: 10 additions & 10 deletions Dockerfile
@@ -1,15 +1,16 @@
FROM php:8.0.13-fpm
FROM php:8.1.0-fpm

ENV APP_ENV prod
ENV APP_DEBUG 0
ENV COMPOSER_ALLOW_SUPERUSER 1

RUN apt-get update && apt-get install -y \
zlib1g-dev libzip-dev libxml2-dev libicu-dev g++ git unzip jq wget \
RUN apt-get update \
&& apt-get install -y \
zlib1g-dev libzip-dev libxml2-dev libicu-dev g++ git unzip jq wget \
&& rm -rf /var/lib/apt/lists/*

# Copy the install-php-extensions (Easily install PHP extension in official PHP Docker containers)
COPY --from=mlocati/php-extension-installer:1.4.2 /usr/bin/install-php-extensions /usr/local/bin/
COPY --from=mlocati/php-extension-installer:1.4.6 /usr/bin/install-php-extensions /usr/local/bin/

# Install and enable all necessary PHP extensions
RUN install-php-extensions \
Expand All @@ -18,11 +19,10 @@ RUN install-php-extensions \
intl \
opcache \
pdo_mysql \
xdebug \
zip

# Copy the Composer PHAR from the Composer image into the PHP image
COPY --from=composer:2.1.12 /usr/bin/composer /usr/bin/composer
COPY --from=composer:2.1.14 /usr/bin/composer /usr/bin/composer

WORKDIR /app

Expand All @@ -34,10 +34,10 @@ RUN chmod +x /app/docker-entrypoint.sh
RUN chmod +x /usr/bin/composer

RUN curl -s https://api.github.com/repos/fabpot/local-php-security-checker/releases/latest | \
grep -E "browser_download_url(.+)linux_amd64" | \
cut -d : -f 2,3 | \
tr -d \" | \
xargs -I{} wget -O local-php-security-checker {} \
grep -E "browser_download_url(.+)linux_amd64" | \
cut -d : -f 2,3 | \
tr -d \" | \
xargs -I{} wget -O local-php-security-checker {} \
&& mv local-php-security-checker /usr/bin/local-php-security-checker \
&& chmod +x /usr/bin/local-php-security-checker

Expand Down
23 changes: 12 additions & 11 deletions Dockerfile_dev
@@ -1,4 +1,4 @@
FROM php:8.0.13-fpm
FROM php:8.1.0-fpm

# Let's use bash as a default shell with login each time
SHELL ["/bin/bash", "--login", "-c"]
Expand All @@ -10,16 +10,17 @@ ARG HOST_GID
# Declare constants
ENV PATH "$PATH:/home/dev/.composer/vendor/bin:/app/vendor/bin"
ENV NVM_VERSION v0.39.0
ENV NODE_VERSION 17.1.0
ENV NODE_VERSION 17.2.0

# Update package list and install necessary libraries
RUN apt-get update && apt-get install -y \
zlib1g-dev libzip-dev libxml2-dev libicu-dev g++ nano vim git unzip jq bash-completion iproute2 sudo wget \
python3-dev python3-pip python3-setuptools \
RUN apt-get update \
&& apt-get install -y \
zlib1g-dev libzip-dev libxml2-dev libicu-dev g++ nano vim git unzip jq bash-completion iproute2 sudo wget \
python3-dev python3-pip python3-setuptools \
&& rm -rf /var/lib/apt/lists/*

# Copy the install-php-extensions (Easily install PHP extension in official PHP Docker containers)
COPY --from=mlocati/php-extension-installer:1.4.2 /usr/bin/install-php-extensions /usr/local/bin/
COPY --from=mlocati/php-extension-installer:1.4.6 /usr/bin/install-php-extensions /usr/local/bin/

# Enable all necessary PHP packages
RUN install-php-extensions \
Expand All @@ -32,7 +33,7 @@ RUN install-php-extensions \
zip

# Copy the Composer PHAR from the Composer image into the PHP image
COPY --from=composer:2.1.12 /usr/bin/composer /usr/bin/composer
COPY --from=composer:2.1.14 /usr/bin/composer /usr/bin/composer

# Copy development `php.ini` configuration to container
COPY ./docker/php/php-dev.ini /usr/local/etc/php/php.ini
Expand All @@ -51,10 +52,10 @@ RUN chmod +x /app/bin/console \
RUN chmod -R o+s+w /usr/local/etc/php

RUN curl -s https://api.github.com/repos/fabpot/local-php-security-checker/releases/latest | \
grep -E "browser_download_url(.+)linux_amd64" | \
cut -d : -f 2,3 | \
tr -d \" | \
xargs -I{} wget -O local-php-security-checker {} \
grep -E "browser_download_url(.+)linux_amd64" | \
cut -d : -f 2,3 | \
tr -d \" | \
xargs -I{} wget -O local-php-security-checker {} \
&& mv local-php-security-checker /usr/bin/local-php-security-checker \
&& chmod +x /usr/bin/local-php-security-checker

Expand Down
4 changes: 2 additions & 2 deletions composer.json
Expand Up @@ -19,7 +19,7 @@
}
],
"require": {
"php": "^8.0.0",
"php": "^8.1.0",
"ext-iconv": "*",
"ext-json": "*",
"ext-mbstring": "*",
Expand Down Expand Up @@ -78,7 +78,7 @@
},
"config": {
"platform": {
"php": "8.0.2"
"php": "8.1.0"
},
"preferred-install": {
"*": "dist"
Expand Down
6 changes: 3 additions & 3 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 3 additions & 2 deletions ecs.php
Expand Up @@ -12,6 +12,7 @@
use PhpCsFixer\Fixer\CastNotation\CastSpacesFixer;
use PhpCsFixer\Fixer\ClassNotation\ClassAttributesSeparationFixer;
use PhpCsFixer\Fixer\ControlStructure\YodaStyleFixer;
use PhpCsFixer\Fixer\FunctionNotation\FunctionTypehintSpaceFixer;
use PhpCsFixer\Fixer\FunctionNotation\NativeFunctionInvocationFixer;
use PhpCsFixer\Fixer\FunctionNotation\SingleLineThrowFixer;
use PhpCsFixer\Fixer\Import\OrderedImportsFixer;
Expand All @@ -30,7 +31,6 @@
use PhpCsFixer\Fixer\PhpTag\BlankLineAfterOpeningTagFixer;
use PhpCsFixer\Fixer\Whitespace\BlankLineBeforeStatementFixer;
use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator;
use Symplify\CodingStandard\Fixer\Strict\BlankLineAfterStrictTypesFixer;
use Symplify\EasyCodingStandard\ValueObject\Option;

return static function (ContainerConfigurator $containerConfigurator): void {
Expand Down Expand Up @@ -168,10 +168,11 @@
NoBlankLinesBeforeNamespaceFixer::class => null,
NotOperatorWithSuccessorSpaceFixer::class => null,
SingleLineThrowFixer::class => null,
BlankLineAfterStrictTypesFixer::class => null,
PhpdocAlignFixer::class => null,
PhpdocToCommentFixer::class => null,
NativeFunctionInvocationFixer::class => null,
// https://github.com/FriendsOfPHP/PHP-CS-Fixer/issues/6164
FunctionTypehintSpaceFixer::class => null,
]
);

Expand Down
47 changes: 30 additions & 17 deletions src/Rest/SearchTerm.php
Expand Up @@ -129,24 +129,30 @@ private static function getTerm(int $mode, string $term): string
}

/**
* @param string|array<int, string>|null $column search column(s), could be a
* string or an array of strings
* @param string|array<int, string|null>|null $column search column(s), could be a string or an array of strings
*
* @return array<int, string>
*/
private static function getColumns(array | string | null $column): array
{
// Normalize column and search parameters
return array_filter(
array_map('trim', (is_array($column) ? $column : (array)(string)$column)),
static fn (string $value): bool => trim($value) !== ''
);
// Normalize columns
return $column === null
? []
: array_filter(
array_map(
'trim',
(is_array($column)
? array_filter($column, static fn (string | null $column): bool => is_string($column))
: (array)$column),
),
static fn (string $value): bool => trim($value) !== '',
);
}

/**
* Method to get search terms.
*
* @param string|array<int, string>|null $search search term(s), could be a string or an array of strings
* @param string|array<int, string|null>|null $search search term(s), could be a string or an array of strings
*
* @return array<int, string>
*/
Expand All @@ -163,14 +169,21 @@ private static function getSearchTerms(array | string | null $search): array
}
}

return array_unique(
array_filter(
array_map(
static fn (string $term): string => (string)preg_replace('#\s+#', ' ', $term),
array_map('trim', (is_array($search) ? $search : explode(' ', (string)$search))),
),
static fn (string $value): bool => trim($value) !== ''
)
);
return $search === null
? []
: array_unique(
array_filter(
array_map(
static fn (string $term): string => (string)preg_replace('#\s+#', ' ', $term),
array_map(
'trim',
(is_array($search)
? array_filter($search, static fn (string | null $term): bool => is_string($term))
: explode(' ', $search)),
),
),
static fn (string $value): bool => trim($value) !== ''
)
);
}
}
54 changes: 48 additions & 6 deletions tests/Unit/Rest/SearchTermTest.php
Expand Up @@ -39,18 +39,18 @@ public function testThatWithoutColumnOrSearchTermCriteriaIsNull(mixed $column, m
* @dataProvider dataProviderTestThatReturnedCriteriaIsExpected
*
* @phpstan-param StringableArrayObject<array> $inputArguments
* @phpstan-param StringableArrayObject<array> $expected
* @phpstan-param StringableArrayObject<array> | null $expected
* @psalm-param StringableArrayObject $inputArguments
* @psalm-param StringableArrayObject $expected
* @psalm-param StringableArrayObject | null $expected
*
* @testdox Test that `getCriteria` method returns `$expected` with given `$inputArguments` arguments
*/
public function testThatReturnedCriteriaIsExpected(
StringableArrayObject $inputArguments,
StringableArrayObject $expected
StringableArrayObject | null $expected
): void {
self::assertSame(
$expected->getArrayCopy(),
$expected?->getArrayCopy(),
call_user_func_array([SearchTerm::class, 'getCriteria'], $inputArguments->getArrayCopy())
);
}
Expand Down Expand Up @@ -94,11 +94,53 @@ public function dataProviderTestThatWithoutColumnOrSearchTermCriteriaIsNull(): G
/**
* Data provider for testThatReturnedCriteriaIsExpected
*
* @psalm-return Generator<array{0: StringableArrayObject, 1: StringableArrayObject}>
* @phpstan-return Generator<array{0: StringableArrayObject<mixed>, 1: StringableArrayObject<mixed>}>
* @psalm-return Generator<array{0: StringableArrayObject, 1: StringableArrayObject|null}>
* @phpstan-return Generator<array{0: StringableArrayObject<mixed>, 1: StringableArrayObject<mixed>|null}>
*/
public function dataProviderTestThatReturnedCriteriaIsExpected(): Generator
{
// To cover array_filter on search term
yield [
new StringableArrayObject(['c1', '0']),
new StringableArrayObject([
'and' => [
'or' => [
['entity.c1', 'like', '%0%'],
],
],
]),
];

yield [
new StringableArrayObject([null, null]),
null,
];

yield [
new StringableArrayObject(['c1', null]),
null,
];

yield [
new StringableArrayObject([null, 'word']),
null,
];

yield [
new StringableArrayObject(['', '']),
null,
];

yield [
new StringableArrayObject(['c1', '']),
null,
];

yield [
new StringableArrayObject(['', 'word']),
null,
];

yield [
new StringableArrayObject(['c1', 'word']),
new StringableArrayObject([
Expand Down
2 changes: 1 addition & 1 deletion tools/01_phpunit/composer.json
Expand Up @@ -13,7 +13,7 @@
},
"config": {
"platform": {
"php": "7.4.0"
"php": "8.1.0"
},
"preferred-install": {
"*": "dist"
Expand Down

0 comments on commit 51d49f9

Please sign in to comment.