Conditions | 2 |
Paths | 2 |
Total Lines | 54 |
Code Lines | 40 |
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 |
||
51 | public function testSaveUpdateDeleteItem() |
||
52 | { |
||
53 | $search = $this->object->createSearch(); |
||
54 | $search->setConditions( $search->compare( '==', 'price.property.editor', $this->editor ) ); |
||
55 | $results = $this->object->searchItems( $search ); |
||
56 | |||
57 | if( ( $item = reset($results) ) === false ) { |
||
58 | throw new \RuntimeException( 'No property item found' ); |
||
59 | } |
||
60 | |||
61 | $item->setId(null); |
||
62 | $item->setLanguageId( 'en' ); |
||
63 | $resultSaved = $this->object->saveItem( $item ); |
||
64 | $itemSaved = $this->object->getItem( $item->getId() ); |
||
65 | |||
66 | $itemExp = clone $itemSaved; |
||
67 | $itemExp->setValue( 'unittest' ); |
||
68 | $resultUpd = $this->object->saveItem( $itemExp ); |
||
69 | $itemUpd = $this->object->getItem( $itemExp->getId() ); |
||
70 | |||
71 | $this->object->deleteItem( $itemSaved->getId() ); |
||
72 | |||
73 | $context = \TestHelperMShop::getContext(); |
||
74 | |||
75 | $this->assertTrue( $item->getId() !== null ); |
||
76 | $this->assertTrue( $itemSaved->getType() !== null ); |
||
77 | $this->assertEquals( $item->getId(), $itemSaved->getId() ); |
||
78 | $this->assertEquals( $item->getParentId(), $itemSaved->getParentId() ); |
||
79 | $this->assertEquals( $item->getSiteId(), $itemSaved->getSiteId() ); |
||
80 | $this->assertEquals( $item->getType(), $itemSaved->getType() ); |
||
81 | $this->assertEquals( $item->getLanguageId(), $itemSaved->getLanguageId() ); |
||
82 | $this->assertEquals( $item->getValue(), $itemSaved->getValue() ); |
||
83 | |||
84 | $this->assertEquals( $context->getEditor(), $itemSaved->getEditor() ); |
||
85 | $this->assertRegExp( '/\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}/', $itemSaved->getTimeCreated() ); |
||
86 | $this->assertRegExp( '/\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}/', $itemSaved->getTimeModified() ); |
||
87 | |||
88 | $this->assertTrue( $itemUpd->getType() !== null ); |
||
89 | $this->assertEquals( $itemExp->getId(), $itemUpd->getId() ); |
||
90 | $this->assertEquals( $itemExp->getParentId(), $itemUpd->getParentId() ); |
||
91 | $this->assertEquals( $itemExp->getSiteId(), $itemUpd->getSiteId() ); |
||
92 | $this->assertEquals( $itemExp->getType(), $itemUpd->getType() ); |
||
93 | $this->assertEquals( $itemExp->getLanguageId(), $itemUpd->getLanguageId() ); |
||
94 | $this->assertEquals( $itemExp->getValue(), $itemUpd->getValue() ); |
||
95 | |||
96 | $this->assertEquals( $context->getEditor(), $itemUpd->getEditor() ); |
||
97 | $this->assertEquals( $itemExp->getTimeCreated(), $itemUpd->getTimeCreated() ); |
||
98 | $this->assertRegExp( '/\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}/', $itemUpd->getTimeModified() ); |
||
99 | |||
100 | $this->assertInstanceOf( \Aimeos\MShop\Common\Item\Iface::class, $resultSaved ); |
||
101 | $this->assertInstanceOf( \Aimeos\MShop\Common\Item\Iface::class, $resultUpd ); |
||
102 | |||
103 | $this->setExpectedException( \Aimeos\MShop\Exception::class ); |
||
104 | $this->object->getItem( $itemSaved->getId() ); |
||
105 | } |
||
179 |