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
Clineを含めたAIエージェントを 大規模組織に導入し、投資対効果を考える / Introducing AI agents into your organization
i35_267
4
1.2k
新卒3年目の後悔〜機械学習モデルジョブの運用を頑張った話〜
kameitomohiro
0
360
初めてのAzure FunctionsをClaude Codeで作ってみた / My first Azure Functions using Claude Code
hideakiaoyagi
1
170
kubellが挑むBPaaSにおける、人とAIエージェントによるサービス開発の最前線と技術展望
kubell_hr
1
390
米国国防総省のDevSecOpsライフサイクルをAWSのセキュリティサービスとOSSで実現
syoshie
2
650
Agentic Workflowという選択肢を考える
tkikuchi1002
1
230
(非公式) AWS Summit Japan と 海浜幕張 の歩き方 2025年版
coosuke
PRO
1
320
Amazon Q Developer for GitHubとAmplify Hosting でサクッとデジタル名刺を作ってみた
kmiya84377
0
3.5k
Claude Code Actionを使ったコード品質改善の取り組み
potix2
PRO
1
190
比起獨自升級 我更喜歡 DevOps 文化 <3
line_developers_tw
PRO
0
1.1k
In Praise of "Normal" Engineers (LDX3)
charity
2
1.1k
OTFSG勉強会 / Introduction to the History of Delta Lake + Iceberg
databricksjapan
0
120
Featured
See All Featured
Practical Tips for Bootstrapping Information Extraction Pipelines
honnibal
PRO
20
1.3k
Mobile First: as difficult as doing things right
swwweet
223
9.7k
実際に使うSQLの書き方 徹底解説 / pgcon21j-tutorial
soudai
PRO
181
53k
How to Ace a Technical Interview
jacobian
276
23k
Into the Great Unknown - MozCon
thekraken
39
1.8k
Building Applications with DynamoDB
mza
95
6.5k
jQuery: Nuts, Bolts and Bling
dougneiner
63
7.8k
How to Create Impact in a Changing Tech Landscape [PerfNow 2023]
tammyeverts
52
2.8k
Helping Users Find Their Own Way: Creating Modern Search Experiences
danielanewman
29
2.7k
Building a Scalable Design System with Sketch
lauravandoore
462
33k
Faster Mobile Websites
deanohume
307
31k
Sharpening the Axe: The Primacy of Toolmaking
bcantrill
43
2.4k
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