| Conditions | 1 |
| Paths | 1 |
| Total Lines | 61 |
| Code Lines | 48 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 1 | ||
| Bugs | 0 | Features | 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 |
||
| 87 | public function testSaveUpdateDeleteItem() |
||
| 88 | { |
||
| 89 | $search = $this->object->filter()->slice( 0, 1 ) |
||
| 90 | ->add( ['rule.provider' => 'Percent,Category', 'rule.editor' => $this->editor] ); |
||
| 91 | |||
| 92 | $item = $this->object->search( $search ) |
||
| 93 | ->first( new \RuntimeException( sprintf( 'No rule item including "%1$s" found', 'Percent,Category' ) )); |
||
| 94 | |||
| 95 | $item->setId( null ); |
||
| 96 | $item->setProvider( 'Example1' ); |
||
| 97 | $resultSaved = $this->object->save( $item ); |
||
| 98 | $itemSaved = $this->object->get( $item->getId() ); |
||
| 99 | |||
| 100 | $itemExp = clone $itemSaved; |
||
| 101 | $itemExp->setProvider( 'Example' ); |
||
| 102 | $itemExp->setPosition( 5 ); |
||
| 103 | $itemExp->setStatus( -1 ); |
||
| 104 | $resultUpd = $this->object->save( $itemExp ); |
||
| 105 | $itemUpd = $this->object->get( $itemExp->getId() ); |
||
| 106 | |||
| 107 | $this->object->delete( $itemSaved->getId() ); |
||
| 108 | |||
| 109 | |||
| 110 | $this->assertTrue( $item->getId() !== null ); |
||
| 111 | $this->assertTrue( $itemSaved->getType() !== null ); |
||
| 112 | $this->assertEquals( $item->getId(), $itemSaved->getId() ); |
||
| 113 | $this->assertEquals( $item->getSiteId(), $itemSaved->getSiteId() ); |
||
| 114 | $this->assertEquals( $item->getProvider(), $itemSaved->getProvider() ); |
||
| 115 | $this->assertEquals( $item->getDateStart(), $itemSaved->getDateStart() ); |
||
| 116 | $this->assertEquals( $item->getDateEnd(), $itemSaved->getDateEnd() ); |
||
| 117 | $this->assertEquals( $item->getType(), $itemSaved->getType() ); |
||
| 118 | $this->assertEquals( $item->getLabel(), $itemSaved->getLabel() ); |
||
| 119 | $this->assertEquals( $item->getConfig(), $itemSaved->getConfig() ); |
||
| 120 | $this->assertEquals( $item->getPosition(), $itemSaved->getPosition() ); |
||
| 121 | $this->assertEquals( $item->getStatus(), $itemSaved->getStatus() ); |
||
| 122 | |||
| 123 | $this->assertEquals( $this->editor, $itemSaved->getEditor() ); |
||
| 124 | $this->assertRegExp( '/\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}/', $itemSaved->getTimeCreated() ); |
||
| 125 | $this->assertRegExp( '/\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}/', $itemSaved->getTimeModified() ); |
||
| 126 | |||
| 127 | $this->assertTrue( $itemUpd->getType() !== null ); |
||
| 128 | $this->assertEquals( $itemExp->getId(), $itemUpd->getId() ); |
||
| 129 | $this->assertEquals( $itemExp->getSiteId(), $itemUpd->getSiteId() ); |
||
| 130 | $this->assertEquals( $itemExp->getProvider(), $itemUpd->getProvider() ); |
||
| 131 | $this->assertEquals( $itemExp->getDateStart(), $itemUpd->getDateStart() ); |
||
| 132 | $this->assertEquals( $itemExp->getDateEnd(), $itemUpd->getDateEnd() ); |
||
| 133 | $this->assertEquals( $itemExp->getType(), $itemUpd->getType() ); |
||
| 134 | $this->assertEquals( $itemExp->getLabel(), $itemUpd->getLabel() ); |
||
| 135 | $this->assertEquals( $itemExp->getConfig(), $itemUpd->getConfig() ); |
||
| 136 | $this->assertEquals( $itemExp->getPosition(), $itemUpd->getPosition() ); |
||
| 137 | $this->assertEquals( $itemExp->getStatus(), $itemUpd->getStatus() ); |
||
| 138 | |||
| 139 | $this->assertEquals( $this->editor, $itemUpd->getEditor() ); |
||
| 140 | $this->assertEquals( $itemExp->getTimeCreated(), $itemUpd->getTimeCreated() ); |
||
| 141 | $this->assertRegExp( '/\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}/', $itemUpd->getTimeModified() ); |
||
| 142 | |||
| 143 | $this->assertInstanceOf( \Aimeos\MShop\Common\Item\Iface::class, $resultSaved ); |
||
| 144 | $this->assertInstanceOf( \Aimeos\MShop\Common\Item\Iface::class, $resultUpd ); |
||
| 145 | |||
| 146 | $this->expectException( \Aimeos\MShop\Exception::class ); |
||
| 147 | $this->object->get( $itemSaved->getId() ); |
||
| 148 | } |
||
| 204 |