Skip to content

Commit

Permalink
Support for Nette 2.4 (#34)
Browse files Browse the repository at this point in the history
* Repo: added editorconfig, gitattributes, update gitignore

* Composer: allow nette 2.4

* Introduce Makefile

* CI: switch to github actions

* Tests: update bootstrap, setup code coverage (coveralls)

* Tests: remove example tests

* Add support for nette 2.4
  • Loading branch information
f3l1x authored May 12, 2021
1 parent 8ad2bae commit 95c61b6
Show file tree
Hide file tree
Showing 18 changed files with 407 additions and 63 deletions.
23 changes: 14 additions & 9 deletions .docs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,11 @@ config.neon:

```neon
extensions:
# Nette 3.0+
rabbitmq: Contributte\RabbitMQ\DI\RabbitMQExtension
# Nette 2.4
rabbitmq: Contributte\RabbitMQ\DI\RabbitMQExtension24
```

### Example configuration
Expand All @@ -40,7 +44,7 @@ rabbitmq:
testQueue:
connection: default
# force queue declare on first queue operation during request
# autoCreate: true
# autoCreate: true
exchanges:
testExchange:
Expand Down Expand Up @@ -75,20 +79,20 @@ tracy:

### Declaring Queues and Exchanges

Since v3.0, all queues and exchanges are by default declared on demand using the console command:
Since v3.0, all queues and exchanges are by default declared on demand using the console command:

```bash
php index.php rabbitmq:declareQueuesAndExchanges
```

It's intended to be a part of the deploy process to make sure all the queues and exchanges are prepared for use.

If you need to override this behavior (for example only declare queues that are used during a request and nothing else),
If you need to override this behavior (for example only declare queues that are used during a request and nothing else),
just add the `autoCreate: true` parameter to queue or exchange of your choice.

You may also want to declare the queues and exchanges via rabbitmq management interface or a script but if you fail to
do so, don't run the declare console command and don't specify `autoCreate: true`, exceptions will be thrown
when accessing undeclared queues/exchanges.
You may also want to declare the queues and exchanges via rabbitmq management interface or a script but if you fail to
do so, don't run the declare console command and don't specify `autoCreate: true`, exceptions will be thrown when
accessing undeclared queues/exchanges.

### Publishing messages

Expand Down Expand Up @@ -201,7 +205,8 @@ final class LongRunningTestQueue

### Consuming messages

Your consumer callback has to return a confirmation that particular message has been acknowledges (or different states - unack, reject).
Your consumer callback has to return a confirmation that particular message has been acknowledges (or different states -
unack, reject).

TestConsumer.php

Expand Down Expand Up @@ -234,7 +239,8 @@ final class TestConsumer implements IConsumer

### Running a consumer trough CLI

There are two consumer commands prepared. `rabbitmq:consumer` wiil consume messages for specified amount of time (in seconds), to run indefinitely skip this parameter. Following command will be consuming messages for one hour:
There are two consumer commands prepared. `rabbitmq:consumer` wiil consume messages for specified amount of time (in
seconds), to run indefinitely skip this parameter. Following command will be consuming messages for one hour:

```bash
php index.php rabbitmq:consumer testConsumer 3600
Expand All @@ -246,7 +252,6 @@ Following command will be consuming messages indefinitely:
php index.php rabbitmq:consumer testConsumer
```


`rabbitmq:staticConsumer` will consume particular amount of messages. Following example will consume just 20 messages:

```bash
Expand Down
16 changes: 16 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# EditorConfig is awesome: http://EditorConfig.org

root = true

[*]
charset = utf-8
end_of_line = lf
insert_final_newline = true
trim_trailing_whitespace = true
indent_style = tab
indent_size = tab
tab_width = 4

[{*.yml,*.md}]
indent_style = space
indent_size = 2
11 changes: 11 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# Not archived
.docs export-ignore
tests export-ignore
.editorconfig export-ignore
.gitattributes export-ignore
.gitignore export-ignore
.travis.yml export-ignore
Makefile export-ignore
phpstan.neon export-ignore
README.md export-ignore
ruleset.xml export-ignore
2 changes: 2 additions & 0 deletions .github/FUNDING.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
github: [f3l1x]
custom: ["https://contributte.org/partners.html"]
100 changes: 95 additions & 5 deletions .github/workflows/main.yaml
Original file line number Diff line number Diff line change
@@ -1,11 +1,19 @@
name: "build"

on: [push, pull_request]
on:
pull_request:
paths-ignore:
- ".docs/**"
push:
branches:
- "master"
schedule:
- cron: "0 8 * * 1" # At 08:00 on Monday

env:
extensions: "json"
cache-version: "1"
composer-version: "v1"
composer-version: "v2"
composer-install: "composer update --no-interaction --no-progress --no-suggest --prefer-dist --prefer-stable"

jobs:
Expand Down Expand Up @@ -128,6 +136,15 @@ jobs:
name: "Tests"
runs-on: "${{ matrix.operating-system }}"

services:
mysql:
image: mysql:5.7
env:
MYSQL_ALLOW_EMPTY_PASSWORD: yes
MYSQL_DATABASE: tests
ports:
- 3306:3306

strategy:
matrix:
php-version: ["7.4", "8.0"]
Expand All @@ -137,9 +154,6 @@ jobs:
- php-version: "7.4"
operating-system: "ubuntu-latest"
composer-args: "--prefer-lowest"
- php-version: "8.0"
operating-system: "ubuntu-latest"
composer-args: ""
fail-fast: false

continue-on-error: "${{ matrix.php-version == '8.0' }}"
Expand Down Expand Up @@ -192,3 +206,79 @@ jobs:

- name: "Tests"
run: "make tests"

tests-code-coverage:
name: "Tests with code coverage"
runs-on: "${{ matrix.operating-system }}"

services:
mysql:
image: mysql:5.7
env:
MYSQL_ALLOW_EMPTY_PASSWORD: yes
MYSQL_DATABASE: tests
ports:
- 3306:3306

strategy:
matrix:
php-version: ["7.4"]
operating-system: ["ubuntu-latest"]
fail-fast: false

if: "github.event_name == 'push'"

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

- name: "Setup PHP cache environment"
id: "extcache"
uses: "shivammathur/cache-extensions@v1"
with:
php-version: "${{ matrix.php-version }}"
extensions: "${{ env.extensions }}"
key: "${{ env.cache-version }}"

- name: "Cache PHP extensions"
uses: "actions/cache@v2"
with:
path: "${{ steps.extcache.outputs.dir }}"
key: "${{ steps.extcache.outputs.key }}"
restore-keys: "${{ steps.extcache.outputs.key }}"

- name: "Install PHP"
uses: "shivammathur/setup-php@v2"
with:
php-version: "${{ matrix.php-version }}"
extensions: "${{ env.extensions }}"
tools: "composer:${{ env.composer-version }} "

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

- name: "Get Composer cache directory"
id: "composercache"
run: 'echo "::set-output name=dir::$(composer config cache-files-dir)"'

- name: "Cache PHP dependencies"
uses: "actions/cache@v2"
with:
path: "${{ steps.composercache.outputs.dir }}"
key: "${{ runner.os }}-composer-${{ hashFiles('**/composer.json') }}"
restore-keys: "${{ runner.os }}-composer-"

- name: "Install dependencies"
run: "${{ env.composer-install }}"

- name: "Tests"
run: "make coverage-clover"

- name: "Coveralls.io"
env:
CI_NAME: github
CI: true
COVERALLS_REPO_TOKEN: "${{ secrets.GITHUB_TOKEN }}"
run: |
wget https://github.com/php-coveralls/php-coveralls/releases/download/v2.1.0/php-coveralls.phar
php php-coveralls.phar --verbose --config tests/.coveralls.yml
11 changes: 8 additions & 3 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
.idea
composer.lock
# Editor
/.idea

# Tests
/tests/temp

# Composer
/vendor
/tests/Cases/output
/composer.lock
6 changes: 6 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,9 @@ phpstan:

tests:
vendor/bin/tester -s -p php --colors 1 -C tests/Cases

coverage-clover:
vendor/bin/tester -s -p phpdbg --colors 1 -C --coverage ./coverage.xml --coverage-src ./src ./tests/Cases

coverage-html:
vendor/bin/tester -s -p phpdbg --colors 1 -C --coverage ./coverage.html --coverage-src ./src ./tests/Cases
12 changes: 7 additions & 5 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,19 +27,21 @@
"php": ">=7.4",
"bunny/bunny": "^0.2.4 || ^0.3 || ^0.4 || ^0.5",
"symfony/console": "~3.3 || ^4.0 || ^5.0",
"nette/di": "^3.0",
"nette/utils": "^3.2"
"nette/di": "^2.4.17 || ^3.0.7",
"nette/utils": "^2.5.4 || ^3.2.0"
},
"require-dev": {
"nette/tester": "^2.3.1",
"nette/neon": "^3.0",
"mockery/mockery": "^1.4",
"ninjify/nunjuck": "^0.4",
"nette/neon": "^2.4.3 || ^3.2.1",
"mockery/mockery": "^1.3.3",
"gamee/php-code-checker-rules": "^2.0",
"tracy/tracy": "^2.5"
},
"suggest": {
"tracy/tracy": "Allows using tracy bar panel"
},
"minimum-stability": "dev",
"prefer-stable": true,
"extra": {
"branch-alias": {
"dev-master": "9.0.x-dev"
Expand Down
6 changes: 3 additions & 3 deletions src/DI/Helpers/AbstractHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

namespace Contributte\RabbitMQ\DI\Helpers;

use Contributte\RabbitMQ\DI\RabbitMQExtension;
use Nette\DI\CompilerExtension;

abstract class AbstractHelper
{
Expand All @@ -13,10 +13,10 @@ abstract class AbstractHelper
* @var array
*/
protected array $defaults = [];
protected RabbitMQExtension $extension;
protected CompilerExtension $extension;


public function __construct(RabbitMQExtension $extension)
public function __construct(CompilerExtension $extension)
{
$this->extension = $extension;
}
Expand Down
Loading

0 comments on commit 95c61b6

Please sign in to comment.