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
320
Outside in BDD
jamescowie
1
72
Behaviour Driven Development
jamescowie
1
960
Other Decks in Technology
See All in Technology
web-application-security
matsuihidetoshi
1
200
認知症フレンドリーテックとスタックチャン
naokiuc
0
340
Cypress or Playwright?
rainerhahnekamp
0
180
Autonomous Database Cloud 技術詳細 / adb-s_technical_detail_jp
oracle4engineer
PRO
15
35k
DX企業CTOとして考える技術への向き合い方
shoheitai
0
100
今年のRubyKaigiはProfiler Year🤘
osyoyu
0
490
今さら聞けないDocker入門 〜 Dockerfileのベストプラクティス編
devops_vtj
21
6.1k
KubeConにproposalを送りたい人へのアドバイス
sat
PRO
3
280
止まらないLinuxシステムを構築する_高信頼性クラスタ入門
koedoyoshida
3
2.3k
Oracle Base Database Service 技術詳細
oracle4engineer
PRO
5
37k
同じ様なUIをiOS/Android間で合わせるヒントNo.2
fumiyasac0921
1
110
ゼロから始めるVue.jsコミュニティ貢献 / first-vuejs-community-contribution-link-and-motivation
lmi
1
150
Featured
See All Featured
KATA
mclloyd
16
12k
Code Review Best Practice
trishagee
56
15k
Being A Developer After 40
akosma
67
580k
Understanding Cognitive Biases in Performance Measurement
bluesmoon
12
1k
Refactoring Trust on Your Teams (GOTO; Chicago 2020)
rmw
26
2.3k
How to Ace a Technical Interview
jacobian
273
22k
Web development in the modern age
philhawksworth
203
10k
Fontdeck: Realign not Redesign
paulrobertlloyd
76
4.9k
Writing Fast Ruby
sferik
622
60k
Build your cross-platform service in a week with App Engine
jlugia
226
17k
Teambox: Starting and Learning
jrom
128
8.4k
Clear Off the Table
cherdarchuk
85
310k
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