Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
Whats new in Magento 2
Search
James Cowie
September 17, 2015
Technology
0
110
Whats new in Magento 2
An overview of what has changed since Magento 1 and what to expect as a developer
James Cowie
September 17, 2015
Tweet
Share
More Decks by James Cowie
See All by James Cowie
Learn to love testing an agile journey into Behat, PHPSpec and Magento
jamescowie
0
340
Outside in BDD
jamescowie
1
75
Behaviour Driven Development
jamescowie
1
970
Other Decks in Technology
See All in Technology
アカデミーキャンプ 2025 SuuuuuuMMeR「燃えろ!!ロボコン」 / Academy Camp 2025 SuuuuuuMMeR "Burn the Spirit, Robocon!!" DAY 1
ks91
PRO
0
150
Cloud WANの基礎から応用~少しだけDeep Dive~
masakiokuda
3
120
Intro to Software Startups: Spring 2025
arnabdotorg
0
280
LLM 機能を支える Langfuse / ClickHouse のサーバレス化
yuu26
9
2.6k
LTに影響を受けてテンプレリポジトリを作った話
hol1kgmg
0
380
ABEMAにおける 生成AI活用の現在地 / The Current Status of Generative AI at ABEMA
dekatotoro
0
250
モノレポにおけるエラー管理 ~Runbook自動生成とチームメンションの最適化
biwashi
0
370
意志の力が9割。アニメから学ぶAI時代のこれから。
endohizumi
1
110
AIと描く、未来のBacklog 〜プロジェクト管理の次の10年を想像し、創造するセッション〜
hrm_o25
0
110
UDDのススメ - 拡張版 -
maguroalternative
1
620
Kiro と Q Dev で 同じゲームを作らせてみた
r3_yamauchi
PRO
1
120
JAWS-UG のイベントで使うハンズオンシナリオを Amazon Q Developer for CLI で作ってみた話
kazzpapa3
0
120
Featured
See All Featured
What’s in a name? Adding method to the madness
productmarketing
PRO
23
3.6k
Agile that works and the tools we love
rasmusluckow
329
21k
Practical Tips for Bootstrapping Information Extraction Pipelines
honnibal
PRO
23
1.4k
Building an army of robots
kneath
306
45k
GraphQLとの向き合い方2022年版
quramy
49
14k
RailsConf & Balkan Ruby 2019: The Past, Present, and Future of Rails at GitHub
eileencodes
139
34k
How To Stay Up To Date on Web Technology
chriscoyier
790
250k
Helping Users Find Their Own Way: Creating Modern Search Experiences
danielanewman
29
2.8k
The MySQL Ecosystem @ GitHub 2015
samlambert
251
13k
How to Think Like a Performance Engineer
csswizardry
25
1.8k
I Don’t Have Time: Getting Over the Fear to Launch Your Podcast
jcasabona
33
2.4k
How to Ace a Technical Interview
jacobian
279
23k
Transcript
1 Whats New in magento 2
2 James Cowie Software Engineer Session Digital @Jcowie
3 What to expect as a developer
4 Whats changed Since Magento 1
5
6 2012 2009 2012 2009 2013 Composer namespaces. traits generators.
type hinting
7 The world of engineering has changed
8 • Server Architecture • TDD • BDD • DDD
Cloud Docker VPS PHPSpec - 2011 Behat - 2011
9 installing Magento break time
None
11
12 composer create-project --stability=beta --no-install magento/project-community-edition M2Test
{ "name": "magento/project-community-edition", "type": "project", "require": { "magento/product-community-edition": "0.74.0-beta12" },
"require-dev": { } }
14 composer can do much more
15 • Packagist + packages.magento.com • Package versioning • Dependency
Management
composer require "league/period"
1 /** 2 * @var League\Period\Period; 3 */ 4 protected
$_datePeriod; 5 6 /** 7 * @param \League\Period\Period; $datePeriod 8 */ 9 public function __construct(\League\Period\Period $datePeriod) 10 { 11 $this->_datePeriod = $datePeriod; 12 }
18 Versioning In Composer
19 Exact version: “1.4.2″, “v1.4.2″. "magento/product-community-edition": “1.0.1”
20 Ranges: >=1.0, <2.0, "magento/product-community-edition": “>=1.0, <2”
21 Wildcard: “1.0.*”, “1.*” "magento/product-community-edition": “1.*” "magento/product-community-edition": “1.0.*”
22 Next Significant Release: “~1.2″ is equivalent to “>=1.2,<2.0″. "magento/product-community-edition":
“~1.2”
None
24 Decoupling modules
None
26 •Clean Code •Reusable packages •Testable •Easier to read •Easier
to maintain
27 • No Dependency Injection container. • Mage god class
• Hard to test • Hard to decouple logic
28 Dependency Injection in Magento 2
None
public function __construct( \Magento\Framework\App\Action\Context $context, \Magento\Catalog\Model\Design $catalogDesign, \Magento\Catalog\Model\Session $catalogSession, \Magento\Framework\Registry
$coreRegistry, \Magento\Store\Model\StoreManagerInterface $storeManager, \Magento\CatalogUrlRewrite\Model\CategoryUrlPathGenerator $categoryUrlPathGenerator, PageFactory $resultPageFactory, \Magento\Framework\Controller\Result\ForwardFactory $resultForwardFactory, Resolver $layerResolver, CategoryRepositoryInterface $categoryRepository \Magento\Framework\App\Action\Context $context, \Magento\Catalog\Model\Design $catalogDesign, \Magento\Catalog\Model\Session $catalogSession, \Magento\Framework\Registry $coreRegistry, \Magento\Store\Model\StoreManagerInterface $storeManager, \Magento\CatalogUrlRewrite\Model\CategoryUrlPathGenerator
public function __construct( \Magento\Framework\App\Action\Context $context, \Magento\Catalog\Model\Design $catalogDesign, \Magento\Catalog\Model\Session $catalogSession, \Magento\Framework\Registry
$coreRegistry, \Magento\Store\Model\StoreManagerInterface $storeManager, \Magento\CatalogUrlRewrite\Model\CategoryUrlPathGenerator $categoryUrlPathGenerator, PageFactory $resultPageFactory, \Magento\Framework\Controller\Result\ForwardFactory $resultForwardFactory, Resolver $layerResolver, CategoryRepositoryInterface $categoryRepository \Magento\Framework\App\Action\Context $context, \Magento\Catalog\Model\Design $catalogDesign, \Magento\Catalog\Model\Session $catalogSession, \Magento\Framework\Registry $coreRegistry, \Magento\Store\Model\StoreManagerInterface $storeManager, \Magento\CatalogUrlRewrite\Model\CategoryUrlPathGenerator Code Smell
32 • replaces Mage:: god class • Dependency Injection can
be overused. • enables composition.
1 <?php 2 class Sample 3 { 4 protected $logger;
5 6 public function doSomething() 7 { 8 $this->logger = new \Logger(); 9 $logger->doSomething(); 10 } 11 }
1 <?php 2 class Sample 3 { 4 protected $logger;
5 6 public function doSomething() 7 { 8 $this->logger = new \Logger(); 9 $logger->doSomething(); 10 } 11 }
1 <?php 2 class SampleDi { 3 protected $logger; 4
public function __construct(\Logger $logger) { 5 $this->logger = $logger; 6 } 7 8 public function doSomething() { 9 $this->logger->doSomething(); 10 } 11 }
1 <?php 2 class SampleDi { 3 protected $logger; 4
public function __construct(\Logger $logger) { 5 $this->logger = $logger; 6 } 7 8 public function doSomething() { 9 $this->logger->doSomething(); 10 } 11 }
1 <?php 2 class SampleDi { 3 protected $logger; 4
public function __construct(\Logger $logger) { 5 $this->logger = $logger; 6 } 7 8 public function doSomething() { 9 $this->logger->doSomething(); 10 } 11 }
38 • Responsibility • swap concrete implementation • Mock the
dependency
39 Back to Magento 2
/** * @param \Magento\Framework\View\Element\Context $conte */ public function __construct( \Magento\Framework\View\Element\Context
$context ) { parent::__construct($context, $data); }
41 Its not only Objects that can be injected.
<type name="Magento\Cms\Model\Wysiwyg\Images\Storage"> <arguments> <argument name="extensions" xsi:type="array"> <item name="allowed" xsi:type="array"> <item
name="jpg" xsi:type="number">1</item> <item name="jpeg" xsi:type="number">1</item> <item name="png" xsi:type="number">1</item> <item name="gif" xsi:type="number">1</item> </item> </argument> </arguments> …
<type name="Magento\Cms\Model\Wysiwyg\Images\Storage"> <arguments> <argument name="extensions" xsi:type="array"> <item name="allowed" xsi:type="array"> <item
name="jpg" xsi:type="number">1</item> <item name="jpeg" xsi:type="number">1</item> <item name="png" xsi:type="number">1</item> <item name="gif" xsi:type="number">1</item> </item> </argument> </arguments> …
<type name="Magento\Cms\Model\Wysiwyg\Images\Storage"> <arguments> <argument name="extensions" xsi:type="array"> <item name="allowed" xsi:type="array"> <item
name="jpg" xsi:type="number">1</item> <item name="jpeg" xsi:type="number">1</item> <item name="png" xsi:type="number">1</item> <item name="gif" xsi:type="number">1</item> </item> </argument> </arguments> …
<type name="Magento\Cms\Model\Wysiwyg\Images\Storage"> <arguments> <argument name="extensions" xsi:type="array"> <item name="allowed" xsi:type="array"> <item
name="jpg" xsi:type="number">1</item> <item name="jpeg" xsi:type="number">1</item> <item name="png" xsi:type="number">1</item> <item name="gif" xsi:type="number">1</item> </item> </argument> </arguments> …
protected $_extensions; public function __construct( array $extensions = [] )
{ $this->_extensions = $extensions; }
$allowed = $this->_extensions["{$type}_allowed"];
48 • Separating instantiation of objects from the object •
Easier to test • Aids with Separation of concerns
49 Testing
None
None
function it_should_create_a_new_cached_image($filesystem) { $filesystem->beADoubleOf( \Magento\Framework\Filesystem $fileSystem); $this->createCachedFile($filesystem) ->shouldReturnTrue(); }
53 • Composer can help create reusable packages • Dependency
Injection is a must, • Yet be careful on how many dependencies are injected • Testing has become easier • Decoupling of modules is now easier • Magento 2 service contracts / Design by contract ( Interfaces )
54 special thanks
55