Skip to content
This repository has been archived by the owner on Mar 16, 2024. It is now read-only.

Commit

Permalink
Improve logs
Browse files Browse the repository at this point in the history
  • Loading branch information
webeweb committed Aug 8, 2019
1 parent 77951bd commit aefe097
Show file tree
Hide file tree
Showing 7 changed files with 40 additions and 30 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
CHANGELOG
=========

### [1.3.0](https://github.com/webeweb/smsmode-bundle/tree/v1.3.0) (2019-08-08)

- Improve logs
- Update dependencies

### [1.3.0](https://github.com/webeweb/smsmode-bundle/tree/v1.3.0) (2019-07-31)

> IMPORTANT NOTICE: The following classes are deprecated
Expand Down
6 changes: 0 additions & 6 deletions Controller/SMSModeController.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,6 @@ public function deliveryReportCallbackAction(Request $request) {
$deliveryReportCallback = $this->newDeliveryReportCallback($request);

$event = new DeliveryReportCallbackEvent($deliveryReportCallback);

$this->getLogger()->info(sprintf("sMsmode controller dispatch an event with name \"%s\"", $event->getEventName()));

$this->dispatchEvent($event->getEventName(), $event);

return new JsonResponse(["code" => 200, "message" => "OK"]);
Expand All @@ -55,9 +52,6 @@ public function smsReplyCallbackAction(Request $request) {
$smsReplyCallback = $this->newSMSReplyCallback($request);

$event = new SMSReplyCallbackEvent($smsReplyCallback);

$this->getLogger()->info(sprintf("sMsmode controller dispatch an event with name \"%s\"", $event->getEventName()));

$this->dispatchEvent($event->getEventName(), $event);

return new JsonResponse(["code" => 200, "message" => "OK"]);
Expand Down
10 changes: 8 additions & 2 deletions EventListener/SMSModeEventListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,9 @@
namespace WBW\Bundle\SMSModeBundle\EventListener;

use InvalidArgumentException;
use Psr\Log\LoggerInterface;
use RuntimeException;
use WBW\Bundle\CoreBundle\Service\LoggerTrait;
use WBW\Bundle\SMSModeBundle\Event\AbstractEvent;
use WBW\Bundle\SMSModeBundle\Event\AccountBalanceEvent;
use WBW\Bundle\SMSModeBundle\Event\AddingContactEvent;
Expand Down Expand Up @@ -44,6 +46,8 @@
*/
class SMSModeEventListener {

use LoggerTrait;

/**
* Runtime exception message.
*
Expand All @@ -70,10 +74,12 @@ class SMSModeEventListener {

/**
* Constructor.
*
* @param LoggerInterface $logger The logger.
*/
public function __construct() {
public function __construct(LoggerInterface $logger) {
$authentication = new Authentication();
$this->setApiProvider(new APIProvider($authentication));
$this->setApiProvider(new APIProvider($authentication, $logger));
}

/**
Expand Down
1 change: 1 addition & 0 deletions Resources/config/event_listeners.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ services:
wbw.smsmode.event_listener:
class: WBW\Bundle\SMSModeBundle\EventListener\SMSModeEventListener
public: true
arguments: ["@logger"]
calls:
- ["setAccessToken", ["@?smsmode.access_token"]]
- ["setPseudo", ["@?smsmode.pseudo"]]
Expand Down
4 changes: 4 additions & 0 deletions Resources/config/services.yml
Original file line number Diff line number Diff line change
@@ -1,2 +1,6 @@
# Resources/config/services.yml
services:

logger:
alias: "monolog.logger"
public: true
40 changes: 20 additions & 20 deletions Tests/EventListener/SMSModeEventListenerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ protected function setUp() {
parent::setUp();

// Set a sMsmode event listener.
$this->smsModeEventListener = new SMSModeEventListener();
$this->smsModeEventListener = new SMSModeEventListener($this->logger);
$this->smsModeEventListener->setPseudo("pseudo");
$this->smsModeEventListener->setPass("pass");
}
Expand All @@ -98,7 +98,7 @@ public function testConstruct() {
$this->assertEquals("sMsmode configuration is missing in your app/config/config.yml.\nPlease, add smsmode.accesss_token or smsmode.pseudo and smsmode.pass", SMSModeEventListener::RUNTIME_EXCEPTION_MESSAGE);
$this->assertEquals("wbw.smsmode.event_listener", SMSModeEventListener::SERVICE_NAME);

$obj = new SMSModeEventListener();
$obj = new SMSModeEventListener($this->logger);

$this->assertNotNull($obj->getApiProvider());
}
Expand Down Expand Up @@ -134,7 +134,7 @@ public function testOnAccountBalanceWithRuntimeException() {
// Set an Account balance event mock.
$accountBalanceEvent = new AccountBalanceEvent();

$obj = new SMSModeEventListener();
$obj = new SMSModeEventListener($this->logger);

try {

Expand Down Expand Up @@ -177,7 +177,7 @@ public function testOnAddingContactWithRuntimeException() {
// Set an Adding contact event mock.
$addingContactEvent = new AddingContactEvent($this->addingContact);

$obj = new SMSModeEventListener();
$obj = new SMSModeEventListener($this->logger);

try {

Expand Down Expand Up @@ -220,7 +220,7 @@ public function testOnCheckingSMSMessageStatusWithRuntimeException() {
// Set an Checking SMS message status event mock.
$checkingSMSMessageStatusEvent = new CheckingSMSMessageStatusEvent($this->checkingSMSMessageStatus);

$obj = new SMSModeEventListener();
$obj = new SMSModeEventListener($this->logger);

try {

Expand Down Expand Up @@ -263,7 +263,7 @@ public function testOnCreatingAPIKeyWithRuntimeException() {
// Set a Creating API key event mock.
$creatingAPIKeyEvent = new CreatingAPIKeyEvent();

$obj = new SMSModeEventListener();
$obj = new SMSModeEventListener($this->logger);

try {

Expand Down Expand Up @@ -306,7 +306,7 @@ public function testOnCreatingSubAccountWithRuntimeException() {
// Set a Creating sub-account event mock.
$creatingSubAccountEvent = new CreatingSubAccountEvent($this->creatingSubAccount);

$obj = new SMSModeEventListener();
$obj = new SMSModeEventListener($this->logger);

try {

Expand Down Expand Up @@ -349,7 +349,7 @@ public function testOnDeletingSMSWithRuntimeException() {
// Set a Deleting SMS event mock.
$deletingSMSEvent = new DeletingSMSEvent($this->deletingSMS);

$obj = new SMSModeEventListener();
$obj = new SMSModeEventListener($this->logger);

try {

Expand Down Expand Up @@ -392,7 +392,7 @@ public function testOnDeletingSubAccountWithRuntimeException() {
// Set a Deleting sub-account event mock.
$deletingSubAccountEvent = new DeletingSubAccountEvent($this->deletingSubAccount);

$obj = new SMSModeEventListener();
$obj = new SMSModeEventListener($this->logger);

try {

Expand Down Expand Up @@ -435,7 +435,7 @@ public function testOnDeliveryReportWithRuntimeException() {
// Set a Delivery report event mock.
$deliveryReportEvent = new DeliveryReportEvent($this->deliveryReport);

$obj = new SMSModeEventListener();
$obj = new SMSModeEventListener($this->logger);

try {

Expand Down Expand Up @@ -478,7 +478,7 @@ public function testOnRetrievingSMSReplyWithRuntimeException() {
// Set a Retrieving SMS reply event mock.
$retrievingSMSReplyEvent = new RetrievingSMSReplyEvent($this->retrievingSMSReply);

$obj = new SMSModeEventListener();
$obj = new SMSModeEventListener($this->logger);

try {

Expand Down Expand Up @@ -521,7 +521,7 @@ public function testOnSendingSMSBatchWithRuntimeException() {
// Set a Sending SMS batch event mock.
$sendingSMSBatchEvent = new SendingSMSBatchEvent($this->sendingSMSBatch);

$obj = new SMSModeEventListener();
$obj = new SMSModeEventListener($this->logger);

try {

Expand Down Expand Up @@ -564,7 +564,7 @@ public function testOnSendingSMSMessageWithRuntimeException() {
// Set a Sending SMS message event mock.
$sendingSMSMessageEvent = new SendingSMSMessageEvent($this->sendingSMSMessage);

$obj = new SMSModeEventListener();
$obj = new SMSModeEventListener($this->logger);

try {

Expand Down Expand Up @@ -607,7 +607,7 @@ public function testOnSendingTextToSpeechSMSWithRuntimeException() {
// Set a Sending text-to-speech SMS event mock.
$sendingTextToSpeechSMSEvent = new SendingTextToSpeechSMSEvent($this->sendingTextToSpeechSMS);

$obj = new SMSModeEventListener();
$obj = new SMSModeEventListener($this->logger);

try {

Expand Down Expand Up @@ -650,7 +650,7 @@ public function testOnSendingUnicodeSMSWithRuntimeException() {
// Set a Sending unicode SMS event mock.
$sendingUnicodeSMSEvent = new SendingUnicodeSMSEvent($this->sendingUnicodeSMS);

$obj = new SMSModeEventListener();
$obj = new SMSModeEventListener($this->logger);

try {

Expand Down Expand Up @@ -693,7 +693,7 @@ public function testOnSentSMSMessageListWithRuntimeException() {
// Set a Sent SMS message list event mock.
$sentSMSMessageListEvent = new SentSMSMessageListEvent($this->sentSMSMessageList);

$obj = new SMSModeEventListener();
$obj = new SMSModeEventListener($this->logger);

try {

Expand Down Expand Up @@ -736,7 +736,7 @@ public function testOnTransferringCreditsWithRuntimeException() {
// Set a Transferring credits event mock.
$transferringCreditsEvent = new TransferringCreditsEvent($this->transferringCredits);

$obj = new SMSModeEventListener();
$obj = new SMSModeEventListener($this->logger);

try {

Expand All @@ -755,7 +755,7 @@ public function testOnTransferringCreditsWithRuntimeException() {
*/
public function testSetAccessToken() {

$obj = new SMSModeEventListener();
$obj = new SMSModeEventListener($this->logger);

$obj->setAccessToken("accessToken");
$this->assertEquals("accessToken", $obj->getApiProvider()->getAuthentication()->getAccessToken());
Expand All @@ -768,7 +768,7 @@ public function testSetAccessToken() {
*/
public function testSetPass() {

$obj = new SMSModeEventListener();
$obj = new SMSModeEventListener($this->logger);

$obj->setPass("pass");
$this->assertEquals("pass", $obj->getApiProvider()->getAuthentication()->getPass());
Expand All @@ -781,7 +781,7 @@ public function testSetPass() {
*/
public function testSetPseudo() {

$obj = new SMSModeEventListener();
$obj = new SMSModeEventListener($this->logger);

$obj->setPseudo("pseudo");
$this->assertEquals("pseudo", $obj->getApiProvider()->getAuthentication()->getPseudo());
Expand Down
4 changes: 2 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@
"require": {
"php": "^5.6|^7.0",
"ext-json": "*",
"webeweb/core-bundle": "^2.4",
"webeweb/smsmode-library": "^2.1"
"webeweb/core-bundle": "^2.9",
"webeweb/smsmode-library": "^2.5"
},
"require-dev": {
"phpunit/phpunit": "^5.7|^7.0",
Expand Down

0 comments on commit aefe097

Please sign in to comment.