| Conditions | 1 |
| Paths | 1 |
| Total Lines | 85 |
| Code Lines | 58 |
| 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 |
||
| 117 | public function testRunCollapsedLines() |
||
| 118 | { |
||
| 119 | $mqmStub = $this->getMockBuilder( '\\Aimeos\\MW\\MQueue\\Manager\\Standard' ) |
||
| 120 | ->setConstructorArgs( [$this->context->getConfig()] ) |
||
| 121 | ->setMethods( ['get'] ) |
||
| 122 | ->getMock(); |
||
| 123 | |||
| 124 | $mqStub = $this->getMockBuilder( '\\Aimeos\\MW\\MQueue\\Standard' ) |
||
| 125 | ->disableOriginalConstructor() |
||
| 126 | ->setMethods( ['getQueue'] ) |
||
| 127 | ->getMock(); |
||
| 128 | |||
| 129 | $queueStub = $this->getMockBuilder( '\\Aimeos\\MW\\MQueue\\Queue\\Standard' ) |
||
| 130 | ->disableOriginalConstructor() |
||
| 131 | ->setMethods( ['del', 'get'] ) |
||
| 132 | ->getMock(); |
||
| 133 | |||
| 134 | $msgStub = $this->getMockBuilder( '\\Aimeos\\MW\\MQueue\\Message\\Standard' ) |
||
| 135 | ->disableOriginalConstructor() |
||
| 136 | ->setMethods( ['getBody'] ) |
||
| 137 | ->getMock(); |
||
| 138 | |||
| 139 | |||
| 140 | $this->context->setMessageQueueManager( $mqmStub ); |
||
| 141 | $this->context->getConfig()->set( 'controller/jobs/subscription/export/csv/collapse', true ); |
||
| 142 | $this->context->getConfig()->set( 'controller/jobs/subscription/export/csv/mapping', [ |
||
| 143 | 'subscription' => array( |
||
| 144 | 0 => 'subscription.interval', |
||
| 145 | 1 => 'subscription.period', |
||
| 146 | 2 => 'subscription.ordbaseid', |
||
| 147 | ), |
||
| 148 | 'address' => array( |
||
| 149 | 3 => 'order.base.address.firstname', |
||
| 150 | 4 => 'order.base.address.lastname', |
||
| 151 | ), |
||
| 152 | 'product' => array( |
||
| 153 | 5 => 'order.base.product.prodcode', |
||
| 154 | 6 => 'order.base.product.price', |
||
| 155 | ), |
||
| 156 | ] ); |
||
| 157 | |||
| 158 | |||
| 159 | $mqmStub->expects( $this->once() )->method( 'get' ) |
||
| 160 | ->will( $this->returnValue( $mqStub ) ); |
||
| 161 | |||
| 162 | $mqStub->expects( $this->once() )->method( 'getQueue' ) |
||
| 163 | ->will( $this->returnValue( $queueStub ) ); |
||
| 164 | |||
| 165 | $queueStub->expects( $this->exactly( 2 ) )->method( 'get' ) |
||
| 166 | ->will( $this->onConsecutiveCalls( $msgStub, null ) ); |
||
| 167 | |||
| 168 | $queueStub->expects( $this->once() )->method( 'del' ); |
||
| 169 | |||
| 170 | $msgStub->expects( $this->once() )->method( 'getBody' ) |
||
| 171 | ->will( $this->returnValue( '{"sitecode":"unittest"}' ) ); |
||
| 172 | |||
| 173 | |||
| 174 | $object = new \Aimeos\Controller\Jobs\Subscription\Export\Csv\Standard( $this->context, $this->aimeos ); |
||
| 175 | $object->run(); |
||
| 176 | |||
| 177 | |||
| 178 | $jobManager = \Aimeos\MAdmin::create( $this->context, 'job' ); |
||
| 179 | $jobSearch = $jobManager->createSearch(); |
||
| 180 | $jobSearch->setConditions( $jobSearch->compare( '=~', 'job.label', 'subscription-export_' ) ); |
||
| 181 | $jobItems = $jobManager->searchItems( $jobSearch ); |
||
| 182 | $jobManager->deleteItems( array_keys( $jobItems ) ); |
||
| 183 | |||
| 184 | $this->assertEquals( 1, count( $jobItems ) ); |
||
| 185 | |||
| 186 | |||
| 187 | $filename = dirname( dirname( dirname( dirname( dirname( __DIR__ ) ) ) ) ) . '/tmp/' . reset( $jobItems )->getLabel(); |
||
| 188 | $fp = fopen( $filename, 'r' ); |
||
| 189 | |||
| 190 | $line1 = fgetcsv( $fp ); |
||
| 191 | $line2 = fgetcsv( $fp ); |
||
| 192 | $line3 = fgetcsv( $fp ); |
||
| 193 | |||
| 194 | fclose( $fp ); |
||
| 195 | unlink( $filename ); |
||
| 196 | |||
| 197 | $this->assertEquals( 'P0Y1M0W0D', $line1[0] ); |
||
| 198 | $this->assertEquals( 'Unittest', $line1[4] ); |
||
| 199 | $this->assertEquals( 'CNE', $line1[5] ); |
||
| 200 | $this->assertEquals( 'P1Y0M0W0D', $line2[0] ); |
||
| 201 | $this->assertFalse( $line3 ); |
||
| 202 | } |
||
| 204 |