Skip to content

Commit

Permalink
(yiisoft#7) Fixed psalm issues and build image
Browse files Browse the repository at this point in the history
  • Loading branch information
s1lver committed Jul 7, 2023
1 parent b839fcf commit b786aa8
Show file tree
Hide file tree
Showing 7 changed files with 48 additions and 95 deletions.
52 changes: 27 additions & 25 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,38 +1,40 @@
build:
COMPOSE_FILE=tests/docker/docker-compose.yml docker-compose up -d --build
help: ## Display help information
@fgrep -h "##" $(MAKEFILE_LIST) | fgrep -v fgrep | sed -e 's/\\$$//' | sed -e 's/##//'

down:
COMPOSE_FILE=tests/docker/docker-compose.yml docker-compose down
build: ## Build an image from a docker-compose file. Params: {{ v=8.1 }}. Default latest PHP 8.1
PHP_VERSION=$(filter-out $@,$(v)) docker-compose -f tests/docker/docker-compose.yml up -d --build

start:
COMPOSE_FILE=tests/docker/docker-compose.yml docker-compose up -d
down: ## Stop and remove containers, networks
docker-compose -f tests/docker/docker-compose.yml down

test: test80 test81
start: ## Start services
docker-compose -f tests/docker/docker-compose.yml up -d

test80:
COMPOSE_FILE=tests/docker/docker-compose.yml docker-compose build --pull php80
make create-cluster
COMPOSE_FILE=tests/docker/docker-compose.yml docker-compose run php80 vendor/bin/phpunit --colors=always
COMPOSE_FILE=tests/docker/docker-compose.yml docker-compose down
sh: ## Enter the container with the application
docker exec -it cache-redis-php sh

test81:
COMPOSE_FILE=tests/docker/docker-compose.yml docker-compose build --pull php81
test: ## Run tests. Params: {{ v=8.1 }}. Default latest PHP 8.1
PHP_VERSION=$(filter-out $@,$(v)) docker-compose -f tests/docker/docker-compose.yml build --pull cache-redis-php
make create-cluster
COMPOSE_FILE=tests/docker/docker-compose.yml docker-compose run php81 vendor/bin/phpunit --colors=always
COMPOSE_FILE=tests/docker/docker-compose.yml docker-compose down
PHP_VERSION=$(filter-out $@,$(v)) docker-compose -f tests/docker/docker-compose.yml run cache-redis-php vendor/bin/phpunit --colors=always
docker-compose -f tests/docker/docker-compose.yml down

create-cluster:
create-cluster: ## Create Redis cluster
docker exec redis1 sh -c "redis-cli -p 6381 -a Password --cluster create 172.20.128.2:6381 172.20.128.3:6382 172.20.128.4:6383 172.20.128.5:6384 172.20.128.6:6385 172.20.128.7:6386 --cluster-replicas 1 --no-auth-warning --cluster-yes"

connect-cluster:
connect-cluster: ## Connect to Redis cluster
docker exec -it redis1 sh -c "redis-cli -c -p 6381 -a Password --no-auth-warning"

mutation-test:
COMPOSE_FILE=tests/docker/docker-compose.yml docker-compose build --pull php$(v)
mutation-test: ## Run mutation tests. Params: {{ v=8.1 }}. Default latest PHP 8.1
PHP_VERSION=$(filter-out $@,$(v)) docker-compose -f tests/docker/docker-compose.yml build --pull cache-redis-php
make create-cluster
COMPOSE_FILE=tests/docker/docker-compose.yml docker-compose run php$(v) php -dpcov.enabled=1 -dpcov.directory=. vendor/bin/roave-infection-static-analysis-plugin -j2 --ignore-msi-with-no-mutations --only-covered
COMPOSE_FILE=tests/docker/docker-compose.yml docker-compose down
PHP_VERSION=$(filter-out $@,$(v)) docker-compose -f tests/docker/docker-compose.yml run cache-redis-php php -dpcov.enabled=1 -dpcov.directory=. vendor/bin/roave-infection-static-analysis-plugin -j2 --ignore-msi-with-no-mutations --only-covered
make down

coverage: ## Run code coverage. Params: {{ v=8.1 }}. Default latest PHP 8.1
PHP_VERSION=$(filter-out $@,$(v)) docker-compose -f tests/docker/docker-compose.yml run cache-redis-php vendor/bin/phpunit --coverage-clover coverage.xml
make down

coverage:
COMPOSE_FILE=tests/docker/docker-compose.yml docker-compose run php80 vendor/bin/phpunit --coverage-clover coverage.xml
COMPOSE_FILE=tests/docker/docker-compose.yml docker-compose down
static-analyze: ## Run code static analyze. Params: {{ v=8.1 }}. Default latest PHP 8.1
PHP_VERSION=$(filter-out $@,$(v)) docker-compose -f tests/docker/docker-compose.yml run cache-redis-php vendor/bin/psalm --config=psalm.xml --shepherd --stats --php-version=$(v)
make down
2 changes: 2 additions & 0 deletions psalm.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
<?xml version="1.0"?>
<psalm
errorLevel="1"
findUnusedBaselineEntry="true"
findUnusedCode="false"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="https://getpsalm.org/schema/config"
xsi:schemaLocation="https://getpsalm.org/schema/config vendor/vimeo/psalm/config.xsd"
Expand Down
4 changes: 4 additions & 0 deletions src/RedisCache.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ public function isCluster(): bool
foreach ($this->connections as $connection) {
/** @var StreamConnection $connection */
$cluster = (new Client($connection->getParameters()))->info('Cluster');
/** @psalm-suppress MixedArrayAccess */
if (isset($cluster['Cluster']['cluster_enabled']) && 1 === (int)$cluster['Cluster']['cluster_enabled']) {
return true;
}
Expand All @@ -73,6 +74,7 @@ public function isCluster(): bool
public function get(string $key, mixed $default = null): mixed
{
$this->validateKey($key);
/** @var null|string $value */
$value = $this->client->get($key);
return $value === null ? $default : unserialize($value);
}
Expand Down Expand Up @@ -201,6 +203,7 @@ public function setMultiple(iterable $values, null|int|DateInterval $ttl = null)
$this->client->expire($key, (int)$ttl);
}

/** @var null|array $results */
$results = $this->client->exec();

return !in_array(null, (array)$results, true);
Expand Down Expand Up @@ -238,6 +241,7 @@ public function deleteMultiple(iterable $keys): bool
public function has(string $key): bool
{
$this->validateKey($key);
/** @var int $ttl */
$ttl = $this->client->ttl($key);
/** "-1" - if the key exists but has no associated expire {@see https://redis.io/commands/ttl}. */
return $ttl > 0 || $ttl === -1;
Expand Down
35 changes: 2 additions & 33 deletions tests/RedisClusterCacheTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -276,39 +276,6 @@ public function testNormalizeTtl($ttl, $expectedResult): void
$this->assertSameExceptObject($expectedResult, $result);
}

/**
* @return array
*/
public function iterableProvider(): array
{
return [
'array' => [
['a' => 1, 'b' => 2,],
['a' => 1, 'b' => 2,],
],
'ArrayIterator' => [
['a' => 1, 'b' => 2,],
new ArrayIterator(['a' => 1, 'b' => 2,]),
],
'IteratorAggregate' => [
['a' => 1, 'b' => 2,],
new class () implements IteratorAggregate {
public function getIterator(): ArrayIterator
{
return new ArrayIterator(['a' => 1, 'b' => 2,]);
}
},
],
'generator' => [
['a' => 1, 'b' => 2,],
(static function () {
yield 'a' => 1;
yield 'b' => 2;
})(),
],
];
}

/**
* @return array
*/
Expand Down Expand Up @@ -447,4 +414,6 @@ private function assertSameExceptObject(mixed $expected, mixed $actual): void
}
}
}


}
27 changes: 8 additions & 19 deletions tests/docker/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,31 +1,20 @@
version: '3.8'

