| Conditions | 1 |
| Paths | 1 |
| Total Lines | 65 |
| Code Lines | 45 |
| 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 |
||
| 11 | public function testNewAuction() |
||
| 12 | {
|
||
| 13 | $config = $this->getMockBuilder(Config::class) |
||
| 14 | ->disableOriginalConstructor() |
||
| 15 | ->getMock(); |
||
| 16 | |||
| 17 | $soapClient = $this->getMockBuilder(SoapClient::class) |
||
| 18 | ->disableOriginalConstructor() |
||
| 19 | ->setMethods(['doQuerySysStatus', 'doLogin', 'doNewAuctionExt', 'doVerifyItem']) |
||
| 20 | ->getMock(); |
||
| 21 | |||
| 22 | $soapClient->expects($this->once()) |
||
| 23 | ->method('doQuerySysStatus')
|
||
| 24 | ->willReturn((object)['verKey' => 'someVersionKey']); |
||
| 25 | |||
| 26 | $soapClient->expects($this->once()) |
||
| 27 | ->method('doLogin')
|
||
| 28 | ->willReturn((object)['userId' => 'someUserId', 'sessionHandlePart' => 'someSessionHandlePart']); |
||
| 29 | |||
| 30 | |||
| 31 | |||
| 32 | $apiClient = $this->getMockBuilder(Client::class) |
||
| 33 | ->setConstructorArgs([$config, $soapClient]) |
||
| 34 | ->setMethods(['newAuctionExt', 'verifyItem']) |
||
| 35 | ->getMock(); |
||
| 36 | |||
| 37 | $apiClient->expects($this->once()) |
||
| 38 | ->method('newAuctionExt')
|
||
| 39 | ->with([ |
||
| 40 | 'fields' => [ |
||
| 41 | [ |
||
| 42 | 'fvalueString' => 'test title', |
||
| 43 | 'fid' => 1, |
||
| 44 | 'fvalueInt' => 0, |
||
| 45 | 'fvalueFloat' => 0, |
||
| 46 | 'fvalueImage' => '', |
||
| 47 | 'fvalueDate' => '', |
||
| 48 | 'fvalueDatetime' => 0, |
||
| 49 | 'fvalueRangeInt' => [ |
||
| 50 | 'fvalueRangeIntMin' => 0, |
||
| 51 | 'fvalueRangeIntMax' => 0, |
||
| 52 | ], |
||
| 53 | 'fvalueRangeFloat' => [ |
||
| 54 | 'fvalueRangeFloatMin' => 0, |
||
| 55 | 'fvalueRangeFloatMax' => 0, |
||
| 56 | ], |
||
| 57 | 'fvalueRangeDate' => [ |
||
| 58 | 'fvalueRangeDateMin' => '', |
||
| 59 | 'fvalueRangeDateMax' => '', |
||
| 60 | ] |
||
| 61 | ] |
||
| 62 | ], |
||
| 63 | 'localId' => 1 |
||
| 64 | ]); |
||
| 65 | |||
| 66 | $apiClient->expects($this->once()) |
||
| 67 | ->method('verifyItem')
|
||
| 68 | ->willReturn((object)['itemId' => 1234]); |
||
| 69 | |||
| 70 | $helper = new Helper($apiClient); |
||
| 71 | |||
| 72 | $result = $helper->newAuction(new Auction([1 => 'test title']), 1); |
||
| 73 | |||
| 74 | $this->assertSame(1234, $result); |
||
| 75 | } |
||
| 76 | } |
||
| 77 |