Skip to content

Commit

Permalink
Fixed tests (#171)
Browse files Browse the repository at this point in the history
  • Loading branch information
s1lver authored Jul 22, 2023
1 parent 206c3a0 commit 953bee1
Show file tree
Hide file tree
Showing 11 changed files with 62 additions and 59 deletions.
1 change: 1 addition & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ on:
- 'psalm.xml'

push:
branches: [ 'master' ]
paths-ignore:
- 'docs/**'
- 'README.md'
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/composer-require-checker.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ on:
- 'psalm.xml'

push:
branches: [ 'master' ]
paths-ignore:
- 'docs/**'
- 'README.md'
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/mutation.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ on:
- 'psalm.xml'

push:
branches: [ 'master' ]
paths-ignore:
- 'docs/**'
- 'README.md'
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/static.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ on:
- 'phpunit.xml.dist'

push:
branches: [ 'master' ]
paths-ignore:
- 'docs/**'
- 'README.md'
Expand Down
41 changes: 20 additions & 21 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,32 +1,31 @@
export COMPOSE_PROJECT_NAME=yii-queue

build:
docker-compose -f tests/docker-compose.yml up -d --build
help: ## Display help information
@fgrep -h "##" $(MAKEFILE_LIST) | fgrep -v fgrep | sed -e 's/\\$$//' | sed -e 's/##//'

down:
docker-compose -f tests/docker-compose.yml 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

test:
docker-compose -f tests/docker-compose.yml build --pull php$(v)
docker-compose -f tests/docker-compose.yml run php$(v) vendor/bin/phpunit --colors=always -v --debug
make down
down: ## Stop and remove containers, networks
docker-compose -f tests/docker/docker-compose.yml down

sh: ## Enter the container with the application
docker exec -it yii-queue-php sh

mutation-test:
docker-compose -f tests/docker-compose.yml build --pull php$(v)
docker-compose -f tests/docker-compose.yml run php$(v) php -dpcov.enabled=1 -dpcov.directory=. vendor/bin/roave-infection-static-analysis-plugin -j2 --ignore-msi-with-no-mutations --only-covered
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 yii-queue-php
PHP_VERSION=$(filter-out $@,$(v)) docker-compose -f tests/docker/docker-compose.yml run yii-queue-php vendor/bin/phpunit --debug
make down

coverage:
docker-compose -f tests/docker-compose.yml run php$(v) vendor/bin/phpunit --coverage-clover coverage.xml
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 yii-queue-php
PHP_VERSION=$(filter-out $@,$(v)) docker-compose -f tests/docker/docker-compose.yml run yii-queue-php php -dpcov.enabled=1 -dpcov.directory=. vendor/bin/roave-infection-static-analysis-plugin -j2 --ignore-msi-with-no-mutations --only-covered
make down

static-analyze:
docker-compose -f tests/docker-compose.yml run php$(v) vendor/bin/psalm --config=psalm.xml --shepherd --stats --php-version=$(v)
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 yii-queue-php vendor/bin/phpunit --coverage-clover coverage.xml
make down

clean:
docker-compose down
sudo rm -rf tests/runtime/*
sudo rm -rf composer.lock
sudo rm -rf vendor/
sudo rm -rf tests/runtime/.composer*
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 yii-queue-php vendor/bin/psalm --config=psalm.xml --shepherd --stats --php-version=$(v)
make down
3 changes: 2 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,8 @@
"sort-packages": true,
"allow-plugins": {
"infection/extension-installer": true,
"composer/package-versions-deprecated": true
"composer/package-versions-deprecated": true,
"yiisoft/config": true
}
},
"scripts": {
Expand Down
2 changes: 2 additions & 0 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
convertWarningsToExceptions="true"
stopOnFailure="false"
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.3/phpunit.xsd"
executionOrder="random"
verbose="true"
>
<coverage>
<include>
Expand Down
20 changes: 18 additions & 2 deletions tests/Unit/Debug/QueueCollectorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
namespace Yiisoft\Yii\Queue\Tests\Unit\Debug;

use Yiisoft\Yii\Debug\Collector\CollectorInterface;
use Yiisoft\Yii\Debug\Collector\SummaryCollectorInterface;
use Yiisoft\Yii\Debug\Tests\Shared\AbstractCollectorTestCase;
use Yiisoft\Yii\Queue\Debug\QueueCollector;
use Yiisoft\Yii\Queue\Enum\JobStatus;
Expand Down Expand Up @@ -91,9 +92,9 @@ protected function checkCollectedData(array $data): void
);
}

protected function checkIndexData(array $data): void
protected function checkSummaryData(array $data): void
{
parent::checkIndexData($data);
parent::checkSummaryData($data);
[
'countPushes' => $countPushes,
'countStatuses' => $countStatuses,
Expand All @@ -104,4 +105,19 @@ protected function checkIndexData(array $data): void
$this->assertEquals(1, $countStatuses);
$this->assertEquals(3, $countProcessingMessages);
}

public function testEmptyCollector(): void
{
$collector = $this->getCollector();

foreach ($collector->getCollected() as $collected) {
$this->assertEquals([], $collected);
}

if ($collector instanceof SummaryCollectorInterface) {
foreach ($collector->getSummary()['queue'] as $count) {
$this->assertEquals(0, $count);
}
}
}
}
34 changes: 0 additions & 34 deletions tests/docker-compose.yml

This file was deleted.

13 changes: 13 additions & 0 deletions tests/docker/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
version: '3.8'

services:
yii-queue-php:
container_name: yii-queue-php
build:
context: ../..
dockerfile: tests/docker/php/Dockerfile
args:
PHP_VERSION: ${PHP_VERSION:-8.1}
volumes:
- ../runtime:/app/tests/runtime
- ../..:/app
4 changes: 3 additions & 1 deletion tests/docker/php/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# Important! Do not use this image in production!

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

RUN apk add git autoconf g++ make linux-headers

Expand Down

0 comments on commit 953bee1

Please sign in to comment.