Skip to content

Commit 2133525

Browse files
author
John Kelly
committed
Add tests
Update to PSR-2 standard Add maintainer tools (scrutinizer, styleci, etc)
1 parent de026fa commit 2133525

37 files changed

+751
-205
lines changed

.editorconfig

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
; This file is for unifying the coding style for different editors and IDEs.
2+
; More information at http://editorconfig.org
3+
4+
root = true
5+
6+
[*]
7+
charset = utf-8
8+
end_of_line = lf
9+
indent_size = 4
10+
indent_style = space
11+
insert_final_newline = true
12+
trim_trailing_whitespace = true
13+
14+
; Works with some editors only
15+
quote_type = single
16+
max_line_length = 120
17+
spaces_around_brackets = true
18+
spaces_around_operators = true

.gitattributes

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
# Path-based git attributes
2+
# https://www.kernel.org/pub/software/scm/git/docs/gitattributes.html
3+
4+
# Ignore all test and documentation with "export-ignore".
5+
/.editorconfig export-ignore
6+
/.gitattributes export-ignore
7+
/.gitignore export-ignore
8+
/.travis.yml export-ignore
9+
/.scrutinizer.yml export-ignore
10+
/.styleci.yml export-ignore
11+
/examples export-ignore
12+
/tests export-ignore

