Conditions | 1 |
Paths | 1 |
Total Lines | 51 |
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 |
||
52 | public function testSaveUpdateDeleteItem() |
||
53 | { |
||
54 | $search = $this->object->filter()->slice( 0, 1 ); |
||
55 | $item = $this->object->search( $search )->first( new \RuntimeException( 'No item found' ) ); |
||
56 | |||
57 | $item->setId( null ); |
||
58 | $item->setDomain( 'unittest' ); |
||
59 | $resultSaved = $this->object->save( $item ); |
||
60 | $itemSaved = $this->object->get( $item->getId() ); |
||
61 | |||
62 | $itemExp = clone $itemSaved; |
||
63 | $itemExp->setDomain( 'unittest2' ); |
||
64 | $resultUpd = $this->object->save( $itemExp ); |
||
65 | $itemUpd = $this->object->get( $itemExp->getId() ); |
||
66 | |||
67 | $this->object->delete( $itemSaved->getId() ); |
||
68 | |||
69 | $this->assertTrue( $item->getId() !== null ); |
||
70 | $this->assertEquals( $item->getId(), $itemSaved->getId() ); |
||
71 | $this->assertEquals( $item->getSiteId(), $itemSaved->getSiteId() ); |
||
72 | $this->assertEquals( $item->getParentId(), $itemSaved->getParentId() ); |
||
73 | $this->assertEquals( $item->getType(), $itemSaved->getType() ); |
||
74 | $this->assertEquals( $item->getRefId(), $itemSaved->getRefId() ); |
||
75 | $this->assertEquals( $item->getDomain(), $itemSaved->getDomain() ); |
||
76 | $this->assertEquals( $item->getDateStart(), $itemSaved->getDateStart() ); |
||
77 | $this->assertEquals( $item->getDateEnd(), $itemSaved->getDateEnd() ); |
||
78 | $this->assertEquals( $item->getPosition(), $itemSaved->getPosition() ); |
||
79 | |||
80 | $this->assertEquals( $this->context->editor(), $itemSaved->editor() ); |
||
81 | $this->assertMatchesRegularExpression( '/\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}/', $itemSaved->getTimeCreated() ); |
||
82 | $this->assertMatchesRegularExpression( '/\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}/', $itemSaved->getTimeModified() ); |
||
83 | |||
84 | $this->assertEquals( $itemExp->getId(), $itemUpd->getId() ); |
||
85 | $this->assertEquals( $itemExp->getSiteId(), $itemUpd->getSiteId() ); |
||
86 | $this->assertEquals( $itemExp->getParentId(), $itemUpd->getParentId() ); |
||
87 | $this->assertEquals( $itemExp->getType(), $itemUpd->getType() ); |
||
88 | $this->assertEquals( $itemExp->getRefId(), $itemUpd->getRefId() ); |
||
89 | $this->assertEquals( $itemExp->getDomain(), $itemUpd->getDomain() ); |
||
90 | $this->assertEquals( $itemExp->getDateStart(), $itemUpd->getDateStart() ); |
||
91 | $this->assertEquals( $itemExp->getDateEnd(), $itemUpd->getDateEnd() ); |
||
92 | $this->assertEquals( $itemExp->getPosition(), $itemUpd->getPosition() ); |
||
93 | |||
94 | $this->assertEquals( $this->context->editor(), $itemUpd->editor() ); |
||
95 | $this->assertEquals( $itemExp->getTimeCreated(), $itemUpd->getTimeCreated() ); |
||
96 | $this->assertMatchesRegularExpression( '/\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}/', $itemUpd->getTimeModified() ); |
||
97 | |||
98 | $this->assertInstanceOf( \Aimeos\MShop\Common\Item\Iface::class, $resultSaved ); |
||
99 | $this->assertInstanceOf( \Aimeos\MShop\Common\Item\Iface::class, $resultUpd ); |
||
100 | |||
101 | $this->expectException( '\\Aimeos\\MShop\\Exception' ); |
||
102 | $this->object->get( $itemSaved->getId() ); |
||
103 | } |
||
164 |