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