1 | <?php |
||
7 | class ProductTest extends \PHPUnit_Framework_TestCase |
||
8 | { |
||
9 | public function testFind() |
||
10 | { |
||
11 | $product = new \SpeckCatalog\Model\Product; |
||
12 | |||
13 | $service = $this->getMock('\SpeckCatalog\Service\Product', array('populate')); |
||
14 | $service->expects($this->atLeastOnce()) |
||
15 | ->method('populate') |
||
16 | ->with($product) |
||
17 | ->will($this->returnValue($product)); |
||
18 | $mockMapper = $this->getMock('\SpeckCatalog\Mapper\Product'); |
||
19 | $mockMapper->expects($this->once()) |
||
20 | ->method('find') |
||
21 | ->with(array('product_id' => 321)) |
||
22 | ->will($this->returnValue($product)); |
||
23 | $service->setEntityMapper($mockMapper); |
||
24 | |||
25 | $return = $service->find(array('product_id' => 321), true); |
||
26 | $this->assertInstanceOf('\SpeckCatalog\Model\Product', $return); |
||
27 | } |
||
28 | |||
29 | public function testGetFullProduct() |
||
30 | { |
||
31 | $product = new \SpeckCatalog\Model\Product; |
||
32 | |||
33 | $service = $this->getMock('\SpeckCatalog\Service\Product', array('find', 'populate')); |
||
34 | $service->expects($this->once()) |
||
35 | ->method('populate') |
||
36 | ->with($product) |
||
37 | ->will($this->returnValue($product)); |
||
38 | $service->expects($this->once()) |
||
39 | ->method('find') |
||
40 | ->with(array('product_id' => 4321)) |
||
41 | ->will($this->returnValue($product)); |
||
42 | |||
43 | $return = $service->getFullProduct(4321); |
||
44 | $this->assertInstanceOf('\SpeckCatalog\Model\Product', $return); |
||
45 | } |
||
46 | |||
47 | public function testUpdateGetsValuesFromDataForOriginalValsFromArray() |
||
48 | { |
||
49 | $data = array('product_id' => 1); |
||
50 | $mockMapper = $this->getMock('\SpeckCatalog\Mapper\AbstractMapper'); |
||
51 | $mockMapper->expects($this->once()) |
||
52 | ->method('update') |
||
53 | ->with($data, $data); |
||
54 | $service = $this->getService(); |
||
55 | $service->setEntityMapper($mockMapper); |
||
56 | $service->update($data, null); |
||
57 | } |
||
58 | |||
59 | public function testUpdateGetsValuesFromDataForOriginalValsFromProduct() |
||
60 | { |
||
61 | $data = array('product_id' => 97); |
||
62 | $product = new \SpeckCatalog\Model\Product(); |
||
63 | $product->setProductId(97); |
||
64 | $mockMapper = $this->getMock('\SpeckCatalog\Mapper\AbstractMapper'); |
||
65 | $mockMapper->expects($this->once()) |
||
66 | ->method('update') |
||
67 | ->with($product, $data); |
||
68 | $service = $this->getService(); |
||
69 | $service->setEntityMapper($mockMapper); |
||
70 | $service->update($product, null); |
||
71 | } |
||
72 | |||
73 | public function getService() |
||
77 | |||
78 | public function testPopulatePopulatesProduct() |
||
79 | { |
||
80 | $this->markTestIncomplete('Tests was broken/obsoleted'); |
||
81 | $service = $this->getService(); |
||
82 | |||
83 | $optionService = $this->getMock('\SpeckCatalog\Service\Option'); |
||
84 | $optionService->expects($this->once()) |
||
85 | ->method('getByProductId') |
||
86 | ->will($this->returnValue(array(new \SpeckCatalog\Model\Option\Relational))); |
||
87 | $service->setOptionService($optionService); |
||
88 | |||
89 | $imageService = $this->getMock('\SpeckCatalog\Service\Image'); |
||
90 | $imageService->expects($this->once()) |
||
91 | ->method('getImages') |
||
92 | ->will($this->returnValue(array(new \SpeckCatalog\Model\ProductImage\Relational))); |
||
93 | $service->setImageService($imageService); |
||
94 | |||
95 | $documentService = $this->getMock('\SpeckCatalog\Service\Document'); |
||
96 | $documentService->expects($this->once()) |
||
97 | ->method('getDocuments') |
||
98 | ->will($this->returnValue(array(new \SpeckCatalog\Model\Document\Relational))); |
||
99 | $service->setDocumentService($documentService); |
||
100 | |||
101 | $productUomService = $this->getMock('\SpeckCatalog\Service\ProductUom'); |
||
102 | $productUomService->expects($this->once()) |
||
103 | ->method('getByProductId') |
||
104 | ->will($this->returnValue(array(new \SpeckCatalog\Model\ProductUom\Relational))); |
||
105 | $service->setProductUomService($productUomService); |
||
106 | |||
107 | $specService = $this->getMock('\SpeckCatalog\Service\Spec'); |
||
108 | $specService->expects($this->once()) |
||
109 | ->method('getByProductId') |
||
110 | ->will($this->returnValue(array(new \SpeckCatalog\Model\Spec\Relational))); |
||
111 | $service->setSpecService($specService); |
||
112 | |||
113 | $companyService = $this->getMock('\SpeckCatalog\Service\Company'); |
||
114 | $companyService->expects($this->once()) |
||
115 | ->method('findById') |
||
116 | ->will($this->returnValue(new \SpeckCatalog\Model\Company\Relational)); |
||
117 | $service->setCompanyService($companyService); |
||
118 | |||
119 | $product = new \SpeckCatalog\Model\Product\Relational; |
||
120 | $product->setProductId('111'); |
||
121 | $service->populate($product); |
||
122 | |||
123 | $options = $product->getOptions(); |
||
124 | $this->assertTrue(is_array($options)); |
||
125 | $this->assertTrue(count($options) === 1); |
||
126 | |||
127 | $images = $product->getImages(); |
||
128 | $this->assertTrue(is_array($images)); |
||
129 | $this->assertTrue(count($images) === 1); |
||
130 | |||
131 | $documents = $product->getDocuments(); |
||
132 | $this->assertTrue(is_array($documents)); |
||
133 | $this->assertTrue(count($documents) === 1); |
||
134 | |||
135 | $uoms = $product->getUoms(); |
||
136 | $this->assertTrue(is_array($uoms)); |
||
137 | $this->assertTrue(count($uoms) === 1); |
||
138 | |||
139 | $specs = $product->getSpecs(); |
||
140 | $this->assertTrue(is_array($specs)); |
||
141 | $this->assertTrue(count($specs) === 1); |
||
142 | |||
143 | $manufacturer = $product->getManufacturer(); |
||
144 | $this->assertInstanceOf('\SpeckCatalog\Model\Company', $manufacturer); |
||
145 | } |
||
146 | |||
147 | public function testAddOptionWithModelsCallsAddOptionAndReturnsOption() |
||
148 | { |
||
149 | $mockMapper = $this->getMock('\SpeckCatalog\Mapper\Product'); |
||
150 | $mockMapper->expects($this->once()) |
||
151 | ->method('addOption') |
||
152 | ->with(1, 2); |
||
153 | $mockOptionService = $this->getMock('\SpeckCatalog\Service\Option'); |
||
154 | $mockOptionService->expects($this->once()) |
||
155 | ->method('find') |
||
156 | ->with(array('option_id' => 2)) |
||
157 | ->will($this->returnValue(new \SpeckCatalog\Model\Option)); |
||
158 | |||
159 | $service = $this->getService(); |
||
160 | $service->setEntityMapper($mockMapper); |
||
161 | $service->setOptionService($mockOptionService); |
||
162 | |||
163 | $return = $service->addOption(1, 2); |
||
164 | $this->assertInstanceOf('\SpeckCatalog\Model\Option', $return); |
||
165 | } |
||
166 | |||
167 | |||
168 | public function testAddOptionWithIdsCallsAddOptionAndReturnsOption() |
||
169 | { |
||
170 | $mockMapper = $this->getMock('\SpeckCatalog\Mapper\Product'); |
||
171 | $mockMapper->expects($this->once()) |
||
172 | ->method('addOption') |
||
173 | ->with(1, 2); |
||
174 | $mockOptionService = $this->getMock('\SpeckCatalog\Service\Option'); |
||
175 | $mockOptionService->expects($this->once()) |
||
176 | ->method('find') |
||
177 | ->with(array('option_id' => 2)) |
||
178 | ->will($this->returnValue(new \SpeckCatalog\Model\Option)); |
||
179 | |||
180 | $service = $this->getService(); |
||
181 | $service->setEntityMapper($mockMapper); |
||
182 | $service->setOptionService($mockOptionService); |
||
183 | |||
184 | $product = new \SpeckCatalog\Model\Product(); |
||
185 | $product->setProductId(1); |
||
186 | $option = new \SpeckCatalog\Model\Option(); |
||
187 | $option->setOptionId(2); |
||
188 | $return = $service->addOption($product, $option); |
||
189 | $this->assertInstanceOf('\SpeckCatalog\Model\Option', $return); |
||
190 | } |
||
191 | |||
192 | public function testSortOptionsCallsSortOptionsOnMapper() |
||
193 | { |
||
194 | $mockMapper = $this->getMock('\SpeckCatalog\Mapper\Product'); |
||
195 | $mockMapper->expects($this->once()) |
||
196 | ->method('sortOptions') |
||
197 | ->with(1, array(1,2)); |
||
198 | $service = $this->getService(); |
||
199 | $service->setEntityMapper($mockMapper); |
||
200 | $service->sortOptions(1, array(1,2)); |
||
201 | } |
||
202 | |||
203 | public function testRemoveOptionCallsRemoveOptionOnMapper() |
||
204 | { |
||
205 | $mockMapper = $this->getMock('\SpeckCatalog\Mapper\Product'); |
||
206 | $mockMapper->expects($this->once()) |
||
207 | ->method('removeOption') |
||
208 | ->with(1, 2); |
||
209 | $service = $this->getService(); |
||
210 | $service->setEntityMapper($mockMapper); |
||
211 | $service->removeOption(array('product_id' => 1), array('option_id' => 2)); |
||
212 | } |
||
213 | |||
214 | public function testInsertCallsInsertAndReturnsNewProduct() |
||
215 | { |
||
216 | $product = new \SpeckCatalog\Model\Product; |
||
217 | $mockMapper = $this->getMock('\SpeckCatalog\Mapper\Product'); |
||
218 | $mockMapper->expects($this->once()) |
||
219 | ->method('insert') |
||
220 | ->with($product) |
||
221 | ->will($this->returnValue(1)); |
||
222 | $mockMapper->expects($this->once()) |
||
223 | ->method('find') |
||
224 | ->will($this->returnValue(new \SpeckCatalog\Model\Product)); |
||
225 | |||
226 | $service = $this->getService(); |
||
227 | $service->setEntityMapper($mockMapper); |
||
228 | $return = $service->insert($product); |
||
229 | $this->assertInstanceOf('\SpeckCatalog\Model\Product', $return); |
||
230 | } |
||
231 | |||
232 | public function testGetByCategoryIdSetsPaginatorAndCallsGetByCategoryIdOnMapper() |
||
233 | { |
||
234 | $mockMapper = $this->getMock('\SpeckCatalog\Mapper\Product'); |
||
235 | $mockMapper->expects($this->once()) |
||
236 | ->method('usePaginator'); |
||
237 | $mockMapper->expects($this->once()) |
||
238 | ->method('getByCategoryId') |
||
239 | ->with(1); |
||
240 | |||
241 | $service = $this->getService(); |
||
242 | $service->setEntityMapper($mockMapper); |
||
243 | $return = $service->getByCategoryId(1); |
||
|
|||
244 | } |
||
245 | |||
246 | public function testPopulateForPricingPopulatesRecursiveOptionsAndProductUoms() |
||
250 | |||
251 | public function testGetOptionService() |
||
252 | { |
||
253 | $service = $this->getService(); |
||
254 | $service->setOptionService($this->getMock('\SpeckCatalog\Service\Option')); |
||
255 | $return = $service->getOptionService(); |
||
256 | $this->assertInstanceOf('\SpeckCatalog\Service\Option', $return); |
||
257 | } |
||
258 | |||
259 | public function testGetOptionServiceGetsOptionServiceFromServiceManager() |
||
260 | { |
||
261 | $service = $this->getService(); |
||
262 | $mockServiceManager = $this->getMock('\Zend\ServiceManager\ServiceManager'); |
||
271 | |||
272 | public function testGetProductUomService() |
||
279 | |||
280 | public function testGetProductUomServiceGetsProductUomServiceFromServiceManager() |
||
292 | |||
293 | public function testGetImageService() |
||
300 | |||
301 | public function testGetImageServiceGetsImageServiceFromServiceManager() |
||
313 | |||
314 | public function testGetDocumentService() |
||
321 | |||
322 | public function testGetDocumentServiceGetsImageServiceFromServiceManager() |
||
334 | |||
335 | public function testGetSpecService() |
||
342 | |||
343 | public function testGetSpecServiceGetsImageServiceFromServiceManager() |
||
355 | |||
356 | public function testGetCompanyService() |
||
363 | |||
364 | public function testGetCompanyServiceGetsImageServiceFromServiceManager() |
||
376 | } |
||
377 |
This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.
Both the
$myVar
assignment in line 1 and the$higher
assignment in line 2 are dead. The first because$myVar
is never used and the second because$higher
is always overwritten for every possible time line.