Conditions | 1 |
Paths | 1 |
Total Lines | 60 |
Code Lines | 38 |
Lines | 0 |
Ratio | 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 |
||
23 | public function testProcessDom() |
||
24 | { |
||
25 | $doc = Mage::helper('eb2ccore')->getNewDomDocument(); |
||
26 | $doc->loadXML( |
||
27 | '<ItemMaster> |
||
28 | <Item operation_type="Add" gsi_client_id="MAGTNA" catalog_id="14"> |
||
29 | <ItemId> |
||
30 | <ClientItemId>14-77554</ClientItemId> |
||
31 | </ItemId> |
||
32 | <BaseAttributes> |
||
33 | <ItemDescription>Gift Wrap 1</ItemDescription> |
||
34 | <ItemType>GiftWrap</ItemType> |
||
35 | <TaxCode>78</TaxCode> |
||
36 | </BaseAttributes> |
||
37 | </Item> |
||
38 | </ItemMaster>' |
||
39 | ); |
||
40 | |||
41 | $feedData = array('event_type' => 'ItemMaster'); |
||
42 | $coreFeed = $this->getModelMockBuilder('ebayenterprise_catalog/feed_core') |
||
43 | ->disableOriginalConstructor() |
||
44 | ->setMethods(array('getFeedConfig')) |
||
45 | ->getMock(); |
||
46 | $coreFeed->expects($this->any()) |
||
47 | ->method('getFeedConfig') |
||
48 | ->will($this->returnValue($feedData)); |
||
49 | |||
50 | $observer = new Varien_Event_Observer(array('event' => new Varien_Event(array('doc' => $doc, 'file_detail' => array( |
||
51 | 'local_file' => 'EbayEnterprise/Product/ItemMaster/Inbound/ItemMaster_TestSubset.xml', |
||
52 | 'core_feed' => 'core feed mock', |
||
53 | 'timestamp' => '2012-07-06 10:09:05', |
||
54 | 'error_file' => '/EbayEnterprise/Eb2c/Feed/Product/ItemMaster/outbound/ItemMaster_20140107224605_12345_ABCD.xml', |
||
55 | 'core_feed' => $coreFeed |
||
56 | ))))); |
||
57 | $cfgData = array( |
||
58 | 'allowable_event_type' => 'ItemMaster', |
||
59 | ); |
||
60 | $config = $this->getModelMock('eb2cgiftwrap/feed_import_config', array('getImportConfigData')); |
||
61 | $config->expects($this->any()) |
||
62 | ->method('getImportConfigData') |
||
63 | ->will($this->returnValue($cfgData)); |
||
64 | $this->replaceByMock('model', 'eb2cgiftwrap/feed_import_config', $config); |
||
65 | |||
66 | $items = $this->getModelMock('eb2cgiftwrap/feed_import_items', array()); |
||
67 | $this->replaceByMock('model', 'eb2cgiftwrap/feed_import_items', $items); |
||
68 | |||
69 | $fileModelMock = $this->getModelMockBuilder('ebayenterprise_catalog/feed_file') |
||
70 | ->disableOriginalConstructor() |
||
71 | ->setMethods(array('process')) |
||
72 | ->getMock(); |
||
73 | $fileModelMock->expects($this->once()) |
||
74 | ->method('process') |
||
75 | ->with($this->identicalTo($config), $this->identicalTo($items)) |
||
76 | ->will($this->returnSelf()); |
||
77 | $this->replaceByMock('model', 'ebayenterprise_catalog/feed_file', $fileModelMock); |
||
78 | |||
79 | $observers = Mage::getModel('eb2cgiftwrap/observers'); |
||
80 | |||
81 | $this->assertSame($observers, $observers->processDom($observer)); |
||
82 | } |
||
83 | |||
146 |
This check looks for the generic type
array
as a return type and suggests a more specific type. This type is inferred from the actual code.