Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
UninstallCollectorTest.php
Go to the documentation of this file.
1 <?php
7 
9 
10 class UninstallCollectorTest extends \PHPUnit\Framework\TestCase
11 {
15  private $collector;
16 
20  private $adapterInterface;
21 
25  private $result;
26 
27  public function setUp()
28  {
29  $objectManagerProvider = $this->createMock(\Magento\Setup\Model\ObjectManagerProvider::class);
31  $this->getMockForAbstractClass(\Magento\Framework\ObjectManagerInterface::class, [], '', false);
32  $objectManagerProvider->expects($this->once())->method('get')->willReturn($objectManager);
33 
34  $setup = $this->createMock(\Magento\Setup\Module\DataSetup::class);
35  $this->adapterInterface = $this->getMockForAbstractClass(
36  \Magento\Framework\DB\Adapter\AdapterInterface::class,
37  [],
38  '',
39  false
40  );
41  $select = $this->createPartialMock(\Magento\Framework\DB\Select::class, ['from']);
42  $this->adapterInterface->expects($this->once())->method('select')->willReturn($select);
43  $setup->expects($this->exactly(2))->method('getConnection')->willReturn($this->adapterInterface);
44  $this->result = $this->createMock(\Magento\Framework\DB\Select::class);
45  $select->expects($this->once())->method('from')->willReturn($this->result);
46 
47  $uninstallA = 'Uninstall Class A';
48  $uninstallB = 'Uninstall Class B';
49  $objectManager->expects($this->any())
50  ->method('create')
51  ->will(
52  $this->returnValueMap([
53  ['Magento\A\Setup\Uninstall', [], $uninstallA],
54  ['Magento\B\Setup\Uninstall', [], $uninstallB],
55  ])
56  );
57  $setupFactory = $this->createMock(\Magento\Setup\Module\DataSetupFactory::class);
58  $setupFactory->expects($this->once())->method('create')->willReturn($setup);
59 
60  $this->collector = new UninstallCollector($objectManagerProvider, $setupFactory);
61  }
62 
63  public function testUninstallCollector()
64  {
65  $this->result->expects($this->never())->method('where');
66  $this->adapterInterface->expects($this->once())
67  ->method('fetchAll')
68  ->with($this->result)
69  ->willReturn([['module' => 'Magento_A'], ['module' => 'Magento_B'], ['module' => 'Magento_C']]);
70 
71  $this->assertEquals(
72  ['Magento_A' => 'Uninstall Class A', 'Magento_B' => 'Uninstall Class B'],
73  $this->collector->collectUninstall()
74  );
75  }
76 
78  {
79  $this->result->expects($this->once())->method('where')->willReturn($this->result);
80  $this->adapterInterface->expects($this->once())
81  ->method('fetchAll')
82  ->with($this->result)
83  ->willReturn([['module' => 'Magento_A']]);
84 
85  $this->assertEquals(['Magento_A' => 'Uninstall Class A'], $this->collector->collectUninstall(['Magento_A']));
86  }
87 }
88 
89 namespace Magento\Setup\Model;
90 
98 function is_subclass_of($obj, $className)
99 {
100  if ($obj == 'Uninstall Class A' && $className == \Magento\Framework\Setup\UninstallInterface::class) {
101  return true;
102  }
103  if ($obj == 'Uninstall Class B' && $className == \Magento\Framework\Setup\UninstallInterface::class) {
104  return true;
105  }
106  return false;
107 }
108 
116 {
117  if ($className == 'Magento\A\Setup\Uninstall' || $className == 'Magento\B\Setup\Uninstall') {
118  return true;
119  }
120  return false;
121 }
is_subclass_of($obj, $className)
$objectManager
Definition: bootstrap.php:17
$setup
Definition: trigger.php:12
if($currentSelectedMethod==$_code) $className
Definition: form.phtml:31