| Conditions | 1 |
| Paths | 1 |
| Total Lines | 68 |
| 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 |
||
| 46 | public function testRun() |
||
| 47 | { |
||
| 48 | $mqmStub = $this->getMockBuilder( '\\Aimeos\\MW\\MQueue\\Manager\\Standard' ) |
||
| 49 | ->setConstructorArgs( [$this->context->getConfig()] ) |
||
| 50 | ->setMethods( ['get'] ) |
||
| 51 | ->getMock(); |
||
| 52 | |||
| 53 | $mqStub = $this->getMockBuilder( '\\Aimeos\\MW\\MQueue\\Standard' ) |
||
| 54 | ->disableOriginalConstructor() |
||
| 55 | ->setMethods( ['getQueue'] ) |
||
| 56 | ->getMock(); |
||
| 57 | |||
| 58 | $queueStub = $this->getMockBuilder( '\\Aimeos\\MW\\MQueue\\Queue\\Standard' ) |
||
| 59 | ->disableOriginalConstructor() |
||
| 60 | ->setMethods( ['del', 'get'] ) |
||
| 61 | ->getMock(); |
||
| 62 | |||
| 63 | $msgStub = $this->getMockBuilder( '\\Aimeos\\MW\\MQueue\\Message\\Standard' ) |
||
| 64 | ->disableOriginalConstructor() |
||
| 65 | ->setMethods( ['getBody'] ) |
||
| 66 | ->getMock(); |
||
| 67 | |||
| 68 | |||
| 69 | $this->context->setMessageQueueManager( $mqmStub ); |
||
| 70 | |||
| 71 | |||
| 72 | $mqmStub->expects( $this->once() )->method( 'get' ) |
||
| 73 | ->will( $this->returnValue( $mqStub ) ); |
||
| 74 | |||
| 75 | $mqStub->expects( $this->once() )->method( 'getQueue' ) |
||
| 76 | ->will( $this->returnValue( $queueStub ) ); |
||
| 77 | |||
| 78 | $queueStub->expects( $this->exactly( 2 ) )->method( 'get' ) |
||
| 79 | ->will( $this->onConsecutiveCalls( $msgStub, null ) ); |
||
| 80 | |||
| 81 | $queueStub->expects( $this->once() )->method( 'del' ); |
||
| 82 | |||
| 83 | $msgStub->expects( $this->once() )->method( 'getBody' ) |
||
| 84 | ->will( $this->returnValue( '{"sitecode":"unittest"}' ) ); |
||
| 85 | |||
| 86 | |||
| 87 | $this->object->run(); |
||
| 88 | |||
| 89 | |||
| 90 | $jobManager = \Aimeos\MAdmin::create( $this->context, 'job' ); |
||
| 91 | $jobSearch = $jobManager->createSearch(); |
||
| 92 | $jobSearch->setConditions( $jobSearch->compare( '=~', 'job.label', 'subscription-export_' ) ); |
||
| 93 | $jobItems = $jobManager->searchItems( $jobSearch ); |
||
| 94 | $jobManager->deleteItems( array_keys( $jobItems ) ); |
||
| 95 | |||
| 96 | $this->assertEquals( 1, count( $jobItems ) ); |
||
| 97 | |||
| 98 | |||
| 99 | $filename = dirname( dirname( dirname( dirname( dirname( __DIR__ ) ) ) ) ) . '/tmp/' . reset( $jobItems )->getLabel(); |
||
| 100 | $fp = fopen( $filename, 'r' ); |
||
| 101 | |||
| 102 | $subscription = fgetcsv( $fp ); |
||
|
|
|||
| 103 | $address1 = fgetcsv( $fp ); |
||
| 104 | $address2 = fgetcsv( $fp ); |
||
| 105 | $product1 = fgetcsv( $fp ); |
||
| 106 | |||
| 107 | fclose( $fp ); |
||
| 108 | unlink( $filename ); |
||
| 109 | |||
| 110 | $this->assertEquals( 'subscription', $subscription[0] ); |
||
| 111 | $this->assertEquals( 'address', $address1[0] ); |
||
| 112 | $this->assertEquals( 'address', $address2[0] ); |
||
| 113 | $this->assertEquals( 'product', $product1[0] ); |
||
| 114 | } |
||
| 204 |