Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
PayloadValidatorTest.php
Go to the documentation of this file.
1 <?php
8 
9 use \Magento\Setup\Model\PayloadValidator;
10 
11 class PayloadValidatorTest extends \PHPUnit\Framework\TestCase
12 {
16  private $fullModuleList;
17 
21  private $model;
22 
23  public function setUp()
24  {
25  $this->fullModuleList = $this->createMock(\Magento\Framework\Module\FullModuleList::class);
26  $this->model = new PayloadValidator($this->fullModuleList);
27  }
28 
35  public function testValidatePayLoad($type, $has, $moduleExists)
36  {
37  $this->fullModuleList->expects($this->exactly($has))->method('has')->willReturn($moduleExists);
38  $this->assertEquals('', $this->model->validatePayload($type));
39  }
40 
44  public function validatePayLoadDataProvider()
45  {
46  return [
47  [['type' => 'uninstall', 'dataOption' => true], 0, false],
48  [['type' => 'update', 'packages' => [['name' => 'vendor\/package', 'version' => '1.0.1']]], 0, false],
49  [['type' => 'enable', 'packages' => [['name' => 'vendor\/package', 'version' => '1.0.1']]], 1, true],
50  [['type' => 'disable', 'packages' => [['name' => 'vendor\/package', 'version' => '1.0.1']]], 1, true],
51  ];
52  }
53 
61  public function testValidatePayLoadNegativeCases($type, $has, $moduleExists, $errorMessage)
62  {
63  $this->fullModuleList->expects($this->exactly($has))->method('has')->willReturn($moduleExists);
64  $this->assertStringStartsWith($errorMessage, $this->model->validatePayload($type));
65  }
66 
71  {
72  return [
73  [['type' => 'uninstall'], 0, false, 'Missing dataOption'],
74  [['type' => 'update'], 0, false, 'Missing packages'],
75  [['type' => 'update',
76  'packages' => [['name' => 'vendor\/package']]],
77  0,
78  false,
79  'Missing package information'
80  ],
81  [['type' => 'enable'], 0, false, 'Missing packages'],
82  [['type' => 'enable',
83  'packages' => [['name' => 'vendor\/package']]],
84  1,
85  false,
86  'Invalid Magento module name'
87  ],
88  [['type' => 'disable',
89  'packages' => [['name' => 'vendor\/package']]],
90  1,
91  false,
92  'Invalid Magento module name'
93  ]
94  ];
95  }
96 }
testValidatePayLoadNegativeCases($type, $has, $moduleExists, $errorMessage)
$type
Definition: item.phtml:13