Conditions | 2 |
Paths | 2 |
Total Lines | 65 |
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 |
||
85 | public function testSave() |
||
86 | { |
||
87 | $manager = \Aimeos\MShop::create( $this->context, 'attribute' ); |
||
88 | $this->view->item = $manager->create(); |
||
89 | |||
90 | |||
91 | $param = array( |
||
92 | 'site' => 'unittest', |
||
93 | 'media' => [[ |
||
94 | 'media.id' => '', |
||
95 | 'media.type' => 'default', |
||
96 | 'media.languageid' => 'de', |
||
97 | 'media.label' => 'test', |
||
98 | 'attribute.lists.type' => 'default', |
||
99 | ]], |
||
100 | ); |
||
101 | |||
102 | $helper = new \Aimeos\Base\View\Helper\Param\Standard( $this->view, $param ); |
||
103 | $this->view->addHelper( 'param', $helper ); |
||
104 | |||
105 | $file = $this->getMockBuilder( \Psr\Http\Message\UploadedFileInterface::class )->getMock(); |
||
106 | $request = $this->getMockBuilder( \Psr\Http\Message\ServerRequestInterface::class )->getMock(); |
||
107 | $request->expects( $this->any() )->method( 'getUploadedFiles' ) |
||
108 | ->willReturn( ['media' => [0 => ['file' => $file]]] ); |
||
109 | |||
110 | $helper = new \Aimeos\Base\View\Helper\Request\Standard( $this->view, $request, '127.0.0.1', 'test' ); |
||
111 | $this->view ->addHelper( 'request', $helper ); |
||
112 | |||
113 | |||
114 | $managerStub = $this->getMockBuilder( \Aimeos\MShop\Media\Manager\Standard::class ) |
||
115 | ->setConstructorArgs( array( $this->context ) ) |
||
116 | ->onlyMethods( ['upload', 'type'] ) |
||
117 | ->getMock(); |
||
118 | |||
119 | \Aimeos\MShop::inject( \Aimeos\MShop\Media\Manager\Standard::class, $managerStub ); |
||
120 | |||
121 | $managerStub->method( 'type' )->willReturn( ['media'] ); |
||
122 | $managerStub->expects( $this->once() )->method( 'upload' )->willReturnArgument( 0 ); |
||
123 | |||
124 | |||
125 | $result = $this->object->save(); |
||
126 | |||
127 | |||
128 | $this->assertEmpty( $this->view->get( 'errors' ) ); |
||
129 | $this->assertEmpty( $result ); |
||
130 | $this->assertEquals( 1, count( $this->view->item->getListItems() ) ); |
||
131 | |||
132 | foreach( $this->view->item->getListItems( 'media' ) as $listItem ) |
||
133 | { |
||
134 | $this->assertEquals( 'media', $listItem->getDomain() ); |
||
135 | |||
136 | $refItem = $listItem->getRefItem(); |
||
137 | $this->assertEquals( 'de', $refItem->getLanguageId() ); |
||
138 | $this->assertEquals( 'test', $refItem->getLabel() ); |
||
139 | } |
||
140 | |||
141 | |||
142 | $helper = new \Aimeos\Base\View\Helper\Param\Standard( $this->view, ['site' => 'unittest', 'media' => []] ); |
||
143 | $this->view->addHelper( 'param', $helper ); |
||
144 | |||
145 | $result = $this->object->save(); |
||
146 | |||
147 | $this->assertEmpty( $this->view->get( 'errors' ) ); |
||
148 | $this->assertEmpty( $result ); |
||
149 | $this->assertEquals( 0, count( $this->view->item->getListItems() ) ); |
||
150 | } |
||
206 |