Conditions | 2 |
Paths | 2 |
Total Lines | 59 |
Code Lines | 45 |
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 |
||
75 | public function testSaveUpdateDeleteItem() |
||
76 | { |
||
77 | $search = $this->object->createSearch(); |
||
78 | $search->setSlice( 0, 1 ); |
||
79 | |||
80 | if( ( $item = $this->object->searchItems( $search )->first() ) === null ) { |
||
81 | throw new \RuntimeException( 'No item found' ); |
||
82 | } |
||
83 | |||
84 | $item->setId( null ); |
||
85 | $item->setDomain( 'unittest' ); |
||
86 | $resultSaved = $this->object->saveItem( $item ); |
||
87 | $itemSaved = $this->object->getItem( $item->getId() ); |
||
88 | |||
89 | $itemExp = clone $itemSaved; |
||
90 | $itemExp->setDomain( 'unittest2' ); |
||
91 | $resultUpd = $this->object->saveItem( $itemExp ); |
||
92 | $itemUpd = $this->object->getItem( $itemExp->getId() ); |
||
93 | |||
94 | $this->object->deleteItem( $itemSaved->getId() ); |
||
95 | |||
96 | |||
97 | $this->assertTrue( $item->getId() !== null ); |
||
98 | $this->assertEquals( $item->getId(), $itemSaved->getId() ); |
||
99 | $this->assertEquals( $item->getSiteId(), $itemSaved->getSiteId() ); |
||
100 | $this->assertEquals( $item->getParentId(), $itemSaved->getParentId() ); |
||
101 | $this->assertEquals( $item->getType(), $itemSaved->getType() ); |
||
102 | $this->assertEquals( $item->getRefId(), $itemSaved->getRefId() ); |
||
103 | $this->assertEquals( $item->getDomain(), $itemSaved->getDomain() ); |
||
104 | $this->assertEquals( $item->getDateStart(), $itemSaved->getDateStart() ); |
||
105 | $this->assertEquals( $item->getDateEnd(), $itemSaved->getDateEnd() ); |
||
106 | $this->assertEquals( $item->getPosition(), $itemSaved->getPosition() ); |
||
107 | $this->assertEquals( $this->editor, $itemSaved->getEditor() ); |
||
108 | $this->assertStringStartsWith( date( 'Y-m-d', time() ), $itemSaved->getTimeCreated() ); |
||
109 | $this->assertStringStartsWith( date( 'Y-m-d', time() ), $itemSaved->getTimeModified() ); |
||
110 | |||
111 | $this->assertEquals( $this->editor, $itemSaved->getEditor() ); |
||
112 | $this->assertRegExp( '/\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}/', $itemSaved->getTimeCreated() ); |
||
113 | $this->assertRegExp( '/\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}/', $itemSaved->getTimeModified() ); |
||
114 | |||
115 | $this->assertEquals( $itemExp->getId(), $itemUpd->getId() ); |
||
116 | $this->assertEquals( $itemExp->getSiteId(), $itemUpd->getSiteId() ); |
||
117 | $this->assertEquals( $itemExp->getParentId(), $itemUpd->getParentId() ); |
||
118 | $this->assertEquals( $itemExp->getType(), $itemUpd->getType() ); |
||
119 | $this->assertEquals( $itemExp->getRefId(), $itemUpd->getRefId() ); |
||
120 | $this->assertEquals( $itemExp->getDomain(), $itemUpd->getDomain() ); |
||
121 | $this->assertEquals( $itemExp->getDateStart(), $itemUpd->getDateStart() ); |
||
122 | $this->assertEquals( $itemExp->getDateEnd(), $itemUpd->getDateEnd() ); |
||
123 | $this->assertEquals( $itemExp->getPosition(), $itemUpd->getPosition() ); |
||
124 | |||
125 | $this->assertEquals( $this->editor, $itemUpd->getEditor() ); |
||
126 | $this->assertEquals( $itemExp->getTimeCreated(), $itemUpd->getTimeCreated() ); |
||
127 | $this->assertRegExp( '/\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}/', $itemUpd->getTimeModified() ); |
||
128 | |||
129 | $this->assertInstanceOf( \Aimeos\MShop\Common\Item\Iface::class, $resultSaved ); |
||
130 | $this->assertInstanceOf( \Aimeos\MShop\Common\Item\Iface::class, $resultUpd ); |
||
131 | |||
132 | $this->expectException( '\\Aimeos\\MShop\\Exception' ); |
||
133 | $this->object->getItem( $itemSaved->getId() ); |
||
134 | } |
||
203 |