├── .gitignore ├── LICENSE ├── README.md ├── codeception.yml ├── composer.json └── src └── Codeception └── Extension ├── EmailNotifier.php └── UbuntuNotifier.php /.gitignore: -------------------------------------------------------------------------------- 1 | vendor/* 2 | composer.lock 3 | composer.phar -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2013 Codeception PHP Testing Framework 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy of 6 | this software and associated documentation files (the "Software"), to deal in 7 | the Software without restriction, including without limitation the rights to 8 | use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of 9 | the Software, and to permit persons to whom the Software is furnished to do so, 10 | subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS 17 | FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 18 | COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER 19 | IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 20 | CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 21 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | Notifier 2 | ======== 3 | 4 | This repository demonstrates the usage of Codeception Extension API. 5 | Check it's source code to write your own extensions. 6 | 7 | ## Notification Extensions for Codeception 8 | 9 | Extensions from this package that can be included in Codeception to receive notification of test results. 10 | 11 | **This notifications are limited to just a few basic examples. It is recommended to get it forked and patched for your actual needs.** 12 | 13 | Notifcation are made via [notificatior](https://github.com/namshi/notificator) library by [NAMSHI](https://github.com/namshi/). 14 | 15 | ## Installation 16 | 17 | Install this package 18 | 19 | ``` 20 | composer require codeception/notifier --dev 21 | ``` 22 | 23 | Enable extensions in `codeception.yml` configuration: 24 | 25 | Sample: 26 | 27 | ``` yaml 28 | paths: 29 | tests: tests 30 | log: tests/_log 31 | data: tests/_data 32 | helpers: tests/_helpers 33 | extensions: 34 | enabled: 35 | # enable ubuntu notifications 36 | - Codeception\Extension\UbuntuNotifier # extension class name 37 | 38 | # enable email notifications 39 | - Codeception\Extension\EmailNotifier: 40 | email: tests@company.com 41 | 42 | ``` 43 | 44 | ## Ubuntu Notifications 45 | 46 | Class: **Codeception\Extension\UbuntuNotifier**. 47 | 48 | A basic `notify-send` wrapper of Notificator can be used to send notifications in Ubuntu. 49 | Done via notificator's NotifySend handler. 50 | 51 | Can be dynamically started (without adding to config) by providing `--ext UbuntuNotifier` option: 52 | 53 | ``` 54 | ./vendor/bin/codecept run --ext UbuntuNotifier 55 | ``` 56 | 57 | ## Email Notification 58 | 59 | Class: **Codeception\Extension\EmailNotifier** 60 | 61 | Unlike Ubuntu Notification this extension also takes extra parameter from config `codeception.yml`: 62 | 63 | ``` yaml 64 | 65 | extensions: 66 | - Codeception\Extension\EmailNotifier: 67 | address: tests@company.com 68 | 69 | ``` 70 | 71 | This email will be used to send notifications. 72 | 73 | ----- 74 | -------------------------------------------------------------------------------- /codeception.yml: -------------------------------------------------------------------------------- 1 | paths: 2 | tests: tests 3 | log: tests/_log 4 | data: tests/_data 5 | helpers: tests/_helpers 6 | settings: 7 | bootstrap: _bootstrap.php 8 | suite_class: \PHPUnit_Framework_TestSuite 9 | colors: true 10 | memory_limit: 1024M 11 | log: true 12 | extensions: 13 | - Codeception\Extension\UbuntuNotifier 14 | modules: 15 | config: 16 | Db: 17 | dsn: '' 18 | user: '' 19 | password: '' 20 | dump: tests/_data/dump.sql 21 | -------------------------------------------------------------------------------- /composer.json: -------------------------------------------------------------------------------- 1 | { 2 | "name":"codeception/notifier", 3 | "description":"Notification Extension for Codeception", 4 | "keywords":["notification", "acceptance testing", "functional testing", "unit testing", "tdd"], 5 | "homepage":"http://codeception.com/", 6 | 7 | "type":"library", 8 | "license":"MIT", 9 | "authors":[ 10 | { 11 | "name":"Michael Bodnarchuk", 12 | "email":"davert.php@mailican.com", 13 | "homepage":"http://codeception.com" 14 | } 15 | ], 16 | "require": { 17 | "namshi/notificator": "1.0.*" 18 | }, 19 | "require-dev": { 20 | "codeception/codeception": "@dev" 21 | }, 22 | "autoload":{ 23 | "psr-0":{ 24 | "Codeception":"src" 25 | 26 | } 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /src/Codeception/Extension/EmailNotifier.php: -------------------------------------------------------------------------------- 1 | getRecipientAddress(), $notification->subject, $notification->body); 16 | } 17 | } 18 | 19 | class SimpleEmailNotification extends EmailNotification implements EmailNotificationInterface 20 | { 21 | public $subject; 22 | public $body; 23 | 24 | public function __construct($recipientAddress, $subject, $body, array $parameters = array()) 25 | { 26 | parent::__construct($recipientAddress, $parameters); 27 | 28 | $this->subject = $subject; 29 | $this->body = $body; 30 | } 31 | } 32 | 33 | class EmailNotifier extends \Codeception\Platform\Extension { 34 | 35 | static $events = array('result.print.after' => 'notify'); 36 | 37 | function notify($event) 38 | { 39 | $result = $event->getResult(); 40 | $failed = $result->failureCount() or $result->errorCount(); 41 | 42 | // print_r($this->config); 43 | if (!isset($this->config['email'])) 44 | throw new \Codeception\Exception\Extension(__CLASS__, 'email option is required'); 45 | $email = $this->config['email']; 46 | 47 | $status = $failed ? 'FAILED' : 'PASSED'; 48 | $print = $event->getPrinter()->printResult($result); 49 | 50 | // create the manager and assign the handler to it 51 | $manager = new Manager(); 52 | $manager->addHandler(new SimpleEmailHandler()); 53 | $notification = new SimpleEmailNotification($email, "Codeception tests $status", $print); 54 | 55 | $manager->trigger($notification); 56 | } 57 | } 58 | -------------------------------------------------------------------------------- /src/Codeception/Extension/UbuntuNotifier.php: -------------------------------------------------------------------------------- 1 | 'notify'); 12 | 13 | function notify($event) 14 | { 15 | $result = $event->getResult(); 16 | 17 | $manager = new Manager(); 18 | $manager->addHandler(new NotifySendHandler(new ExecutableFinder())); 19 | 20 | $icon = '/usr/share/icons/gnome/48x48/emotes/'; 21 | if ($result->errorCount() > 0) { 22 | $icon .= 'face-angry'; 23 | } else if ($result->failureCount() > 0 ) { 24 | $icon .= 'face-sad'; 25 | } else { 26 | $icon .= 'face-cool'; 27 | } 28 | $icon .= '.png'; 29 | 30 | $notification = new NotifySendNotification( 31 | "\"Codeception Tests results: ". 32 | $result->count(). " test where ". 33 | $result->failureCount()." failed, ". 34 | $result->errorCount()." errors, ". 35 | $result->skippedCount()." skyped, ". 36 | $result->notImplementedCount()." not implemented.\"", 37 | [ 38 | '--urgency' => 'low', 39 | '--category' => 'testing', 40 | '--icon' => $icon 41 | ] 42 | ); 43 | 44 | $manager->trigger($notification); 45 | } 46 | 47 | } 48 | --------------------------------------------------------------------------------