| Conditions | 2 |
| Paths | 2 |
| Total Lines | 58 |
| Code Lines | 44 |
| 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 |
||
| 65 | public function testSaveUpdateDeleteItem() |
||
| 66 | { |
||
| 67 | $search = $this->object->filter()->slice( 0, 1 ); |
||
| 68 | |||
| 69 | if( ( $item = $this->object->search( $search )->first() ) === null ) { |
||
| 70 | throw new \RuntimeException( 'No item found' ); |
||
| 71 | } |
||
| 72 | |||
| 73 | $item->setId( null ); |
||
| 74 | $item->setDomain( 'unittest' ); |
||
| 75 | $resultSaved = $this->object->save( $item ); |
||
| 76 | $itemSaved = $this->object->get( $item->getId() ); |
||
| 77 | |||
| 78 | $itemExp = clone $itemSaved; |
||
| 79 | $itemExp->setDomain( 'unittest2' ); |
||
| 80 | $resultUpd = $this->object->save( $itemExp ); |
||
| 81 | $itemUpd = $this->object->get( $itemExp->getId() ); |
||
| 82 | |||
| 83 | $this->object->delete( $itemSaved->getId() ); |
||
| 84 | |||
| 85 | |||
| 86 | $this->assertTrue( $item->getId() !== null ); |
||
| 87 | $this->assertEquals( $item->getId(), $itemSaved->getId() ); |
||
| 88 | $this->assertEquals( $item->getSiteId(), $itemSaved->getSiteId() ); |
||
| 89 | $this->assertEquals( $item->getParentId(), $itemSaved->getParentId() ); |
||
| 90 | $this->assertEquals( $item->getType(), $itemSaved->getType() ); |
||
| 91 | $this->assertEquals( $item->getRefId(), $itemSaved->getRefId() ); |
||
| 92 | $this->assertEquals( $item->getDomain(), $itemSaved->getDomain() ); |
||
| 93 | $this->assertEquals( $item->getDateStart(), $itemSaved->getDateStart() ); |
||
| 94 | $this->assertEquals( $item->getDateEnd(), $itemSaved->getDateEnd() ); |
||
| 95 | $this->assertEquals( $item->getPosition(), $itemSaved->getPosition() ); |
||
| 96 | $this->assertEquals( $this->editor, $itemSaved->getEditor() ); |
||
| 97 | $this->assertStringStartsWith( date( 'Y-m-d', time() ), $itemSaved->getTimeCreated() ); |
||
| 98 | $this->assertStringStartsWith( date( 'Y-m-d', time() ), $itemSaved->getTimeModified() ); |
||
| 99 | |||
| 100 | $this->assertEquals( $this->editor, $itemSaved->getEditor() ); |
||
| 101 | $this->assertRegExp( '/\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}/', $itemSaved->getTimeCreated() ); |
||
| 102 | $this->assertRegExp( '/\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}/', $itemSaved->getTimeModified() ); |
||
| 103 | |||
| 104 | $this->assertEquals( $itemExp->getId(), $itemUpd->getId() ); |
||
| 105 | $this->assertEquals( $itemExp->getSiteId(), $itemUpd->getSiteId() ); |
||
| 106 | $this->assertEquals( $itemExp->getParentId(), $itemUpd->getParentId() ); |
||
| 107 | $this->assertEquals( $itemExp->getType(), $itemUpd->getType() ); |
||
| 108 | $this->assertEquals( $itemExp->getRefId(), $itemUpd->getRefId() ); |
||
| 109 | $this->assertEquals( $itemExp->getDomain(), $itemUpd->getDomain() ); |
||
| 110 | $this->assertEquals( $itemExp->getDateStart(), $itemUpd->getDateStart() ); |
||
| 111 | $this->assertEquals( $itemExp->getDateEnd(), $itemUpd->getDateEnd() ); |
||
| 112 | $this->assertEquals( $itemExp->getPosition(), $itemUpd->getPosition() ); |
||
| 113 | |||
| 114 | $this->assertEquals( $this->editor, $itemUpd->getEditor() ); |
||
| 115 | $this->assertEquals( $itemExp->getTimeCreated(), $itemUpd->getTimeCreated() ); |
||
| 116 | $this->assertRegExp( '/\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}/', $itemUpd->getTimeModified() ); |
||
| 117 | |||
| 118 | $this->assertInstanceOf( \Aimeos\MShop\Common\Item\Iface::class, $resultSaved ); |
||
| 119 | $this->assertInstanceOf( \Aimeos\MShop\Common\Item\Iface::class, $resultUpd ); |
||
| 120 | |||
| 121 | $this->expectException( '\\Aimeos\\MShop\\Exception' ); |
||
| 122 | $this->object->get( $itemSaved->getId() ); |
||
| 123 | } |
||
| 192 |