.gitignore

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,4 @@
11
composer.lock
2-
vendor/*
2+
vendor/
3+
phpunit.xml
4+
build/

.scrutinizer.yml

+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
filter:
2+
paths: [lib/*]
3+
excluded_paths: [config/*, examples/*, vendor/*]
4+
5+
checks:
6+
php:
7+
remove_extra_empty_lines: true
8+
remove_php_closing_tag: true
9+
remove_trailing_whitespace: true
10+
fix_use_statements:
11+
remove_unused: true
12+
preserve_multiple: false
13+
preserve_blanklines: true
14+
order_alphabetically: true
15+
fix_php_opening_tag: true
16+
fix_linefeed: true
17+
fix_line_ending: true
18+
fix_identation_4spaces: true
19+
fix_doc_comments: true
20+
21+
tools:
22+
external_code_coverage:
23+
timeout: 1020
24+
runs: 6

.styleci.yml

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
preset: psr2

.travis.yml

+32
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
language: php
2+
3+
php:
4+
- 5.3
5+
- 5.4
6+
- 5.5
7+
- 5.6
8+
- 7.0
9+
- hhvm
10+
11+
# This triggers builds to run on the new TravisCI infrastructure.
12+
# See: http://docs.travis-ci.com/user/workers/container-based-infrastructure/
13+
sudo: false
14+
15+
matrix:
16+
fast_finish: true
17+
include:
18+
- php: 5.3
19+
env: 'COMPOSER_FLAGS="--prefer-stable --prefer-lowest"'
20+
21+
before_script:
22+
- travis_retry composer self-update
23+
- travis_retry composer update ${COMPOSER_FLAGS} --no-interaction --prefer-source
24+
25+
script:
26+
- vendor/bin/phpunit -d zend.enable_gc=0 --coverage-text --coverage-clover=coverage.clover
27+
28+
after_script:
29+
- if [[ $TRAVIS_PHP_VERSION != 'hhvm' ]]; then php vendor/bin/ocular code-coverage:upload --format=php-clover coverage.clover; fi
30+
31+
services:
32+
rabbitmq

CHANGELOG.md

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
# Changelog
2+
3+
All Notable changes to `php-amqplib/thumper` will be documented in this file.
4+
5+
Updates should follow the [Keep a CHANGELOG](http://keepachangelog.com/) principles.
6+
7+
## 0.4.1 - Added Package Maintenance Files
8+
9+
### Added
10+
- Added many package maintenance files

CONDUCT.md

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
# Contributor Code of Conduct
2+
3+
As contributors and maintainers of this project, and in the interest of fostering an open and welcoming community, we pledge to respect all people who contribute through reporting issues, posting feature requests, updating documentation, submitting pull requests or patches, and other activities.
4+
5+
We are committed to making participation in this project a harassment-free experience for everyone, regardless of level of experience, gender, gender identity and expression, sexual orientation, disability, personal appearance, body size, race, ethnicity, age, religion, or nationality.
6+
7+
Examples of unacceptable behavior by participants include:
8+
9+
* The use of sexualized language or imagery
10+
* Personal attacks
11+
* Trolling or insulting/derogatory comments
12+
* Public or private harassment
13+
* Publishing other's private information, such as physical or electronic addresses, without explicit permission
14+
* Other unethical or unprofessional conduct.
15+
16+
Project maintainers have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct. By adopting this Code of Conduct, project maintainers commit themselves to fairly and consistently applying these principles to every aspect of managing this project. Project maintainers who do not follow or enforce the Code of Conduct may be permanently removed from the project team.
17+
18+
This code of conduct applies both within project spaces and in public spaces when an individual is representing the project or its community in a direct capacity. Personal views, beliefs and values of individuals do not necessarily reflect those of the organisation or affiliated individuals and organisations.
19+
20+
Instances of abusive, harassing, or otherwise unacceptable behavior may be reported by opening an issue or contacting one or more of the project maintainers.
21+
22+
This Code of Conduct is adapted from the [Contributor Covenant](http://contributor-covenant.org), version 1.2.0, available at [http://contributor-covenant.org/version/1/2/0/](http://contributor-covenant.org/version/1/2/0/)

CONTRIBUTING.md

+32
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
# Contributing
2+
3+
Contributions are **welcome** and will be fully **credited**.
4+
5+
We accept contributions via Pull Requests on [Github](https://github.com/php-amqplib/thumper).
6+
7+
8+
## Pull Requests
9+
10+
- **[PSR-2 Coding Standard](https://github.com/php-fig/fig-standards/blob/master/accepted/PSR-2-coding-style-guide.md)** - The easiest way to apply the conventions is to install [PHP Code Sniffer](http://pear.php.net/package/PHP_CodeSniffer).
11+
12+
- **Add tests!** - Your patch won't be accepted if it doesn't have tests.
13+
14+
- **Document any change in behaviour** - Make sure the `README.md` and any other relevant documentation are kept up-to-date.
15+
16+
- **Consider our release cycle** - We try to follow [SemVer v2.0.0](http://semver.org/). Randomly breaking public APIs is not an option.
17+
18+
- **Create feature branches** - Don't ask us to pull from your master branch.
19+
20+
- **One pull request per feature** - If you want to do more than one thing, send multiple pull requests.
21+
22+
- **Send coherent history** - Make sure each individual commit in your pull request is meaningful. If you had to make multiple intermediate commits while developing, please [squash them](http://www.git-scm.com/book/en/v2/Git-Tools-Rewriting-History#Changing-Multiple-Commit-Messages) before submitting.
23+
24+
25+
## Running Tests
26+
27+
``` bash
28+
$ composer test
29+
```
30+
31+
32+
**Happy coding**!

README.md

+55-18
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,25 @@
1-
# Looking for New Maintainer #
1+
# Thumper
22

3-
See issue: https://github.com/php-amqplib/Thumper/issues/28
4-
5-
# Thumper #
3+
[![Latest Version on Packagist][ico-version]][link-packagist]
4+
[![Software License][ico-license]](LICENSE.md)
5+
[![Build Status][ico-travis]][link-travis]
6+
[![Coverage Status][ico-scrutinizer]][link-scrutinizer]
7+
[![Quality Score][ico-code-quality]][link-code-quality]
8+
[![Total Downloads][ico-downloads]][link-downloads]
69

710
Thumper is a PHP library that aims to abstract several messaging patterns that can be implemented over RabbitMQ.
811

912
Inside the _examples_ folder you can see how to implement RPC, parallel processing, simple queue servers and pub/sub.
1013

11-
INSTALLATION
12-
13-
@see http://getcomposer.org for composer details.
14+
## Install
1415

15-
Clone this project and then just run `composer update` to fetch the dependencies.
16+
Via Composer
1617

17-
This project requires the php-amqplib library.
18+
``` bash
19+
$ composer require php-amqplib/thumper
20+
```
1821

19-
# About the Examples #
22+
## About the Examples
2023

2124
Each example has a README.md file that shows how to execute it. All the examples expect that RabbitMQ is running. They have been tested using RabbitMQ 2.1.1
2225

@@ -39,30 +42,64 @@ And then to consume them on the other side of the wire:
3942
$consumer->setCallback($myConsumer); //myConsumer could be any valid PHP callback
4043
$consumer->consume(5); //5 is the number of messages to consume.
4144

42-
## Queue Server ##
45+
### Queue Server
4346

4447
This example illustrates how to create a producer that will publish jobs into a queue. Those jobs will be processed later by a consumer –or several of them–.
4548

46-
## RPC ##
49+
### RPC
4750

4851
This example illustrates how to do RPC over RabbitMQ. We have a RPC Client that will send request to a server that returns the number of characters in the provided strings. The server code is inside the _parallel\_processing_ folder.
4952

50-
## Parallel Processing ##
53+
### Parallel Processing
5154

5255
This example is based on the RPC one. In this case it shows how to achieve parallel execution with PHP. Let's say that you have to execute two expensive tasks. One takes 5 seconds and the other 10. Instead of waiting 15 seconds, we can send the requests in parallel and then wait for the replies which should take 10 seconds now –the time of the slowest task–.
5356

54-
## Topic ##
57+
### Topic
5558

5659
In this case we can see how to achieve publish/subscribe with RabbitMQ. The example is about logging. We can log with several levels and subjects and then have consumers that listen to different log levels act accordingly.
5760

58-
## Anonymous Consumers ##
61+
### Anonymous Consumers
5962

6063
Also inside the _topic_ folder there's an anonymous consumer example. The idea here is for those situations when you need to hook up a queue to some exchange to "spy" what's going on, but when you quit your program you want that the queue is automatically deleted. We can achieve this using an unnamed queue.
6164

62-
# Disclaimer #
65+
## Change log
66+
67+
Please see [CHANGELOG](CHANGELOG.md) for more information what has changed recently.
68+
69+
## Testing
70+
71+
``` bash
72+
$ composer test
73+
```
74+
75+
## Contributing
76+
77+
Please see [CONTRIBUTING](CONTRIBUTING.md) and [CONDUCT](CONDUCT.md) for details.
78+
79+
## Disclaimer
6380

6481
This code is experimental. The idea is to show how easy is to implement such patterns with RabbitMQ and AMQP.
6582

66-
# License #
83+
## Credits
84+
85+
- [:author_name][link-author]
86+
- [All Contributors][link-contributors]
87+
88+
## License
89+
90+
The MIT License (MIT). Please see [License File](LICENSE.md) for more information.
91+
92+
[ico-version]: https://img.shields.io/packagist/v/php-amqplib/thumper.svg?style=flat-square
93+
[ico-license]: https://img.shields.io/badge/license-MIT-brightgreen.svg?style=flat-square
94+
[ico-travis]: https://img.shields.io/travis/php-amqplib/thumper/master.svg?style=flat-square
95+
[ico-scrutinizer]: https://img.shields.io/scrutinizer/coverage/g/php-amqplib/thumper.svg?style=flat-square
96+
[ico-code-quality]: https://img.shields.io/scrutinizer/g/php-amqplib/thumper.svg?style=flat-square
97+
[ico-downloads]: https://img.shields.io/packagist/dt/php-amqplib/thumper.svg?style=flat-square
6798

68-
See LICENSE.md
99+
[link-packagist]: https://packagist.org/packages/php-amqplib/thumper
100+
[link-travis]: https://travis-ci.org/php-amqplib/thumper
101+
[link-scrutinizer]: https://scrutinizer-ci.com/g/php-amqplib/thumper/code-structure
102+
[link-code-quality]: https://scrutinizer-ci.com/g/php-amqplib/thumper
103+
[link-downloads]: https://packagist.org/packages/php-amqplib/thumper
104+
[link-author]: https://github.com/:author_username
105+
[link-contributors]: ../../contributors

composer.json

+31-4
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,42 @@
33
"replace": {
44
"videlalvaro/thumper": "self.version"
55
},
6+
"license": "MIT",
67
"type": "library",
78
"description": "AMQP Tools",
8-
"keywords": ["library", "AMQP", "RabbitMQ", "PHPAMQPLib", "Thumper"],
9+
"keywords": [
10+
"library",
11+
"AMQP",
12+
"RabbitMQ",
13+
"PHPAMQPLib",
14+
"Thumper"
15+
],
916
"homepage": "https://github.com/php-amqplib/Thumper",
1017
"autoload": {
11-
"psr-0": {"Thumper": "lib"}
18+
"psr-0": {
19+
"Thumper": "lib"
20+
}
21+
},
22+
"autoload-dev": {
23+
"psr-4": {
24+
"Thumper\\Test\\": "tests"
25+
}
1226
},
1327
"require": {
14-
"php": ">=5.3.3",
15-
"php-amqplib/php-amqplib" : "~2.6.0"
28+
"php": "^5.3.3|^7.0",
29+
"php-amqplib/php-amqplib": "^2.6"
30+
},
31+
"require-dev": {
32+
"phpunit/phpunit": "^5.3",
33+
"scrutinizer/ocular": "^1.3",
34+
"squizlabs/php_codesniffer": "^2.6"
35+
},
36+
"scripts": {
37+
"test": "phpunit"
38+
},
39+
"extra": {
40+
"branch-alias": {
41+
"dev-master": "0.5.0-dev"
42+
}
1643
}
1744
}

config/config.php

+7-3
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,12 @@
11
<?php
2-
require_once dirname(__DIR__) . '/vendor/autoload.php';
2+
3+
require __DIR__ . '/../vendor/autoload.php';
4+
5+
use PhpAmqpLib\Connection\AMQPLazyConnection;
6+
use Thumper\ConnectionRegistry;
37

48
$connections = array(
5-
'default' => new \PhpAmqpLib\Connection\AMQPLazyConnection('localhost', 5672, 'guest', 'guest', '/')
9+
'default' => new AMQPLazyConnection('localhost', 5672, 'guest', 'guest', '/')
610
);
711

8-
$registry = new \Thumper\ConnectionRegistry($connections, 'default');
12+
$registry = new ConnectionRegistry($connections, 'default');

examples/parallel_processing/char_count_server.php

+4-6
Original file line numberDiff line numberDiff line change
@@ -27,16 +27,14 @@
2727
* @package Thumper
2828
*/
2929

