The Best Way to Learn Magento 2

The very best way that I have found to figure out how to develop with Magento 2 is to write unit tests for a module. It not only requires you to figure out how to work with phpunit, but to also look at the existing codebase for examples of how the Magento 2 team works with the same objects and handles the same kinds of tasks. Once I wrote a full set of unit tests for my first Magento 2 module, I felt that I had a much better grasp of the workings of Magento 2 than I did before I started writing the unit tests.

When learning how to develop with Magento 1, it seemed that there weren’t that many publicly available resources for the experienced developer new to Magento development. In the end, I learned the most from going through Alan Storm’s (@alanstorm) excellent series on Magento 1.

However, when it comes to Magento 2, it definitely seems that there is an abundance of information available for how to do the extremely simple stuff, but not a lot available when it comes to some of the newer technologies that Magento 2 works with or some of the more obscure customizations that some stores require. Hearing that Magento 2’s architecture was completely different than what Magento 1 employed, and that the Mage object, that had been the core of everything you do as a Magento 1 developer, was gone, a good source for re-training seemed important for a team of Magento 1 developers. With the newness of Magento 2, the first training material I checked out was Magento’s own training videos. While they explained a lot of the dependency injection newness and reading of the very slides that were visible in the video portion, the most memorable part of the training was listening to the instructor repeat multiple file paths that were not reproduced directly in the video, and seemed to appear only in the accompanying notes.

Having a slight grasp of the high-level changes in Magento 2, it was time to find a resource that went a bit more in-depth with some real-world examples of customizations that you might make on your own Magento 2 store. That brought me back to Alan Storm’s Magento 2 series, but I still didn’t have a thorough understanding of how the intricacies of the PHP framework worked. While there was some familiarity with the system, it was not perfect, but it was time to start development with Magento 2.

Working on the first real module in Magento 2, based upon the Magento 2 Sample Module was slow and required lots of research to try to figure out how to load data and parse it, and all the other things that had become so natural with Magento 1. Once I finally got it working the way I wanted it to, I started writing unit tests to make sure that others working on the same code in the future would have some idea as to whether the changes they were making made things better or worse. At this point, it became evident that you have to know quite a bit about how all the factory objects work, and what they return when you call $this->collectionFactory->create(); so that you can not only create mock objects for the factory, but also the objects that are created by the factory. The best way that I found to figure out what these objects were and what to mock was to look at other tests that shipped with Magento 2 and see how they handled the exact same objects. When I started working on the next module after finishing the unit tests for the first one, the time to complete development was greatly reduced, with much less need to look outside the existing Magento 2 codebase for examples of how to accomplish tasks.

After this experience, you can be sure that I will make sure to write as many unit tests as possible, as they have already saved me from shipping some obscure bugs in my code that I would not have found until much further down the line.

Related Posts

Apr 24, 2014
2 minutes

Optimize Magento Time To First Byte

When looking at the performance of your site, waterfall charts are one of the first places you should investigate. The first thing that is represented on these charts is that the HTML for the website is the first resource that is downloaded every time.

As a result of being the first resource downloaded every time, this is the logical first place to look to improve the performance of your Magento website. There are a few ways to make sure that the page downloads more quickly, and they all involve making sure that the file size is as small as possible.

Mar 24, 2015
2 minutes

Laravel Removed The QuickStart For Version 5

To start out, I want to be clear that what follows should not be interpreted to be a criticism of the software framework that those that work on Laravel publish, nor an indictment of open-source software as a whole. Rather, it is a look at how some projects, open or closed source make it harder than it should be for new users/developers to utilize their terrific products.

It seems experts conveniently “forget” the tips and tricks and tribulations it takes to learn a new technology, covering it all with, “It’s just so easy”.

Mar 25, 2014
2 minutes

Magento Cache with Cache Disabled

One of the things that I find quite annoying with a web platform is when you configure it to do one thing, and it does something different. Magento is an eCommerce software platform that many of the leading eCommerce websites use for their web stores.

Magento

Magento comes in two different flavors, a paid enterprise edition as well as a open-source community edition. The enterprise edition allows you to utilize the built-in full-page caching mechanism, while the community edition does not include a full-page caching solution.