Conditions | 2 |
Paths | 2 |
Total Lines | 56 |
Code Lines | 28 |
Lines | 0 |
Ratio | 0 % |
Changes | 0 |
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
1 | <?php |
||
78 | public function testProcessUpdate() |
||
79 | { |
||
80 | $dom = new \DOMDocument(); |
||
81 | $manager = \Aimeos\MShop::create( $this->context, 'price' ); |
||
82 | $listManager = \Aimeos\MShop::create( $this->context, 'product/lists' ); |
||
83 | $product = \Aimeos\MShop::create( $this->context, 'product' )->create(); |
||
84 | |||
85 | $product->addListItem( 'price', |
||
86 | $listManager->create()->setType( 'default' )->setId( 1 ), |
||
87 | $manager->create()->setType( 'test' )->setCurrencyId( 'EUR' ) |
||
88 | ->setTaxrate( '20.00' )->setQuantity( 1 )->setValue( '10.00' ) |
||
89 | ); |
||
90 | $product->addListItem( 'price', |
||
91 | $listManager->create()->setType( 'test' )->setId( 2 ), |
||
92 | $manager->create()->setType( 'default' )->setCurrencyId( 'USD' ) |
||
93 | ->setTaxrate( '10.00' )->setQuantity( 2 )->setValue( '20.00' ) |
||
94 | ); |
||
95 | |||
96 | $dom->loadXML( '<?xml version="1.0" encoding="UTF-8" standalone="no" ?> |
||
97 | <price> |
||
98 | <priceitem lists.type="test"> |
||
99 | <price.type><![CDATA[default]]></price.type> |
||
100 | <price.currencyid><![CDATA[USD]]></price.currencyid> |
||
101 | <price.taxrate><![CDATA[10.00]]></price.taxrate> |
||
102 | <price.quantity><![CDATA[2]]></price.quantity> |
||
103 | <price.value><![CDATA[20.00]]></price.value> |
||
104 | </priceitem> |
||
105 | <priceitem lists.type="default"> |
||
106 | <price.type><![CDATA[test]]></price.type> |
||
107 | <price.currencyid><![CDATA[EUR]]></price.currencyid> |
||
108 | <price.taxrate><![CDATA[20.00]]></price.taxrate> |
||
109 | <price.quantity><![CDATA[1]]></price.quantity> |
||
110 | <price.value><![CDATA[10.00]]></price.value> |
||
111 | </priceitem> |
||
112 | </price>' ); |
||
113 | |||
114 | $product = $this->object->process( $product, $dom->firstChild ); |
||
115 | |||
116 | $pos = 0; |
||
117 | $expected = [ |
||
118 | ['test', 'default', '2', 'USD', '10.00', '20.00'], |
||
119 | ['default', 'test', '1', 'EUR', '20.00', '10.00'], |
||
120 | ]; |
||
121 | |||
122 | $listItems = $product->getListItems(); |
||
123 | $this->assertEquals( 2, count( $listItems ) ); |
||
124 | |||
125 | foreach( $listItems as $listItem ) |
||
126 | { |
||
127 | $this->assertEquals( $expected[$pos][0], $listItem->getType() ); |
||
128 | $this->assertEquals( $expected[$pos][1], $listItem->getRefItem()->getType() ); |
||
129 | $this->assertEquals( $expected[$pos][2], $listItem->getRefItem()->getQuantity() ); |
||
130 | $this->assertEquals( $expected[$pos][3], $listItem->getRefItem()->getCurrencyId() ); |
||
131 | $this->assertEquals( $expected[$pos][4], $listItem->getRefItem()->getTaxrate() ); |
||
132 | $this->assertEquals( $expected[$pos][5], $listItem->getRefItem()->getValue() ); |
||
133 | $pos++; |
||
134 | } |
||
187 |