Skip to content

Commit

Permalink
Release 2.2 (#307)
Browse files Browse the repository at this point in the history
* add PHP 8.2 to Actions

* increase ubuntu version on pipelines

* Counting Dispatched Messages (#295)

* feat(assertions): adding assertions to count messages.

* docs(changelog): breaking lines.

* docs(testing): adding new functions in testing section.

* docs(testing): fixing dispatch method.

* Laravel 10 support

---------

Co-authored-by: Tarsísio Xavier and Leonardo Lemos
  • Loading branch information
jleonardolemos authored Mar 3, 2023
1 parent cf190b6 commit aa1307e
Show file tree
Hide file tree
Showing 7 changed files with 127 additions and 9 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/continous-integration.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ jobs:
ports:
- 5672:5672

runs-on: ubuntu-18.04
runs-on: ubuntu-20.04
strategy:
matrix:
php-versions: ['7.3', '7.4', '8.0']
Expand Down Expand Up @@ -56,10 +56,10 @@ jobs:
ports:
- 5672:5672

runs-on: ubuntu-18.04
runs-on: ubuntu-20.04
strategy:
matrix:
php-versions: ['8.1']
php-versions: ['8.1', '8.2']

steps:
- uses: actions/checkout@v2
Expand Down
22 changes: 22 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,22 +5,33 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [Unreleased]
## [v2.2.0]
### Added
- Support Laravel 10.
- Support PHP 8.2.
- Function Pigeon::assertNothingDispatched().
- Function Pigeon::assertDispatchedCount(int $count).

## [v2.1.0]
### Added
- Laravel 9 support
- php 8.1 support

## [v2.0.0]
### Fixed
- Properties on publish method
- Reconnect when missed heart beat

### Added
- Laravel 8 support
- Added `Pigeon::assertNotDispatched()` method to Fake driver

### Changed
- Change `emmit` method name to `dispatch`
- Change `assertEmitted` method name to `assertDispatched`
- Property `Convenia\Pigeon\Resolver\Resolver::message` is public now
- Method `Convenia\Pigeon\Publisher\PublisherContract::publish()` now have the second param as a properties array

### Removed
- Methods `Pigeon::rpc`, `Convenia\Pigeon\Resolver::response`, `Pigeon::assertRpc`, `Pigeon::rpcPushed`, `Pigeon::assertCallbackReturn`
- Drop PHP 7.2 support
Expand All @@ -35,8 +46,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Added
- Added hability to test for timeout on consumers
- Added hability to test for comsmer multiplicit

### Changed
- Catch `Throwble` instead of `Exception` on default fallback

### Fixed
- Fixed support for Laravel 6
- Fixed facade `dispatch` signature
Expand All @@ -48,6 +61,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
## [v1.4.0]
### Added
- Added hability to send to default exchange when the exchange name is empty in `exchange()` method

### Fixed
- Fixed use of empty string on exchange to use default AMQP queue

Expand All @@ -60,6 +74,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Added `on-failure` config to ack, reject or throw exception
- Added `Pigeon::headers([])` and config `headers` key
- Added possibility to use callable on headers config

### Fixed
- Fixed failing when not set fallback and throw exception
- Fixed wrong `MessageProcessorTest` tests
Expand All @@ -68,9 +83,11 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Added
- Added bugs test suite
- Added null driver throw `Convenia\Pigeon\Exceptions\Driver\NullDriverException` exception

### Fixed
- Fix `No free channel id` message when emit large amount of events
- Fix env example

### Changed
- Change default driver to `rabbit`

Expand All @@ -82,6 +99,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Added
- Add `application_headers` to `Pigeon::dispatch` as last parameter
- Add configurable precondition catch on queue creation

### Fixed
- Auto declare exchange with `routing`
- Fix `application_headers` to `AMQPTable`
Expand All @@ -100,16 +118,20 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Added dead letter exchange to queue/exchange declare
- Added laravel auto discovery
- Added config as publishable using `pigeon.config`

### Change
- Default timeout from 5 to 0

### Fixed
- Fix acknowledge with fake

### Removed
- Remove `$properties` from `PublisherContract::publish()`, `PublisherContract::rpc()`

## [v1.0.0-alpha-1]
### Fixed
- Fixed `getDefaultDriver` return from config

### Change
- Change event listen wildcard from `*` to `#`
- Change event exchange type from `direct` to `topic`
Expand Down
8 changes: 6 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
FROM php:8.1-fpm-alpine
FROM php:8.2-fpm-alpine

COPY --from=composer:latest /usr/bin/composer /usr/bin/composer
RUN apk --no-cache --update add libmemcached-dev zlib-dev libpng-dev libjpeg-turbo-dev freetype-dev libxml2-dev

COPY --from=mlocati/php-extension-installer /usr/bin/install-php-extensions /usr/local/bin/

RUN docker-php-ext-configure gd --with-freetype --with-jpeg \
&& docker-php-ext-install -j$(nproc) gd sockets fileinfo dom xml simplexml pcntl
&& docker-php-ext-install -j$(nproc) gd fileinfo dom xml simplexml pcntl

RUN install-php-extensions sockets

RUN mv "$PHP_INI_DIR/php.ini-development" "$PHP_INI_DIR/php.ini"
6 changes: 3 additions & 3 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
{
"name": "Kauan Sousa",
"email": "[email protected]",
"role": "Maintainer"
"role": "Author"
},
{
"name": "Leonardo Lemos",
Expand All @@ -21,14 +21,14 @@
"ext-json": "*",
"ext-sockets": "*",
"php-amqplib/php-amqplib": "^3.1",
"laravel/framework": "^6.20.12|^7.30.4|>=8.22.1|>=9.2",
"laravel/framework": "^6.20.12|^7.30.4|>=8.22.1|>=9.2|^10.0",
"webpatser/laravel-uuid": "^4.0"
},
"require-dev": {
"ext-curl": "*",
"phpunit/phpunit": "^9.5",
"squizlabs/php_codesniffer": "^2.5",
"orchestra/testbench": "^4.18|^6.21",
"orchestra/testbench": "^4.18|^6.21|^8.0",
"mockery/mockery": "^1.3"
},
"autoload": {
Expand Down
38 changes: 37 additions & 1 deletion docs/TESTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -58,4 +58,40 @@ Pigeon::dispatchConsumer(
'the.queue.name',
['mocked' => 'message'] // mocked incoming message
);
```
```

There is a way to only verify the expected quatity of messages sent.

If you want to assert the exact number of messages, use `assertDispatchCount`.
```php
<?php

use Convenia\Pigeon\Facade\Pigeon;

Pigeon::fake();

Pigeon::dispatch('my-queue', [
'some-data' => 123,
]);

Pigeon::dispatch('another-great-queue', [
'some-data' => 123,
]);

Pigeon::assertDispatchCount(2); // Returns true
```

If you want to only check if nothing was sent, use `assertNothingDispatched`.
```php
<?php

use Convenia\Pigeon\Facade\Pigeon;

Pigeon::fake();

Pigeon::dispatch('my-queue', [
'some-data' => 123,
]);

Pigeon::assertNothingDispatched(); // Returns false
```
21 changes: 21 additions & 0 deletions src/Support/Testing/PigeonFake.php
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,27 @@ public function assertNotDispatched(string $category, array $data)
);
}

/**
* Checks if none message was dispatched.
*
* @return void
*/
public function assertNothingDispatched()
{
$this->assertDispatchCount(0);
}

/**
* Checks if the expected quantity of messages was dispatched.
*
* @param int $count
* @return void
*/
public function assertDispatchCount(int $count)
{
PHPUnit::assertCount($count, $this->events);
}

public function pushed(string $routing, array $message, $callback = null)
{
$callback = $callback ?: function ($publisher) use ($routing, $message) {
Expand Down
35 changes: 35 additions & 0 deletions tests/Unit/PigeonFakeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,15 @@
use Convenia\Pigeon\Publisher\Publisher;
use Convenia\Pigeon\Resolver\ResolverContract;
use Convenia\Pigeon\Tests\TestCase;
use Illuminate\Foundation\Testing\WithFaker;
use PHPUnit\Framework\Constraint\ExceptionMessage;
use PHPUnit\Framework\ExpectationFailedException;

class PigeonFakeTest extends TestCase
{
use WithFaker;

/** @var \Convenia\Pigeon\Support\Testing\PigeonFake */
protected $fake;

protected function setUp(): void
Expand Down Expand Up @@ -438,4 +442,35 @@ public function test_it_should_assert_event_not_dispatched()

$this->fake->assertNotDispatched($category, $data);
}

public function test_it_asserts_nothing_dispatched()
{
$this->fake->assertNothingDispatched();

$this->fake->dispatch('some.dummy.queue', ['dummy-field' => 123]);

$this->expectException(ExpectationFailedException::class);
$this->expectExceptionMessage('Failed asserting that actual size 1 matches expected size 0.');

$this->fake->assertNothingDispatched();
}

public function test_if_asserts_the_count_of_messages()
{
$howMany = 22;

for ($i = $howMany; $i > 0; $i--) {
$this->fake->dispatch(
implode('.', $this->faker->words()),
['some-dummy-field' => $this->faker->sentence()]
);
}

$this->fake->assertDispatchCount($howMany);

$this->expectException(ExpectationFailedException::class);
$this->expectExceptionMessage('Failed asserting that actual size 22 matches expected size 10.');

$this->fake->assertDispatchCount(10);
}
}

0 comments on commit aa1307e

Please sign in to comment.