Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
SetupCacheTest.php
Go to the documentation of this file.
1 <?php
7 
9 
10 class SetupCacheTest extends \PHPUnit\Framework\TestCase
11 {
15  private $object;
16 
17  protected function setUp()
18  {
19  $this->object = new SetupCache();
20  }
21 
22  public function testSetRow()
23  {
24  $table = 'table';
25  $parentId = 'parent';
26  $rowId = 'row';
27  $data = new \stdClass();
28 
29  $this->object->setRow($table, $parentId, $rowId, $data);
30  $this->assertSame($data, $this->object->get($table, $parentId, $rowId));
31  }
32 
33  public function testSetField()
34  {
35  $table = 'table';
36  $parentId = 'parent';
37  $rowId = 'row';
38  $field = 'field';
39  $data = new \stdClass();
40 
41  $this->object->setField($table, $parentId, $rowId, $field, $data);
42  $this->assertSame($data, $this->object->get($table, $parentId, $rowId, $field));
43  }
44 
49  public function testGetNonexistent($field)
50  {
51  $this->assertFalse($this->object->get('table', 'parent', 'row', $field));
52  }
53 
57  public function getNonexistentDataProvider()
58  {
59  return [
60  [null],
61  ['field'],
62  ];
63  }
64 
65  public function testRemove()
66  {
67  $table = 'table';
68  $parentId = 'parent';
69  $rowId = 'row';
70  $data = new \stdClass();
71 
72  $this->object->setRow($table, $parentId, $rowId, $data);
73  $this->object->remove($table, $parentId, $rowId, $data);
74  $this->assertFalse($this->object->get($table, $parentId, $rowId));
75  }
76 
85  public function testHas($table, $parentId, $rowId, $field, $expected)
86  {
87  $this->object->setField('table', 'parent', 'row', 'field', 'data');
88  $this->assertSame($expected, $this->object->has($table, $parentId, $rowId, $field));
89  }
90 
94  public function hasDataProvider()
95  {
96  return [
97  'existing' => ['table', 'parent', 'row', 'field', true],
98  'nonexistent field' => ['table', 'parent', 'row', 'other_field', false],
99  'nonexistent row' => ['table', 'parent', 'other_row', 'field', false],
100  'nonexistent parent' => ['table', 'other_parent', 'row', 'field', false],
101  'nonexistent table' => ['other_table', 'parent', 'row', 'field', false],
102  ];
103  }
104 }
testHas($table, $parentId, $rowId, $field, $expected)
$table
Definition: trigger.php:14