|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace SpeckCatalogTest\Mapper\TestAsset; |
|
4
|
|
|
|
|
5
|
|
|
use PHPUnit\Extensions\Database\TestCase; |
|
6
|
|
|
|
|
7
|
|
|
class AbstractTestCase extends \PHPUnit_Framework_TestCase |
|
8
|
|
|
{ |
|
9
|
|
|
protected $testMapper; |
|
10
|
|
|
|
|
11
|
|
|
public function getTestMapper() |
|
12
|
|
|
{ |
|
13
|
|
|
if (null === $this->testMapper) { |
|
14
|
|
|
$this->testMapper = $this->getServiceManager()->get('speckcatalog_test_mapper'); |
|
15
|
|
|
} |
|
16
|
|
|
return $this->testMapper; |
|
17
|
|
|
} |
|
18
|
|
|
|
|
19
|
|
|
public function getServiceManager() |
|
20
|
|
|
{ |
|
21
|
|
|
return \SpeckCatalogTest\Bootstrap::getServiceManager(); |
|
22
|
|
|
} |
|
23
|
|
|
|
|
24
|
|
|
public function insertProduct() |
|
25
|
|
|
{ |
|
26
|
|
|
$mapper = $this->getTestMapper(); |
|
27
|
|
|
$mapper->setEntityPrototype(new \SpeckCatalog\Model\Product); |
|
28
|
|
|
$product = array('name' => 'product'); |
|
29
|
|
|
$result = $mapper->insert($product, 'catalog_product'); |
|
30
|
|
|
return (int) $result->getGeneratedValue(); |
|
31
|
|
|
} |
|
32
|
|
|
|
|
33
|
|
|
public function insertOption() |
|
34
|
|
|
{ |
|
35
|
|
|
$mapper = $this->getTestMapper(); |
|
36
|
|
|
$mapper->setEntityPrototype(new \SpeckCatalog\Model\Option); |
|
37
|
|
|
$option = array('name' => 'option'); |
|
38
|
|
|
$result = $mapper->insert($option, 'catalog_option'); |
|
39
|
|
|
return (int) $result->getGeneratedValue(); |
|
40
|
|
|
} |
|
41
|
|
|
|
|
42
|
|
|
public function insertChoice($parentOptionId) |
|
43
|
|
|
{ |
|
44
|
|
|
$mapper = $this->getTestMapper(); |
|
45
|
|
|
$mapper->setEntityProtoType(new \SpeckCatalog\Model\Choice); |
|
46
|
|
|
$choice = array('option_id' => $parentOptionId); |
|
47
|
|
|
$result = $mapper->insert($choice, 'catalog_choice'); |
|
48
|
|
|
return (int) $result->getGeneratedValue(); |
|
49
|
|
|
} |
|
50
|
|
|
|
|
51
|
|
|
public function insertProductUom($productId, $uomCode, $quantity) |
|
52
|
|
|
{ |
|
53
|
|
|
$productUom = array( |
|
54
|
|
|
'product_id' => $productId, |
|
55
|
|
|
'uom_code' => $uomCode, |
|
56
|
|
|
'quantity' => $quantity, |
|
57
|
|
|
'price' => 1, |
|
58
|
|
|
'retail' => 1, |
|
59
|
|
|
); |
|
60
|
|
|
$mapper = $this->getTestMapper(); |
|
61
|
|
|
$mapper->insert($productUom, 'catalog_product_uom'); |
|
62
|
|
|
} |
|
63
|
|
|
|
|
64
|
|
|
public function insertAvailability($productId, $uomCode, $quantity, $distributorId) |
|
65
|
|
|
{ |
|
66
|
|
|
$availability = array( |
|
67
|
|
|
'product_id' => $productId, |
|
68
|
|
|
'uom_code' => $uomCode, |
|
69
|
|
|
'quantity' => $quantity, |
|
70
|
|
|
'distributor_id' => $distributorId, |
|
71
|
|
|
'cost' => 1, |
|
72
|
|
|
); |
|
73
|
|
|
$mapper = $this->getTestMapper(); |
|
74
|
|
|
$mapper->insert($availability, 'catalog_availability'); |
|
75
|
|
|
} |
|
76
|
|
|
|
|
77
|
|
|
public function insertImage($parentType, $parentId = 1) |
|
78
|
|
|
{ |
|
79
|
|
|
$mapper = $this->getTestMapper(); |
|
80
|
|
|
$idName = $parentType . '_id'; |
|
81
|
|
|
$image = array($idName => $parentId); |
|
82
|
|
|
$table = 'catalog_' . $parentType . '_image'; |
|
83
|
|
|
$result = $mapper->insert($image, $table); |
|
84
|
|
|
return (int) $result->getGeneratedValue(); |
|
85
|
|
|
} |
|
86
|
|
|
|
|
87
|
|
|
public function insertCategory() |
|
88
|
|
|
{ |
|
89
|
|
|
$category = array('name' => 'category'); |
|
90
|
|
|
$mapper = $this->getTestMapper(); |
|
91
|
|
|
$result = $mapper->insert($category, 'catalog_category'); |
|
92
|
|
|
return (int) $result->getGeneratedValue(); |
|
93
|
|
|
} |
|
94
|
|
|
|
|
95
|
|
|
public function insertDocument($parentProductId = 1) |
|
96
|
|
|
{ |
|
97
|
|
|
$document = array('product_id' => $parentProductId); |
|
98
|
|
|
$mapper = $this->getTestMapper(); |
|
99
|
|
|
$result = $mapper->insert($document, 'catalog_product_document'); |
|
100
|
|
|
return (int) $result->getGeneratedValue(); |
|
101
|
|
|
} |
|
102
|
|
|
|
|
103
|
|
|
public function insertSpec($parentProductId = 1) |
|
104
|
|
|
{ |
|
105
|
|
|
$spec = array('product_id' => $parentProductId); |
|
106
|
|
|
$mapper = $this->getTestMapper(); |
|
107
|
|
|
$result = $mapper->insert($spec, 'catalog_product_spec'); |
|
108
|
|
|
return (int) $result->getGeneratedValue(); |
|
109
|
|
|
} |
|
110
|
|
|
|
|
111
|
|
|
public function insertUom($uomCode, $name) |
|
112
|
|
|
{ |
|
113
|
|
|
$uom = array('uom_code' => $uomCode, 'name' => $name); |
|
114
|
|
|
$mapper = $this->getTestMapper(); |
|
115
|
|
|
$result = $mapper->insert($uom, 'ansi_uom'); |
|
|
|
|
|
|
116
|
|
|
} |
|
117
|
|
|
|
|
118
|
|
|
public function setup() |
|
119
|
|
|
{ |
|
120
|
|
|
$this->getTestMapper()->setup(); |
|
121
|
|
|
} |
|
122
|
|
|
|
|
123
|
|
|
public function teardown() |
|
124
|
|
|
{ |
|
125
|
|
|
$this->getTestMapper()->teardown(); |
|
126
|
|
|
} |
|
127
|
|
|
} |
|
128
|
|
|
|
This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.
Both the
$myVarassignment in line 1 and the$higherassignment in line 2 are dead. The first because$myVaris never used and the second because$higheris always overwritten for every possible time line.