Conditions | 1 |
Paths | 1 |
Total Lines | 82 |
Code Lines | 59 |
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 |
||
45 | public function testRun() |
||
46 | { |
||
47 | $mqmStub = $this->getMockBuilder( '\\Aimeos\\Base\\MQueue\\Manager\\Standard' ) |
||
48 | ->setConstructorArgs( [[]] ) |
||
49 | ->onlyMethods( ['get'] ) |
||
50 | ->getMock(); |
||
51 | |||
52 | $mqStub = $this->getMockBuilder( '\\Aimeos\\Base\\MQueue\\Standard' ) |
||
53 | ->disableOriginalConstructor() |
||
54 | ->onlyMethods( ['getQueue'] ) |
||
55 | ->getMock(); |
||
56 | |||
57 | $queueStub = $this->getMockBuilder( '\\Aimeos\\Base\\MQueue\\Queue\\Standard' ) |
||
58 | ->disableOriginalConstructor() |
||
59 | ->onlyMethods( ['del', 'get'] ) |
||
60 | ->getMock(); |
||
61 | |||
62 | $msgStub = $this->getMockBuilder( '\\Aimeos\\Base\\MQueue\\Message\\Standard' ) |
||
63 | ->disableOriginalConstructor() |
||
64 | ->onlyMethods( ['getBody'] ) |
||
65 | ->getMock(); |
||
66 | |||
67 | |||
68 | $this->context->setMessageQueueManager( $mqmStub ); |
||
69 | |||
70 | |||
71 | $mqmStub->expects( $this->once() )->method( 'get' ) |
||
72 | ->willReturn( $mqStub ); |
||
73 | |||
74 | $mqStub->expects( $this->once() )->method( 'getQueue' ) |
||
75 | ->willReturn( $queueStub ); |
||
76 | |||
77 | $queueStub->expects( $this->exactly( 2 ) )->method( 'get' ) |
||
78 | ->willReturn( $msgStub, null ); |
||
79 | |||
80 | $queueStub->expects( $this->once() )->method( 'del' ); |
||
81 | |||
82 | $msgStub->expects( $this->once() )->method( 'getBody' ) |
||
83 | ->willReturn( '{"sitecode":"unittest"}' ); |
||
84 | |||
85 | |||
86 | $this->object->run(); |
||
87 | |||
88 | |||
89 | $jobManager = \Aimeos\MAdmin::create( $this->context, 'job' ); |
||
90 | $jobSearch = $jobManager->filter(); |
||
91 | $jobSearch->setConditions( $jobSearch->compare( '=~', 'job.label', 'order-export_' ) ); |
||
92 | $jobItems = $jobManager->search( $jobSearch ); |
||
93 | $jobManager->delete( $jobItems->toArray() ); |
||
94 | |||
95 | $this->assertEquals( 1, count( $jobItems ) ); |
||
96 | |||
97 | |||
98 | $filename = dirname( dirname( dirname( dirname( dirname( __DIR__ ) ) ) ) ) . '/tmp/' . $jobItems->first()->getLabel(); |
||
99 | $fp = fopen( $filename, 'r' ); |
||
100 | |||
101 | $invoice = fgetcsv( $fp, null, ',', '"', '' ); |
||
102 | $address1 = fgetcsv( $fp, null, ',', '"', '' ); |
||
103 | $address2 = fgetcsv( $fp, null, ',', '"', '' ); |
||
104 | $service1 = fgetcsv( $fp, null, ',', '"', '' ); |
||
105 | $service2 = fgetcsv( $fp, null, ',', '"', '' ); |
||
106 | $coupon1 = fgetcsv( $fp, null, ',', '"', '' ); |
||
107 | $coupon2 = fgetcsv( $fp, null, ',', '"', '' ); |
||
108 | $product1 = fgetcsv( $fp, null, ',', '"', '' ); |
||
109 | $product2 = fgetcsv( $fp, null, ',', '"', '' ); |
||
110 | $product3 = fgetcsv( $fp, null, ',', '"', '' ); |
||
111 | $product4 = fgetcsv( $fp, null, ',', '"', '' ); |
||
112 | |||
113 | fclose( $fp ); |
||
114 | unlink( $filename ); |
||
115 | |||
116 | $this->assertEquals( 'invoice', $invoice[0] ); |
||
117 | $this->assertEquals( 'address', $address1[0] ); |
||
118 | $this->assertEquals( 'address', $address2[0] ); |
||
119 | $this->assertEquals( 'service', $service1[0] ); |
||
120 | $this->assertEquals( 'service', $service2[0] ); |
||
121 | $this->assertEquals( 'coupon', $coupon1[0] ); |
||
122 | $this->assertEquals( 'coupon', $coupon2[0] ); |
||
123 | $this->assertEquals( 'product', $product1[0] ); |
||
124 | $this->assertEquals( 'product', $product2[0] ); |
||
125 | $this->assertEquals( 'product', $product3[0] ); |
||
126 | $this->assertEquals( 'product', $product4[0] ); |
||
127 | } |
||
129 |