-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
[Notifier] [FakeSms] Add the bridge #39949
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
src/Symfony/Component/Notifier/Bridge/FakeSms/FakeSmsTransport.php
Outdated
Show resolved
Hide resolved
src/Symfony/Component/Notifier/Bridge/FakeSms/FakeSmsTransportFactory.php
Outdated
Show resolved
Hide resolved
I really like this bridge but I think we can do better. I am thinking of using the same approach as in the mercure-notifier and provide a service id for the mailer which should be used. Another thing which came to my mind: why not change ne name and scheme to "fake" only and support chat and sms? Please let's discuss this first before changing some code and get some feedback of others about this idea 💡 thanks |
@OskarStark Why using the service id instead of dependency injection from the constructor here ?
It's good idea, yes. |
@@ -2236,6 +2237,7 @@ private function registerNotifierConfiguration(array $config, ContainerBuilder $ | |||
AllMySmsTransportFactory::class => 'notifier.transport_factory.allmysms', | |||
FirebaseTransportFactory::class => 'notifier.transport_factory.firebase', | |||
FreeMobileTransportFactory::class => 'notifier.transport_factory.freemobile', | |||
FakeSmsTransportFactory::class => 'notifier.transport_factory.fakesms', |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
shouldnt this fake transport only be configured for dev
env?
also i really like the idea of having a fake transport, i have a question; why to rely on a mailer mail? why not a monolog log?
they are displayed in console, they are displayed in profiler, they are stored in file and it does not need another software to be installed
could not found the related issue that lead to this PR :)
thank you
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
shouldnt this fake transport only be configured for dev env?
I agree with that too.
why to rely on a mailer mail? why not a monolog log?
IMOH, I think it's will great if we can choose the destination.
For example :
- By email if the content contains a required information for the workflow (otp code)
- By log if the content is just an information and have no importance
- In a database or a redis to use that in functionnals testing and we should check or get information in the content message
What do you think ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@ke20 What do you think ?
I do not know the feature request/needs that initiate this PR, as written upper :)
But iiuc, the aim is to fake, in dev, the notifier sms logic to see if it works
I think that relying only on the mailer is overkill, a logger is enough => thus my previous comment :)
maybe yes a configured fake transport with multiple sublogic (log > mailer > database) can be the way, lets wait other reviews
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree, it would be interesting to be able to use other distribution channels. The packet was originally developed for the development of an otp system, important in the user workflow, so the choice of emails was made to facilitate testing.
Also, support of chat notifier would be a good thing.
I could do the integration of other channels in a few weeks, if anyone would like to contribute to this PR, feel free.
Maybe it has been discussed before but why not calling the bridge EmailNotifier instead ? And let developers use it for testing purposes or not. The primary need of this bridge is to "Fake SMS" in dev, I get it, but it doesnt necessarily mean that you have to use Email to do that. You could "fake it" by writing in logs for example. Also, a dedicated Email notifier could be useful in case where you have to notify both through SMS and Email while keeping the same kind of logic. |
So, it's also an idea, but I think it would be more interesting to keep the name "FakeNotifier" and to add several channels (like emails, logs, ...). Because, except for tests, there is no reason to use SMS Notifier to finally send emails. |
Lets think a bit further, but I think my idea with the chat is not ideal, because they are not interchangeable because of the options, or we accept all options and add the json payload to the "log", "mail", or "database". We can enable the recipe for Small recap
And we end up with one |
@JamesHemery open to go further? Do you agree with n ideas? If you don't have to much time right now I think we can go with the mail only solution for now and add other ones later. However to make it more clear I would name the scheme: fakesms+mail |
Hi @OskarStark, Yes I agree with these suggestions. I will be doing the schema fix within a week. |
src/Symfony/Component/Notifier/Bridge/FakeSms/FakeSmsTransport.php
Outdated
Show resolved
Hide resolved
friendly ping @JamesHemery 😃 |
8dcbc8c
to
bd87dd4
Compare
src/Symfony/Component/Notifier/Bridge/FakeSms/FakeSmsTransport.php
Outdated
Show resolved
Hide resolved
src/Symfony/Component/Notifier/Bridge/FakeSms/FakeSmsTransport.php
Outdated
Show resolved
Hide resolved
src/Symfony/Component/Notifier/Bridge/FakeSms/FakeSmsTransport.php
Outdated
Show resolved
Hide resolved
src/Symfony/Component/Notifier/Bridge/FakeSms/Tests/FakeSmsTransportTest.php
Outdated
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Some minor
I will make update tomorrow |
src/Symfony/Component/Notifier/Bridge/FakeSms/FakeSmsTransport.php
Outdated
Show resolved
Hide resolved
src/Symfony/Component/Notifier/Bridge/FakeSms/FakeSmsTransport.php
Outdated
Show resolved
Hide resolved
src/Symfony/Component/Notifier/Bridge/FakeSms/FakeSmsTransportFactory.php
Outdated
Show resolved
Hide resolved
src/Symfony/Component/Notifier/Bridge/FakeSms/FakeSmsTransportFactory.php
Outdated
Show resolved
Hide resolved
src/Symfony/Component/Notifier/Bridge/FakeSms/Tests/FakeSmsTransportTest.php
Outdated
Show resolved
Hide resolved
src/Symfony/Component/Notifier/Bridge/FakeSms/Tests/FakeSmsTransportTest.php
Outdated
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good to me 👍
src/Symfony/Component/Notifier/Bridge/FakeSms/Tests/FakeSmsTransportFactoryTest.php
Outdated
Show resolved
Hide resolved
src/Symfony/Component/Notifier/Bridge/FakeSms/FakeSmsTransportFactory.php
Outdated
Show resolved
Hide resolved
src/Symfony/Component/Notifier/Bridge/FakeSms/FakeSmsMailTransport.php
Outdated
Show resolved
Hide resolved
src/Symfony/Component/Notifier/Bridge/FakeSms/FakeSmsTransportFactory.php
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Last round of comments, afterwards I am going to merge this, thanks 👍
ec529fd
to
b705b17
Compare
It is because of the weird logic in that method. I suggest rewriting it to something more similar to: public function create(Dsn $dsn): TransportInterface
{
if ('fakesms+email' !== $dsn->getScheme()) {
throw new UnsupportedSchemeException($dsn, 'fakesms', $this->getSupportedSchemes());
}
$serviceId = $dsn->getHost();
$to = $dsn->getRequiredOption('to');
$from = $dsn->getRequiredOption('from');
$factory = new FakeSmsEmailTransport($this->serviceProvider->get($serviceId), $to, $from);
$factory->setHost($serviceId);
return $factory;
} |
Yes, I think too. But this will need a rewrite when we will add new transport. |
No (almost). It requires a rewrite when you add a new schema to this transport. Im okey with that. |
Or yes, A new transport to this FakeSmsFactory... still, Im okey with that. |
It took time, but here we go, this is in now. Thank you very much James. |
a66e662
to
351065e
Compare
This PR was squashed before being merged into the 5.3-dev branch. Discussion ---------- [Notifier] [FakeSms] Add the bridge Docs for symfony/symfony#39949 Commits ------- 337e251 [Notifier] [FakeSms] Add the bridge
This PR was merged into the 5.3-dev branch. Discussion ---------- [Notifier] [FakeSms] Use correct namespace | Q | A | ------------- | --- | Branch? | 5.x | Bug fix? | yes | New feature? | no | Deprecations? | no | Tickets | Follow #39949 | License | MIT | Doc PR | This fixes the build Needed after #40550 Commits ------- 5572bab [Notifier] [FakeSms] Use correct namespace
…karStark) This PR was merged into the 5.3-dev branch. Discussion ---------- [Notifier] [FakeSms] Change DSN to be more realistic | Q | A | ------------- | --- | Branch? | 5.x | Bug fix? | no | New feature? | no <!-- please update src/**/CHANGELOG.md files --> | Deprecations? | no <!-- please update UPGRADE-*.md and src/**/CHANGELOG.md files --> | Tickets | Follows #39949 | License | MIT | Doc PR | symfony/symfony-docs#... <!-- required for new features --> Just a minor tests change Commits ------- 0b13575 [Notifier] [FakeSms] Change DSN to be more realistic
This PR was merged into the 5.3-dev branch. Discussion ---------- [Notifier] [FakeChat] Added the bridge | Q | A | ------------- | --- | Branch? | 5.x | Bug fix? | no | New feature? | yes | Deprecations? | no | Tickets | | License | MIT | Doc PR | symfony/symfony-docs#15171 | Recipe PR | todo This PR is based on #39949 but for chat messages instead of SMS. Commits ------- 0ce156c [Notifier] [FakeChat] Added the bridge
@OskarStark Bridge added :)