30-
require_once(dirname(dirname(__DIR__)) . '/config/config.php');
30+
require __DIR__ . '/../../config/config.php';
3131

32-
$charCount = function($word)
33-
{
34-
sleep(2);
35-
return strlen($word);
32+
$charCount = function ($word) {
33+
sleep(2);
34+
return strlen($word);
3635
};
3736

3837
$server = new Thumper\RpcServer($registry->getConnection());
3938
$server->initServer('charcount');
4039
$server->setCallback($charCount);
4140
$server->start();
42-

examples/parallel_processing/parallel_rpc.php

+1-2
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
* @category Thumper
2727
* @package Thumper
2828
*/
29-
require_once(dirname(dirname(__DIR__)) . '/config/config.php');
29+
require __DIR__ . '/../../config/config.php';
3030

3131
$start = time();
3232

@@ -40,4 +40,3 @@
4040
var_dump($replies);
4141

4242
echo "Total time: ", time() - $start, "\n";
43-

examples/parallel_processing/random_int_server.php

+6-7
Original file line numberDiff line numberDiff line change
@@ -26,17 +26,16 @@
2626
* @category Thumper
2727
* @package Thumper
2828
*/
29-
require_once(dirname(dirname(__DIR__)) . '/config/config.php');
29+
require __DIR__ . '/../../config/config.php';
3030

31-
$randomInt = function($data)
32-
{
33-
sleep(5);
34-
$data = unserialize($data);
35-
return rand($data['min'], $data['max']);
31+
$randomInt = function ($data) {
32+
33+
sleep(5);
34+
$data = unserialize($data);
35+
return rand($data['min'], $data['max']);
3636
};
3737

3838
$server = new Thumper\RpcServer($registry->getConnection());
3939
$server->initServer('random-int');
4040
$server->setCallback($randomInt);
4141
$server->start();
42-

0 commit comments

Comments
 (0)