Skip to content

Commit

Permalink
Merge pull request #12 from GFG/ci-fatal-fix
Browse files Browse the repository at this point in the history
Add dev environment, CI and prevent fatal
  • Loading branch information
mleczakm authored Sep 25, 2023
2 parents 08dddfb + ef9f0d4 commit 87f9f5c
Show file tree
Hide file tree
Showing 7 changed files with 112 additions and 6 deletions.
32 changes: 32 additions & 0 deletions .docker/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
FROM php:8-cli-alpine as php-base

# Install composer
ENV COMPOSER_ALLOW_SUPERUSER 1
ENV COMPOSER_HOME /var/.composer

COPY --from=composer/composer:2.2.21-bin /composer /usr/bin/composer

RUN apk add --no-cache --virtual .build-deps $PHPIZE_DEPS && \
pecl install redis && \
docker-php-ext-enable redis && \
apk del .build-deps && \
rm -Rf /tmp/*

CMD tail -f /dev/null

WORKDIR /var/app

COPY composer.json ./

RUN composer install --no-dev --no-progress -anq --no-scripts

FROM php-base AS php-dev-base

EXPOSE 8080

RUN apk add linux-headers && \
apk add --no-cache --virtual .build-deps $PHPIZE_DEPS && \
pecl install pcov xdebug && \
docker-php-ext-enable pcov xdebug && \
apk del .build-deps && \
rm -rf /tmp/*
7 changes: 7 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
/.docker export-ignore
/.gitattributes export-ignore
/.github export-ignore
/.gitignore export-ignore
/example export-ignore
/phpunit.xml.dist export-ignore
/tests export-ignore
52 changes: 52 additions & 0 deletions .github/workflows/test.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
name: Test

on: [push, pull_request]

jobs:
test:
name: PHP ${{ matrix.php-version }} + Symfony ${{ matrix.symfony-version }}

runs-on: ubuntu-20.04

continue-on-error: ${{ matrix.experimental }}

strategy:
matrix:
include:
- php-version: '8.1'
coverage: none
- php-version: '8.2'

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

- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
coverage: ${{ matrix.coverage }}
ini-values: "memory_limit=-1"
php-version: ${{ matrix.php-version }}
tools: composer:v2

- name: Validate composer.json
run: composer validate --no-check-lock

- name: Install Composer dependencies
uses: ramsey/composer-install@v1
with:
composer-options: "--prefer-dist"

- name: Setup problem matchers for PHP
run: echo "::add-matcher::${{ runner.tool_cache }}/php.json"

- name: Setup problem matchers for PHPUnit
run: echo "::add-matcher::${{ runner.tool_cache }}/phpunit.json"

- name: Run PHPUnit
if: matrix.coverage == 'none'
run: vendor/phpunit/phpunit/phpunit

- name: Run PHPUnit with coverage
if: matrix.coverage != 'none'
run: vendor/phpunit/phpunit/phpunit --coverage-clover=coverage.clover
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
.idea
/vendor/
composer.phar
composer.lock
composer.lock
.phpunit.result.cache
13 changes: 13 additions & 0 deletions docker-compose.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
services:
php:
user: 1000:1000
build:
dockerfile: .docker/Dockerfile
target: php-dev-base
context: .
volumes:
- ./:/var/app
- ~/.composer:/var/.composer

redis:
image: redis:alpine
3 changes: 2 additions & 1 deletion src/BloomFilter/Persist/BitRedis.php
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,9 @@ public function getBulk(array $bits): array
$this->assertOffset($bit);
$pipe->getBit($this->key, $bit);
}
$return = $pipe->exec();

return $pipe->exec();
return is_array($return) ? $return : [$return];
}

/**
Expand Down
8 changes: 4 additions & 4 deletions tests/Persist/BitRedisTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ public function setBits()

$pipeMock->expects($this->once())
->method('exec')
->willReturn(1);
->willReturn(false);
/** @var \Redis $redisMock */
$persister = new BitRedis($redisMock, BitRedis::DEFAULT_KEY);
$persister->setBulk($bits);
Expand Down Expand Up @@ -150,7 +150,7 @@ public function unsetBits()

$pipeMock->expects($this->once())
->method('exec')
->willReturn(1);
->willReturn(false);
/** @var \Redis $redisMock */
$persister = new BitRedis($redisMock, BitRedis::DEFAULT_KEY);
$persister->unsetBulk($bits);
Expand Down Expand Up @@ -189,11 +189,11 @@ public function getBits()
[BitRedis::DEFAULT_KEY, $bits[1]],
[BitRedis::DEFAULT_KEY, $bits[2]]
)
->willReturn([1,1,1]);
->willReturnOnConsecutiveCalls(1,1,1);

$pipeMock->expects($this->once())
->method('exec')
->willReturn([1]);
->willReturn(false);
/** @var \Redis $redisMock */
$persister = new BitRedis($redisMock, BitRedis::DEFAULT_KEY);
$persister->getBulk($bits);
Expand Down

0 comments on commit 87f9f5c

Please sign in to comment.