18. class ModelExample
{
protected $model;
public function __construct(
Model $model
) {
$this->model = $model;
}
}
$objectManager->create('FoomanDiExamplesModelModel');
behind the scenes:
19. class ModelExample
{
protected $model;
public function __construct(
Model $model
) {
$this->model = $model;
}
}
$objectManager->create('FoomanDiExamplesModelModel');
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
<type name="FoomanDiExamplesModelModel" shared="false" />
</config>
behind the scenes:
20. Executive Summary Dependency Injection
• Constructor based with Magento flavour
• di.xml
• Use Interfaces wherever possible
• Don’t use the ObjectManager directly
26. <?php
namespace FoomanPrintOrderPdfControllerAdminhtmlOrder;
/**
* @magentoAppArea adminhtml
*/
class PrintActionTest extends MagentoTestFrameworkTestCaseAbstractBackendController
{
public function setUp()
{
$this->resource = 'Magento_Sales::sales_order';
$this->uri = 'backend/fooman_printorderpdf/order/print';
parent::setUp();
}
}
27.
28. public function testAclHasAccess()
{
if ($this->uri === null) {
$this->markTestIncomplete('AclHasAccess test is not complete');
}
$this->dispatch($this->uri);
$this->assertNotSame(403, $this->getResponse()->getHttpResponseCode());
$this->assertNotSame(404, $this->getResponse()->getHttpResponseCode());
}
public function testAclNoAccess()
{
if ($this->resource === null) {
$this->markTestIncomplete('Acl test is not complete');
}
$this->_objectManager->get('MagentoFrameworkAclBuilder’)->getAcl()
->deny(null, $this->resource);
$this->dispatch($this->uri);
$this->assertSame(403, $this->getResponse()->getHttpResponseCode());
}
53. 1. Growing Up
Invest in yourself
2. Learning from Magento
Dependency Injection
Use and create your own Service Contracts
Leverage Test Frameworks
3. Learning with the Community
Composer + Semantic Versioning
PSR-X
Get involved