| Conditions | 1 |
| Paths | 1 |
| Total Lines | 61 |
| 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 |
||
| 40 | public function testSubmitForm() |
||
| 41 | { |
||
| 42 | $data = [ |
||
| 43 | 'username' => 'John Doe', |
||
| 44 | 'email' => '[email protected]', |
||
| 45 | 'mobile' => '13421234123', |
||
| 46 | 'password' => '123456', |
||
| 47 | 'password_confirmation' => '123456', |
||
| 48 | //"avatar" => "test.jpg", |
||
| 49 | 'profile' => [ |
||
| 50 | 'first_name' => 'John', |
||
| 51 | 'last_name' => 'Doe', |
||
| 52 | 'postcode' => '123456', |
||
| 53 | 'address' => 'Jinshajiang RD', |
||
| 54 | 'latitude' => '131.2123123456', |
||
| 55 | 'longitude' => '21.342123456', |
||
| 56 | 'color' => '#ffffff', |
||
| 57 | 'start_at' => date('Y-m-d H:i:s', time()), |
||
| 58 | 'end_at' => date('Y-m-d H:i:s', time()), |
||
| 59 | ], |
||
| 60 | ]; |
||
| 61 | |||
| 62 | $this->visit('admin/users/create') |
||
| 63 | ->attach(__DIR__.'/assets/test.jpg', 'avatar') |
||
| 64 | |||
| 65 | ->submitForm('Submit', $data) |
||
| 66 | ->seePageIs('admin/users') |
||
| 67 | ->seeInElement('td', 1) |
||
| 68 | ->seeInElement('td', $data['username']) |
||
| 69 | ->seeInElement('td', $data['email']) |
||
| 70 | ->seeInElement('td', $data['mobile']) |
||
| 71 | ->seeInElement('td', "{$data['profile']['first_name']} {$data['profile']['last_name']}") |
||
| 72 | ->seeElement('td img') |
||
| 73 | ->seeInElement('td', $data['profile']['postcode']) |
||
| 74 | ->seeInElement('td', $data['profile']['address']) |
||
| 75 | ->seeInElement('td', "{$data['profile']['latitude']} {$data['profile']['longitude']}") |
||
| 76 | ->seeInElement('td', $data['profile']['color']) |
||
| 77 | ->seeInElement('td', $data['profile']['start_at']) |
||
| 78 | ->seeInElement('td', $data['profile']['end_at']); |
||
| 79 | |||
| 80 | $this->assertCount(1, UserModel::all()); |
||
| 81 | |||
| 82 | $this->seeInDatabase('test_users', ['username' => $data['username']]); |
||
| 83 | $this->seeInDatabase('test_users', ['email' => $data['email']]); |
||
| 84 | $this->seeInDatabase('test_users', ['mobile' => $data['mobile']]); |
||
| 85 | $this->seeInDatabase('test_users', ['password' => $data['password']]); |
||
| 86 | |||
| 87 | $this->seeInDatabase('test_user_profiles', ['first_name' => $data['profile']['first_name']]); |
||
| 88 | $this->seeInDatabase('test_user_profiles', ['last_name' => $data['profile']['last_name']]); |
||
| 89 | $this->seeInDatabase('test_user_profiles', ['postcode' => $data['profile']['postcode']]); |
||
| 90 | $this->seeInDatabase('test_user_profiles', ['address' => $data['profile']['address']]); |
||
| 91 | $this->seeInDatabase('test_user_profiles', ['latitude' => $data['profile']['latitude']]); |
||
| 92 | $this->seeInDatabase('test_user_profiles', ['longitude' => $data['profile']['longitude']]); |
||
| 93 | $this->seeInDatabase('test_user_profiles', ['color' => $data['profile']['color']]); |
||
| 94 | $this->seeInDatabase('test_user_profiles', ['start_at' => $data['profile']['start_at']]); |
||
| 95 | $this->seeInDatabase('test_user_profiles', ['end_at' => $data['profile']['end_at']]); |
||
| 96 | |||
| 97 | $avatar = UserModel::first()->avatar; |
||
| 98 | |||
| 99 | $this->assertFileExists(public_path('uploads/'.$avatar)); |
||
| 100 | } |
||
| 101 | |||
| 210 |