| Conditions | 1 |
| Paths | 1 |
| Total Lines | 56 |
| Code Lines | 35 |
| 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 |
||
| 64 | public function testWhenApplicationWithTokenExists(): void { |
||
| 65 | $application = new MembershipApplication(); |
||
| 66 | |||
| 67 | $application->modifyDataObject( function( MembershipApplicationData $data ) { |
||
| 68 | $data->setUpdateToken( self::CORRECT_UPDATE_TOKEN ); |
||
| 69 | $data->setAccessToken( self::CORRECT_ACCESS_TOKEN ); |
||
| 70 | } ); |
||
| 71 | |||
| 72 | $this->specify( |
||
| 73 | 'given correct application id and correct token, update authorization succeeds', |
||
| 74 | function() use ( $application ) { |
||
| 75 | $authorizer = $this->newAuthorizerWithApplications( self::CORRECT_UPDATE_TOKEN, null, $application ); |
||
| 76 | $this->assertTrue( $authorizer->canModifyApplication( $application->getId() ) ); |
||
| 77 | } |
||
| 78 | ); |
||
| 79 | |||
| 80 | $this->specify( |
||
| 81 | 'given wrong application id and correct token, update authorization fails', |
||
| 82 | function() use ( $application ) { |
||
| 83 | $authorizer = $this->newAuthorizerWithApplications( self::CORRECT_UPDATE_TOKEN, null, $application ); |
||
| 84 | $this->assertFalse( $authorizer->canModifyApplication( self::ID_OF_WRONG_APPLICATION ) ); |
||
| 85 | } |
||
| 86 | ); |
||
| 87 | |||
| 88 | $this->specify( |
||
| 89 | 'given correct application id and wrong token, update authorization fails', |
||
| 90 | function() use ( $application ) { |
||
| 91 | $authorizer = $this->newAuthorizerWithApplications( self::WRONG__UPDATE_TOKEN, null, $application ); |
||
| 92 | $this->assertFalse( $authorizer->canModifyApplication( $application->getId() ) ); |
||
| 93 | } |
||
| 94 | ); |
||
| 95 | |||
| 96 | $this->specify( |
||
| 97 | 'given correct application id and correct token, access authorization succeeds', |
||
| 98 | function() use ( $application ) { |
||
| 99 | $authorizer = $this->newAuthorizerWithApplications( null, self::CORRECT_ACCESS_TOKEN, $application ); |
||
| 100 | $this->assertTrue( $authorizer->canAccessApplication( $application->getId() ) ); |
||
| 101 | } |
||
| 102 | ); |
||
| 103 | |||
| 104 | $this->specify( |
||
| 105 | 'given wrong application id and correct token, access authorization fails', |
||
| 106 | function() use ( $application ) { |
||
| 107 | $authorizer = $this->newAuthorizerWithApplications( null, self::CORRECT_ACCESS_TOKEN, $application ); |
||
| 108 | $this->assertFalse( $authorizer->canAccessApplication( self::ID_OF_WRONG_APPLICATION ) ); |
||
| 109 | } |
||
| 110 | ); |
||
| 111 | |||
| 112 | $this->specify( |
||
| 113 | 'given correct application id and wrong token, access authorization fails', |
||
| 114 | function() use ( $application ) { |
||
| 115 | $authorizer = $this->newAuthorizerWithApplications( null, self::WRONG_ACCESS_TOKEN, $application ); |
||
| 116 | $this->assertFalse( $authorizer->canAccessApplication( $application->getId() ) ); |
||
| 117 | } |
||
| 118 | ); |
||
| 119 | } |
||
| 120 | |||
| 174 |