Skip to content

Incoming message handling tweaks#60

Closed
dpi wants to merge 12 commits into
8.x-1.xfrom
incoming-tweaks-2832601
Closed

Incoming message handling tweaks#60
dpi wants to merge 12 commits into
8.x-1.xfrom
incoming-tweaks-2832601

Conversation

@dpi
Copy link
Copy Markdown
Owner

@dpi dpi commented Dec 3, 2016

@dpi dpi force-pushed the incoming-tweaks-2832601 branch from 5f6cf34 to 1fc03f8 Compare December 3, 2016 06:13
Added results and reports for incoming messages created in tests.
Added createMessageResult test helper to create reports and result for a message.
@dpi dpi force-pushed the incoming-tweaks-2832601 branch from a6702a9 to cc2f4cf Compare December 3, 2016 09:13
@dpi dpi force-pushed the incoming-tweaks-2832601 branch from cc2f4cf to d8c3170 Compare December 3, 2016 10:46
Compacted sms_test_gateway gateway config schema (Derivative types)
Added plugin incoming method to execution order tests.
New test file covering \Drupal\sms\EventSubscriber\SmsMessageProcessor (some \Drupal\Tests\sms\Kernel\SmsFrameworkProviderTest tests should be moved there)
@dpi dpi force-pushed the incoming-tweaks-2832601 branch from e0c168c to 9f18f1f Compare December 4, 2016 10:22
Added SmsGateway::supportsIncoming()
Add preprocess check to incoming messages ensuring they have a gateway set, and the gateway supports incoming messages.
Added tests for above.
Added missing gateway entity to incoming message tests.
@dpi dpi force-pushed the incoming-tweaks-2832601 branch from 9f18f1f to ffbe6a1 Compare December 4, 2016 10:42
Comment thread src/Provider/DefaultSmsProvider.php Outdated

$this->dispatchEvent(SmsEvents::MESSAGE_INCOMING_POST_PROCESS, [$sms_message]);
$this->dispatchEvent(SmsEvents::MESSAGE_POST_PROCESS, [$sms_message]);
if ($plugin instanceof SmsGatewayPluginIncomingEventInterface) {
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What I did not understand here is how a plugin can also be an Event. What is the reasoning behind the interface name?
Ok, I just checked the SmsGatewayPluginIncomingEventInterface interface description and so I think it should be called IncomingEventSubscriberInterface or IncomingEventProcessorInterface so it's clearer that the plugin is an incoming event subscriber or processor.

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This interface is designed specifically for gateway plugins, do we not want to prefix these interfaces with SmsGateway or SmsGatewayPlugin?

  • SmsGatewayPluginIncomingEventInterface (current, prefixed)
  • SmsGatewayPluginIncomingEventSubscriberInterface
  • SmsGatewayPluginIncomingEventProcessorInterface I'd probably go with this one.

Bit of a mouthful 😒

Copy link
Copy Markdown

@almaudoh almaudoh Dec 11, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's the verbosity that made me leave out 'SmsGatewayPlugin..' in my original suggestion. These Drupal interface names are becoming like Java class names :)

TBH I can't really decide which is better: SmsGatewayPluginIncomingEventProcessorInterface is too long, but it's also consistent with others. So it depends on how people feel about long class and interface names. Maybe it's becoming acceptable in the Drupal world.
OTOH, since IncomingEventProcessorInterface is namespaced in Drupal\sms\Plugin it should be understood that it's specifically for gateway plugins.

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

since IncomingEventProcessorInterface is namespaced in Drupal\sms\Plugin it should be understood that it's specifically for gateway plugins.

Not quite. I think if it was in \Drupal\sms\Plugin\SmsGateway we can avoid the prefix.

Result:

\Drupal\sms\Plugin\SmsGateway\IncomingEventProcessorInterface

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Renaming to \Drupal\sms\Plugin\SmsGateway\SmsIncomingEventInterface

It would be more consistent with the rest of plugin interfaces to have the directory name as the file prefix (SmsGatewayIncomingEventInterface).

File name still has the module prefix. Its in the SmsGateway directory so we can omit 'Gateway' I suppose. 'IncomingEvent' portion of file name matches the method exactly incomingEvent.

}

// Slice of the first {$delete_reports}x reports.
$reports = array_slice($reports, $delete_reports);
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be "// Slice off..."

}

/**
* Ensure exception thrown if incoming message is missing a result.
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Description needs update.

$this->container->get('cron')->run();

$expected[] = SmsEvents::MESSAGE_INCOMING_PRE_PROCESS;
$expected[] = 'incomingEvent'; // Plugin incoming event.
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It looks wierd that this is the only one without a constant defined in SmsEvents? Is it not a real event like the others?

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it not a real event like the others?

Not exactly, see \Drupal\sms\Provider\DefaultSmsProvider::incoming

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

https://www.drupal.org/node/2832601#comment-11809897: Comment 7 & 8 are pretty much why this is weird.

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we should use a constant like the others for consistency sake. Even though it's not a subscribed Symfony event like the others. The purpose of a constant is to store a value so you remain DRY in your programming.
So even this is not a real event, it needs to live somewhere as a constant and I don't think we need to create another class just for it.

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we should use a constant like the others for consistency sake. Even though it's not a subscribed Symfony event like the others. The purpose of a constant is to store a value so you remain DRY in your programming.

Except this value 'incomingEvent' is ONLY used for testing, and only in the sms_test_gateway submodule. The events are used in normal operation of the module.

The 'incomingEvent' is almost constant-like in its meaning, because it is derived from the method name. It isnt set from a plain string. See \Drupal\sms_test_gateway\Plugin\SmsGateway\Memory::incomingEvent

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not saying the $expected[] = 'incomingEvent'; assertion is aesthetically good. But if we could refer to method names in PHP like we can with classes ($class::class - class name resoution) then I would do that here.

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since we are using in tests only, I guess I can live with that.

Copy link
Copy Markdown
Owner Author

@dpi dpi Dec 15, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Before this is committed I'm going to change the magic constant from __FUNCTION__ to __METHOD__ so it captures the full namespace and class name. So it is easier to reverse engineer where its coming from when looking at the testing/assertion code.

$expected[] = 'incomingEvent'; will become $expected[] = 'Drupal\sms_test_gateway\Plugin\SmsGateway\Memory::incomingEvent'

/**
* Interface for gateways implementing an incoming event subscriber.
*/
interface SmsIncomingEventInterface {
Copy link
Copy Markdown

@almaudoh almaudoh Dec 15, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Still missed out the 'Processor' part which I think is the key word here SmsIncomingEventProcessorInterface or SmsIncomingEventSubscriberInterface. I guess "Processor" is more preferred to avoid confusion with real Symfony event subscribers.

Copy link
Copy Markdown
Owner Author

@dpi dpi Dec 15, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

SmsIncomingEventInterface renamed to SmsIncomingEventProcessorInterface

@dpi dpi force-pushed the incoming-tweaks-2832601 branch from 2612c34 to b54b459 Compare December 15, 2016 13:22
@dpi dpi closed this Dec 15, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants