| Total Complexity | 7 |
| Total Lines | 97 |
| Duplicated Lines | 31.96 % |
| Changes | 4 | ||
| Bugs | 0 | Features | 0 |
Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.
Common duplication problems, and corresponding solutions are:
| 1 | <?php namespace GeneaLabs\LaravelCaffeine\Tests\Feature; |
||
| 6 | class CaffeineTest extends TestCase |
||
| 7 | { |
||
| 8 | public function testDripEndpoint() |
||
| 9 | { |
||
| 10 | $dripRoute = config('genealabs-laravel-caffeine.route', 'genealabs/laravel-caffeine/drip'); |
||
| 11 | |||
| 12 | $response = $this->get($dripRoute); |
||
| 13 | |||
| 14 | $response->assertStatus(204); |
||
| 15 | } |
||
| 16 | |||
| 17 | public function testMiddlewareInjectsDripScript() |
||
| 18 | { |
||
| 19 | $expectedResult = file_get_contents(__DIR__ . '/../Fixtures/expired_script.txt'); |
||
| 20 | |||
| 21 | $response = $this->get(route('genealabs-laravel-caffeine.tests.form')); |
||
| 22 | |||
| 23 | $response->assertSee($expectedResult); |
||
|
1 ignored issue
–
show
|
|||
| 24 | } |
||
| 25 | |||
| 26 | View Code Duplication | public function testSuccessfulDrip() |
|
|
1 ignored issue
–
show
|
|||
| 27 | { |
||
| 28 | $dripRoute = config('genealabs-laravel-caffeine.route', 'genealabs/laravel-caffeine/drip'); |
||
| 29 | $html = $this->get(route('genealabs-laravel-caffeine.tests.form')) |
||
| 30 | ->getContent(); |
||
| 31 | $matches = []; |
||
| 32 | preg_match('/<meta name="csrf-token" content="(.*?)">/', $html, $matches); |
||
| 33 | $csrfToken = $matches[1]; |
||
| 34 | |||
| 35 | $response = $this->get($dripRoute, [ |
||
| 36 | '_token' => $csrfToken, |
||
| 37 | ]); |
||
| 38 | |||
| 39 | $response->assertStatus(204); |
||
| 40 | } |
||
| 41 | |||
| 42 | View Code Duplication | public function testExpiredDrip() |
|
|
1 ignored issue
–
show
|
|||
| 43 | { |
||
| 44 | $dripRoute = config( |
||
| 45 | 'genealabs-laravel-caffeine.dripInterval', |
||
| 46 | 'genealabs/laravel-caffeine/drip' |
||
| 47 | ); |
||
| 48 | $html = $this->get(route('genealabs-laravel-caffeine.tests.form')) |
||
| 49 | ->getContent(); |
||
| 50 | $matches = []; |
||
| 51 | preg_match( |
||
| 52 | '/<meta name="csrf-token" content="(.*?)">/', |
||
| 53 | $html, |
||
| 54 | $matches |
||
| 55 | ); |
||
| 56 | $csrfToken = $matches[1]; |
||
| 57 | |||
| 58 | app('session')->flush(); |
||
| 59 | $response = $this->get($dripRoute, [ |
||
| 60 | '_token' => $csrfToken, |
||
| 61 | ]); |
||
| 62 | |||
| 63 | $response->assertStatus(404); |
||
| 64 | } |
||
| 65 | |||
| 66 | public function testDisabledCaffeination() |
||
| 83 | } |
||
| 84 | |||
| 85 | public function testNonStringReturnContent() |
||
| 86 | { |
||
| 87 | $response = $this->get(route('genealabs-laravel-caffeine.tests.null-response')); |
||
| 88 | |||
| 89 | $response->assertDontSee('const caffeineSendDrip'); |
||
| 90 | } |
||
| 91 | |||
| 92 | public function testRouteMiddleware() |
||
| 103 | } |
||
| 104 | } |
||
| 105 |