Conditions | 2 |
Paths | 2 |
Total Lines | 51 |
Code Lines | 37 |
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 |
||
46 | public function testSaveUpdateDeleteItem() |
||
47 | { |
||
48 | $search = $this->object->filter(); |
||
49 | $search->setConditions( $search->compare( '==', 'customer.property.editor', $this->editor ) ); |
||
50 | |||
51 | if( ( $item = $this->object->search( $search )->first() ) === null ) { |
||
52 | throw new \RuntimeException( 'No property item found' ); |
||
53 | } |
||
54 | |||
55 | $item->setId( null ); |
||
56 | $item->setLanguageId( 'en' ); |
||
57 | $resultSaved = $this->object->save( $item ); |
||
58 | $itemSaved = $this->object->get( $item->getId() ); |
||
59 | |||
60 | $itemExp = clone $itemSaved; |
||
61 | $itemExp->setValue( 'unittest' ); |
||
62 | $resultUpd = $this->object->save( $itemExp ); |
||
63 | $itemUpd = $this->object->get( $itemExp->getId() ); |
||
64 | |||
65 | $this->object->delete( $itemSaved->getId() ); |
||
66 | |||
67 | $context = \TestHelper::context(); |
||
68 | |||
69 | $this->assertTrue( $item->getId() !== null ); |
||
70 | $this->assertEquals( $item->getId(), $itemSaved->getId() ); |
||
71 | $this->assertEquals( $item->getParentId(), $itemSaved->getParentId() ); |
||
72 | $this->assertEquals( $item->getSiteId(), $itemSaved->getSiteId() ); |
||
73 | $this->assertEquals( $item->getType(), $itemSaved->getType() ); |
||
74 | $this->assertEquals( $item->getLanguageId(), $itemSaved->getLanguageId() ); |
||
75 | $this->assertEquals( $item->getValue(), $itemSaved->getValue() ); |
||
76 | |||
77 | $this->assertEquals( $context->editor(), $itemSaved->editor() ); |
||
78 | $this->assertMatchesRegularExpression( '/\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}/', $itemSaved->getTimeCreated() ); |
||
79 | $this->assertMatchesRegularExpression( '/\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}/', $itemSaved->getTimeModified() ); |
||
80 | |||
81 | $this->assertEquals( $itemExp->getId(), $itemUpd->getId() ); |
||
82 | $this->assertEquals( $itemExp->getParentId(), $itemUpd->getParentId() ); |
||
83 | $this->assertEquals( $itemExp->getSiteId(), $itemUpd->getSiteId() ); |
||
84 | $this->assertEquals( $itemExp->getType(), $itemUpd->getType() ); |
||
85 | $this->assertEquals( $itemExp->getLanguageId(), $itemUpd->getLanguageId() ); |
||
86 | $this->assertEquals( $itemExp->getValue(), $itemUpd->getValue() ); |
||
87 | |||
88 | $this->assertEquals( $context->editor(), $itemUpd->editor() ); |
||
89 | $this->assertEquals( $itemExp->getTimeCreated(), $itemUpd->getTimeCreated() ); |
||
90 | $this->assertMatchesRegularExpression( '/\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}/', $itemUpd->getTimeModified() ); |
||
91 | |||
92 | $this->assertInstanceOf( \Aimeos\MShop\Common\Item\Iface::class, $resultSaved ); |
||
93 | $this->assertInstanceOf( \Aimeos\MShop\Common\Item\Iface::class, $resultUpd ); |
||
94 | |||
95 | $this->expectException( '\\Aimeos\\MShop\\Exception' ); |
||
96 | $this->object->get( $itemSaved->getId() ); |
||
97 | } |
||
162 |