services:
php80:
container_name: cache-redis-php80
hostname: cache-redis-php80
build: ./php/80
cache-redis-php:
container_name: cache-redis-php
hostname: cache-redis-php
build:
context: ../..
dockerfile: tests/docker/php/Dockerfile
args:
PHP_VERSION: ${PHP_VERSION:-8.1}
volumes:
- ../runtime/.composer80:/root/.composer
- ../..:/var/www
dns:
- 8.8.8.8
- 4.4.4.4
networks: &network
- cache-redis-network

php81:
container_name: cache-redis-php81
hostname: cache-redis-php81
build: ./php/81
volumes:
- ../runtime/.composer81:/root/.composer
- ../..:/var/www
dns:
- 8.8.8.8
- 4.4.4.4
networks: *network

redis-single:
image: redis:7.0.4-alpine
container_name: redis-single
Expand Down
16 changes: 0 additions & 16 deletions tests/docker/php/81/Dockerfile

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
FROM --platform=linux/amd64 php:8.0.28-fpm-alpine
# Important! Do not use this image in production!

ARG PHP_VERSION
FROM --platform=linux/amd64 php:${PHP_VERSION}-cli-alpine

RUN apk add unzip zlib-dev libzip-dev autoconf g++ make

RUN docker-php-ext-install zip
RUN docker-php-ext-install zip opcache
RUN pecl install pcov-1.0.11
RUN docker-php-ext-enable pcov

Expand Down

0 comments on commit b786aa8

Please sign in to comment.