<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Digital Cloud - Medium]]></title>
        <description><![CDATA[Digital Cloud - Medium]]></description>
        <link>https://medium.com/digitalcloud?source=rss----66944a455497---4</link>
        <image>
            <url>https://cdn-images-1.medium.com/proxy/1*TGH72Nnw24QL3iV9IOm4VA.png</url>
            <title>Digital Cloud - Medium</title>
            <link>https://medium.com/digitalcloud?source=rss----66944a455497---4</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sun, 06 Dec 2026 08:19:59 GMT</lastBuildDate>
        <atom:link href="https://medium.com/feed/digitalcloud" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Reactive Laravel Notifications]]></title>
            <link>https://medium.com/digitalcloud/reactive-laravel-notifications-d1d712a015ff?source=rss----66944a455497---4</link>
            <guid isPermaLink="false">https://medium.com/p/d1d712a015ff</guid>
            <category><![CDATA[channel]]></category>
            <category><![CDATA[laravel]]></category>
            <category><![CDATA[notifications]]></category>
            <category><![CDATA[multilingual]]></category>
            <category><![CDATA[reactive]]></category>
            <dc:creator><![CDATA[Yassir Awad]]></dc:creator>
            <pubDate>Tue, 15 Jan 2019 15:57:35 GMT</pubDate>
            <atom:updated>2019-01-15T15:57:35.757Z</atom:updated>
            <content:encoded><![CDATA[<h4>Building advanced Laravel notifications, solving multilingual and content changing problems.</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*FjidvsHyWyXeLMtGPbxkSg.gif" /></figure><p>Laravel notification was released in version 5.3 as a major framework addition. It provides a simple, expressive API for sending notifications across a variety of delivery channels with pre-shipped channels, and as always the Laravel community contributes and offers many <a href="http://laravel-notification-channels.com/">custom channels</a>.</p><p>One of the essential channels is <strong>Database Notification</strong> that stores the notification body in the predefined notifications table. Let’s start with a simple example assuming that we have <strong><em>InvitationNotification </em></strong>class that has <em>toArray </em>method containing the notification bodies like title and details:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/372d125ad7306c8779ba1773c34a6ad7/href">https://medium.com/media/372d125ad7306c8779ba1773c34a6ad7/href</a></iframe><h3><strong>Bottleneck</strong></h3><p>As you see in the previous code, Laravel <strong><em>DatabaseChannel </em></strong>will store the result of <em>toArray </em>or <em>toDatabase </em>methods in notification data to be used later, and this may be worked on some projects, but from here we have some limitations:</p><ul><li>Having multiple languages, and the user can switch between these languages, how can we display <em>title </em>and <em>details </em>once in English and the other in Arabic?</li><li>What can we do if the notification content changed dynamically? For example, birthday notification “Today is John Doe’s birthday”, after one-day notification required to be “Yesterday was John Doe’s birthday” and so forth.</li><li>When a user likes a post, a notification is sent to post creator “Jane doe liked your post”, and when another user likes the post, a notification will be changed to “Jon and Jane liked your post”.</li></ul><p>To support multilingual, I tried to solve the problem by storing translations keys and their parameters in the database, and when reading notification applies the <em>trans </em>function on <em>title </em>and <em>details</em>. But also there is a gap because the trans parameters maybe also have translatable keys.</p><p>For the second point, we can’t make these changes only by creating a new notification or updating a current notification body with new messages.</p><h3><strong>Solution</strong></h3><p>After I reached a deadlock to have the best solution to this problem, I found another solution, and I built a package to solve this problem. The solution relies on Overriding <strong><em>DatabaseChannel </em></strong>to store notification data as a serialized notification object instead of storing an array of keys and values.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/88b5e6db4b420e008b7f23d4ba07cd3f/href">https://medium.com/media/88b5e6db4b420e008b7f23d4ba07cd3f/href</a></iframe><p>I also overrode <strong><em>DatabaseNotification </em></strong>model and added an accessor for data field to unserialize data if it was serialized then extract notification object, and finally call <em>toDatabase </em>or <em>toArray </em>methods to get the final output.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/8d82b129c8277781527f0717fd29f8c2/href">https://medium.com/media/8d82b129c8277781527f0717fd29f8c2/href</a></iframe><p><strong>Benefits</strong></p><p>By using this way, all notification body code preparation are moved into <em>toDatabase </em>or to <em>toArray </em>methods that give your code some of the arrangements.</p><h3><strong>Usage</strong></h3><p><a href="https://github.com/DigitalCloud/reactive-notification">DigitalCloud/reactive-notification</a></p><blockquote><strong>Installing</strong></blockquote><pre><em>composer requires digitalcloud/reactive-notification</em></pre><blockquote><strong>Publish &amp; Migration</strong></blockquote><pre><em>php artisan vendor:publish provider=”Digitalcloud\ReactiveNotification\ReactiveNotificationServiceProvider”</em></pre><pre><em>php artisan migrate</em></pre><blockquote><strong>Usage</strong></blockquote><ol><li>Change trait used in the model from <em>Illuminate\Notifications\Notifiable </em>to <em>Digitalcloud\ReactiveNotification\Traits\Notifiable</em>.</li></ol><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/9c8ad2bbad77d59520525603c2003d76/href">https://medium.com/media/9c8ad2bbad77d59520525603c2003d76/href</a></iframe><p>2. Change delivery channel from database or <em>Illuminate\Notifications\Channels\DatabaseChannel </em>to <em>Digitalcloud\ReactiveNotification\Channels\DatabaseChannel</em>.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/1dc085980dafc75e26f26b7fa11d79d4/href">https://medium.com/media/1dc085980dafc75e26f26b7fa11d79d4/href</a></iframe><blockquote><strong>Examples</strong></blockquote><ul><li>Translations:</li></ul><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/115def8cb74487d800a389bf30817188/href">https://medium.com/media/115def8cb74487d800a389bf30817188/href</a></iframe><ul><li>Content changed dynamically:</li></ul><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/d405682d40238ee88f13843f8993a087/href">https://medium.com/media/d405682d40238ee88f13843f8993a087/href</a></iframe><pre><em>$user-&gt;notify(new BirthDayNotification($member));</em></pre><pre><em>$notification = $user-&gt;notifications()-&gt;first();</em></pre><p>If a member’s birthday is today, the result message will be “Today is John’s birthday, wish him a happy birthday!”</p><p>If the member’s birthday was yesterday, the result message will change to “John celebrated his birthday yesterday”.</p><pre><em>Carbon::setTestNow(now()-&gt;addDay());</em></pre><p>Finally, if the member’s birthday was on a date, the result message will change to “John celebrated his birthday on 31 Dec”</p><pre><em>Carbon::setTestNow(now()-&gt;addMonths(3));</em></pre><p>I hope you enjoyed going through this package and benefited from the details listed. Stay tuned to find out more about other helpful stories in regard to advanced Laravel notifications.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=d1d712a015ff" width="1" height="1" alt=""><hr><p><a href="https://medium.com/digitalcloud/reactive-laravel-notifications-d1d712a015ff">Reactive Laravel Notifications</a> was originally published in <a href="https://medium.com/digitalcloud">Digital Cloud</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Social Media Feeds Your Brand]]></title>
            <link>https://medium.com/digitalcloud/social-media-feeds-your-brand-abec21849830?source=rss----66944a455497---4</link>
            <guid isPermaLink="false">https://medium.com/p/abec21849830</guid>
            <category><![CDATA[marketing]]></category>
            <category><![CDATA[social-media]]></category>
            <category><![CDATA[digital]]></category>
            <category><![CDATA[branding]]></category>
            <category><![CDATA[roi]]></category>
            <dc:creator><![CDATA[Mahmoud Aldabous]]></dc:creator>
            <pubDate>Mon, 07 Jan 2019 15:57:48 GMT</pubDate>
            <atom:updated>2019-01-08T13:13:41.149Z</atom:updated>
            <content:encoded><![CDATA[<h4>Business Digitization is the No.1 Miracle of the 21st Century for New Profit-Making Opportunities.</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*PW8JA65RJieO95r7Rg3bKA.gif" /></figure><p>In the 21st century, going viral has been easier than lighting a cigarette; but after bringing the right strategy in hand, and grabbing the most appropriate social media channels which you will exploit to fit your needs and feed your business.</p><p>Social media these days serves and contributes much better than a good mom does. It helps you build your brand, reach your targeted audience, increase your <a href="https://www.investopedia.com/terms/r/returnoninvestment.asp">ROI</a>, highlight your products and services, respond quickly to customers questions and complaints, market anything at any time with less effort, evaluate performance and progress, and many other different purposes!</p><p>You do not have to build all that and leave everything to the coincidence. No, there might be too much competition, and you are required to seize your opportunity and prepare yourself in organized ways. In the digital world, there are multiple social media platforms, which force you to set your business apart and to have a unique structure or a masterpiece in the competition corner of the social media world.</p><p>Three of the fabulous social media platforms are <a href="https://twitter.com/">Twitter</a>, <a href="https://www.facebook.com/">Facebook</a>, and <a href="https://www.instagram.com/">Instagram</a>. Those three paths provide great mechanisms for any brand to climb the ladder of success with their easy to use methods and the high number of users. Despite the many other social platforms, your brand can depend on them to commence the journey into innovation and gain a great deal of audience attention.</p><p><a href="https://dce.sa/en">Digital Cloud</a> has been in the vanguard of digital marketing companies for more than ten years and in appreciating diversity in its workforce. It has helped 70+ clients in building their brands and businesses, grabbing to them millions of customers from the Kingdom of Saudi Arabia and many other regions of the world in a variety of fields. Nothing was simple but based on well-organized workflow by experts who have been succeeding in their Battles using sophisticated Weapons for social media management and digital marketing.</p><p>As a social media analyst, and after experiencing many social media management solutions, I have learned that there are two you can count on; <a href="https://www.socialbakers.com/">Socialbakers</a> and <a href="https://sproutsocial.com/">Sprout Social</a>. Those two global marketing and management platforms provide significant assistance to anyone working in the field, promoting a diversity of methods for businesses to monitor, manage, and take most of the control to track performance and make smart decisions when it comes to pursuing success and beating competitors.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=abec21849830" width="1" height="1" alt=""><hr><p><a href="https://medium.com/digitalcloud/social-media-feeds-your-brand-abec21849830">Social Media Feeds Your Brand</a> was originally published in <a href="https://medium.com/digitalcloud">Digital Cloud</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Killing the Mobile Apps Beast!]]></title>
            <link>https://medium.com/digitalcloud/killing-the-mobile-apps-beast-446c0f041331?source=rss----66944a455497---4</link>
            <guid isPermaLink="false">https://medium.com/p/446c0f041331</guid>
            <category><![CDATA[mobile-app-development]]></category>
            <category><![CDATA[modules]]></category>
            <category><![CDATA[android-app-development]]></category>
            <category><![CDATA[ioc]]></category>
            <category><![CDATA[ios-app-development]]></category>
            <dc:creator><![CDATA[Yusuf Meimeh]]></dc:creator>
            <pubDate>Wed, 02 Jan 2019 13:50:47 GMT</pubDate>
            <atom:updated>2019-01-08T13:16:50.924Z</atom:updated>
            <content:encoded><![CDATA[<h4>How to divide a big iOS and Android projects to modules and shared packages.</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Six8MLXEfjBy2qmKJcdoxA.gif" /></figure><p><strong>Players: </strong>Yusuf Meimeh (iOS) and Abdullah Hussein (Android).</p><p><strong>Level: </strong>70+ Screens in 15+ Modules Mobile App Beast.</p><p><strong>Background: <br></strong>Beast: You enjoyed feed me in the previous six months? I’m feeling satiety and cannot eat more! I will eat you and your productivity.</p><p><strong>Mission: </strong>Figure out the best way to divide the app into smaller decoupled yet integrated parts.</p><p>In this article, we will share our experience to pass this level, and we hope you enjoy our path and share your thoughts with us. One of the most significant problems we face is the inverse relationship between the app grow and our productivity especially when we need to enhance the previous module.</p><p>The app was delivered to us after a long failure with other companies and the product owner needs to build a new version from scratch as fast as possible, so we started with the straightforward approach and developed it as a single app. It is difficult to imagine how big the product will be so we built it in a single app.</p><p>After the first release, the client started to add new features, and the app became bigger and bigger. Therefore, we began to lose control and face many difficulties when updating any existing features which have led to testing all related features again to guarantee everything is ok.</p><p>Delivery time, bug fixing effort, building, debugging and running the app in Simulator or real device, all affected and increased over time, and sometimes it is very complicated even to disable, delete or delay the release of some modification to a later stage!</p><p><strong>The Solution</strong></p><p>As an iOS developer, you may be familiar with a project with one or two targets if you use Pods. On the other hand, we start our Android projects with a single module.</p><p>We explore many separations of concerns methods, some of them end with a layered application, e.g., Presentation, Domain, and Data layer. However, we need more level up to deal with modules, not layers. So, we start splitting the app into smaller blocks:</p><ul><li><strong>App</strong>: register a list of modules and initialize them.</li><li><strong>Modules</strong>: represent a single module in the app.<br>(e.g., Auth, Setting, Events, News, etc.).</li><li><strong>Packages</strong>: common cross features and app features.<br>(e.g., UI views, network helpers and others).</li></ul><p>These blocks can be developed independently, but smoothly integrated and work with each other. While we have an already existing application, we take an incremental approach by leaving the main application as it is, and incrementally decouple its modules and packages one by one.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*vTczxLrlTyUDHkRLbGUzvg.png" /></figure><p>By decoupled feature module, we meant the complete responsibility of the feature including but not limited to the Presentation layer, Models, Notification handling, Menu items, and 3rd Party libraries.</p><p>While focusing on modularity and decoupling, this approach can simplify the reusability of these modules into other apps. Another not planned advantages are the ability to develop each feature with its architecture, and SDK version.</p><p>To achieve the dynamic modules loader, we start our Service Provider Pattern implementation, all of our modules must implement an interface so it can be loaded, initialized, and perform some actions like notification handling and menu items.</p><p>We currently experiment some refinements like IoC container, Event-driven modules communication, Kotlin multi-platform library, and we expect to get back to you soon with some templates and packages.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=446c0f041331" width="1" height="1" alt=""><hr><p><a href="https://medium.com/digitalcloud/killing-the-mobile-apps-beast-446c0f041331">Killing the Mobile Apps Beast!</a> was originally published in <a href="https://medium.com/digitalcloud">Digital Cloud</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Micro TDD, Fake Event Driven Decoupling]]></title>
            <link>https://medium.com/digitalcloud/micro-tdd-fake-event-driven-decoupling-796346f9e03d?source=rss----66944a455497---4</link>
            <guid isPermaLink="false">https://medium.com/p/796346f9e03d</guid>
            <category><![CDATA[microservices]]></category>
            <category><![CDATA[laravel]]></category>
            <category><![CDATA[testing]]></category>
            <category><![CDATA[tdd]]></category>
            <dc:creator><![CDATA[Mohammed S. Shurrab]]></dc:creator>
            <pubDate>Thu, 20 Dec 2018 16:35:35 GMT</pubDate>
            <atom:updated>2019-01-08T13:14:58.778Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*SAYG2HvGrOWknAFo5MQsvA.gif" /></figure><p>In the past article, we started a series about how thinking about <a href="https://medium.com/digitalcloud/micro-tdd-its-hard-but-it-s-worth-it-45017643b4b3">microservices change our TDD approach</a>, and help us set some rules to decouple our code. We saw how migrating a subset of the database can dramatically affect your test suite and reveal unexpected coupling. We also reviewed how to restructure your migration folder, offer helper method for partial migration, and introduce two ways of solving the foreign key problem.</p><p>Wherever your business logic is live, we are amazed how modules coupled to each other. Let’s review this code:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/e3bd9447a155755c8db22895136a63bc/href">https://medium.com/media/e3bd9447a155755c8db22895136a63bc/href</a></iframe><p>Based on the requirements, once the user verifies a new mobile number, we must delete any unverified users linked to that number, delete all related activation codes, link the mobile with the user, delete invalid invitation based on some criteria, and finally notify the user if he/she has a new invitation based on the new number.</p><p>As we can notice, this tiny 6-lines method weaves three modules together, (1) the user module, (2) number verification module, and (3) invitation module. Before using the Micro TDD approach, we simply write a feature test like this:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/358d9890f66529f5f006ca347611ceb2/href">https://medium.com/media/358d9890f66529f5f006ca347611ceb2/href</a></iframe><p>While the test code is simple and asserts many aspects of the addNewMobile, it introduces many problems:</p><ol><li>It does not test all aspects, so you will start adding extra test cases like `test_activation_code_deleted_after_user_add_new_mobile_number` and<em>`test_invalid_invitation_deleted_after_user_add_new_mobile_number`</em> … etc.</li><li>If you run the test coverage report, it will not detect these untested lines, and you will be responsible for ensuring that you cover all cases.</li><li>The code tests three different aspects in one shot, and you need to prepare and assert for all of them. Nevertheless, why I need an invitation table if I test the new mobile number functionality?</li></ol><p>To fix these problems, we add a new rule to our Micro TDD approach. In addition to the partial migration, we use Event-driven approach to decouple the code. If you review the code again, addNewMobile has three chunks, before “Creating” the UserMobile, UserMobile creation, and after the UserMobile “Created”. Doesn’t sound familiar?</p><p>Yes, you can use the <a href="https://laravel.com/docs/5.7/eloquent#events">Eloquent events</a>, but if you notice, this function is only called if we need to create a VERIFIED entry. When you have a specific condition like this, it is better to have our own events. For DDDer, this will support your ubiquitous language. So, we start with the creation of two events and two corresponding listeners. The final addNewMobile will look like:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/49e050a470e552e47152e76936367623/href">https://medium.com/media/49e050a470e552e47152e76936367623/href</a></iframe><p>We add the events and listeners to EventServiceProvide array, generate them using `php artisan event:generate`, and move the logic from the Model method to the listener handlers.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/e0d45776984bd694e5c01374f48b8ab3/href">https://medium.com/media/e0d45776984bd694e5c01374f48b8ab3/href</a></iframe><h4><strong>Bonus :)</strong></h4><p>While the previous code is Okay, we can take it one step further by simulating the Eloquent Events style. To do that we need to:</p><ol><li>Unify the Verifying and Verified event argument to receive a Model instance.</li><li>2. If any of the Verifying listeners return (false), we must stop the process.</li></ol><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/e263e72018d5f3239ea23939225a020e/href">https://medium.com/media/e263e72018d5f3239ea23939225a020e/href</a></iframe><p>The code maybe complicate a little bit, but it is a perfect candidate for new package idea, and we are already working on that ;)</p><p>Returning to the listeners, it is a common mistake to think about them as one to one relation with the events. If another developer reviews the last AddNewMobile method and EventServiceProvider array, he/she will have no idea about what is going on. Let’s divide and rename the listeners where each of them handles single operation.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/3ea4abb1495f4f77118b1892e4e78379/href">https://medium.com/media/3ea4abb1495f4f77118b1892e4e78379/href</a></iframe><p>Look how names are more familiar and the behavior for each of them is expected? The order can quickly change, and they can be reused after different events if needed.</p><p>Let’s return to our <strong>Micro TDD</strong> approach, and see how the test can be better with this approach, and how can we force ourselves to use it. You introduce three main rules when testing a Model level logic.</p><h4><strong>Rule #1 Fake the Event bus:</strong></h4><p>This will simply prevent any event from being dispatched, so you can focus on testing the business logic only. Sometimes you need to Fake only specific events, not the overall event bus so that you can define the array of Faked events as an argument:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/8c8236cc93d1720e5c8a71f4fa15f38c/href">https://medium.com/media/8c8236cc93d1720e5c8a71f4fa15f38c/href</a></iframe><h4><strong>Rule #2 Assert that events are dispatched:</strong></h4><p>It would be best if you made sure that all required events are dispatched, and you can also test additional requirements using the `assertDispatched` 2nd callback parameter, for example, we can make sure that Verifying event include an instance of UserMobile, not the mobile number itself.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/8c8236cc93d1720e5c8a71f4fa15f38c/href">https://medium.com/media/8c8236cc93d1720e5c8a71f4fa15f38c/href</a></iframe><h4><strong>Rule #3 Create a Unit Test for each listener.</strong></h4><p>Until now, if you run the Test Coverage report, all listeners will be uncovered. So, we will start testing the handle methods for each listener separately. This will help us check it once, and reuse it in different context and events. While it is easy in Laravel to Fake specific events, it is not that easy to fire an event and dispatch only one particular listener, so we investigate some options and will publish a package with the final solution if needed.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/cfd903fbf0a7a02f80e67fb76fcc8274/href">https://medium.com/media/cfd903fbf0a7a02f80e67fb76fcc8274/href</a></iframe><h3>2nd Bonus ;)</h3><p>Whenever you see a “Send*” listener, and the listener handle method is only responsible for sending a notification, you can quickly move the handle method within the notification/mailable itself, and delete the listener entirely. Thanks to <a href="https://themsaid.com/laravel-mailables-notfiications-as-event-listeners-20170516/">Mohammed Said</a> trick ❤.</p><p>As you can see, Partial Migration and Fake Events can lead to better decoupling, testable code, and more accurate test coverage. We still have many other topics to be covered to stay tuned for the next article.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=796346f9e03d" width="1" height="1" alt=""><hr><p><a href="https://medium.com/digitalcloud/micro-tdd-fake-event-driven-decoupling-796346f9e03d">Micro TDD, Fake Event Driven Decoupling</a> was originally published in <a href="https://medium.com/digitalcloud">Digital Cloud</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Micro TDD, It’s Hard, But It’s Worth It!]]></title>
            <link>https://medium.com/digitalcloud/micro-tdd-its-hard-but-it-s-worth-it-45017643b4b3?source=rss----66944a455497---4</link>
            <guid isPermaLink="false">https://medium.com/p/45017643b4b3</guid>
            <category><![CDATA[php]]></category>
            <category><![CDATA[microservices]]></category>
            <category><![CDATA[tdd]]></category>
            <category><![CDATA[laravel]]></category>
            <dc:creator><![CDATA[Mohammed S. Shurrab]]></dc:creator>
            <pubDate>Tue, 11 Dec 2018 12:25:26 GMT</pubDate>
            <atom:updated>2019-01-08T13:15:54.014Z</atom:updated>
            <content:encoded><![CDATA[<h4>Microservices drive us to rethink in our TDD approach, and this is why we called it “Micro TDD”.</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*i9UgZlCKb4U96TYvUpTq3w.gif" /></figure><p>I am in love with TDD Laravel for more than two years. During this period, I was amazed at how Laravel help makes it pretty easy to test very advanced topics.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/ebca7df71d766e301ecc165a02feacb9/href">https://medium.com/media/ebca7df71d766e301ecc165a02feacb9/href</a></iframe><p>For now-Laravel developers, this code: migrates a fresh database, fake Passport OAuth 2.0 server, authentication of a user generated by the factory, send a PUT request to update the profile, assert the response status, assert the JSON structure, and assert the sending of a notification to the user!</p><p>If you follow the top-down approach, you will start with a Feature test like this one, and you may occasionally write some Unit tests for more complicated logic. We successfully used this approach for many projects, until we decided to use the Microservices approach in one of them.</p><p>Yes! Microservices drive us to rethink in our TDD approach, and this is why we called it “Micro TDD”. The approach does not require you to use Microservices; it merely makes your code more modular, decoupled, and easier to maintain. As a side effect, the test suite will be more organized, descriptive and faster!</p><h3>The Problem!</h3><p>Let us review the previous Feature test again. We will refer to it as “Monolithic test” because of the following:</p><ol><li>We migrate the full database to test the profile update feature.</li><li>Both “notification_settings” and “events_count” appear in the user resource while they belong to other modules.</li><li>We use the database assertions to ensure that the name is changed nested of test the JSON returned data.</li><li>We test if the notification is sent to the right user.</li></ol><p>Noted why we call it “Monolithic”? The centric database, modules coupling, and dependent on a one-shot Feature test. These characteristics are quite similar to the Monolithic App. Therefore, we decided to try another approach derived from the Microservices patterns.</p><h3>The Biggest Failure</h3><p>The first step we take is to remove the Global migration and seeding codes, and use clear in test setup phase. The new test class will look like:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/3ca37812b78efa1b051b432260f7bf0b/href">https://medium.com/media/3ca37812b78efa1b051b432260f7bf0b/href</a></iframe><p>Nested of seeding the data globally in the base test class setup, we use the seed helper function to run the “MaritalStatusesSeeder” while it’s a part of the user module, and we use custom migrate helper to migrate only the tables related to the current test, in our case the user related tables.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/6935c44bc49603f2b7fb4e681324a314/href">https://medium.com/media/6935c44bc49603f2b7fb4e681324a314/href</a></iframe><p>As you can see in DATABASE_MIGRATIONS_USER, we restructure the database migrations folder and group each set of migrations as folder per module.</p><p>Almost every test case in a suite of ~1k test cases failed, just because not all tables –even from unexpected modules- exist. We try to investigate where these couplings live, and we are amazed that we have coupled Tests, Controllers, Models, Form Requests, Middleware, API Resources, Jobs, And even Migrations files!</p><p>Absolutely, it is not the Framework problem, nor a Monolithic app requirement to couple your app like this, but let us face the fact, you cannot develop a big project without end with these problems, and we need a way to force that decoupling. Remove the usage of full Database Migration is the first step in this journey.</p><p>The most confusing yet simple coupling is the migrations, how migrate a table can cause coupling between modules in the first place?</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/0f5baff5da9efda07e032a7e39cdf18b/href">https://medium.com/media/0f5baff5da9efda07e032a7e39cdf18b/href</a></iframe><p>Oh, my foreign! We cannot migrate the event module unless we migrate user module first, and this is not the case in Microservices world. Therefore, we decide to disable any cross modules foreign keys. You can do that using two approaches:</p><ol><li>Remove the foreign keys entirely and think about modules tables as they deploy in different databases like a real Microservices.</li><li>Keep them and use “enable/disableForeignKeyConstraints” helpers from Laravel Schema façade.</li></ol><p>In the next articles, we will dive deep into other types of coupling, and how can Laravel help us deal with some of them. We also developed some custom solutions to solve more complicated problems, and we will share them as snippets or open source packages with each article.</p><p><strong>Stay tuned!</strong></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=45017643b4b3" width="1" height="1" alt=""><hr><p><a href="https://medium.com/digitalcloud/micro-tdd-its-hard-but-it-s-worth-it-45017643b4b3">Micro TDD, It’s Hard, But It’s Worth It!</a> was originally published in <a href="https://medium.com/digitalcloud">Digital Cloud</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>