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 |
||
16 | class InvalidationSubscriberTest extends WebTestCase |
||
17 | { |
||
18 | public function testInvalidateRoute() |
||
19 | { |
||
20 | $client = static::createClient(); |
||
21 | |||
22 | $client->getContainer()->mock( |
||
|
|||
23 | 'fos_http_cache.cache_manager', |
||
24 | '\FOS\HttpCacheBundle\CacheManager' |
||
25 | ) |
||
26 | ->shouldReceive('supports')->andReturn(true) |
||
27 | ->shouldReceive('invalidateRoute')->once()->with('test_noncached', array()) |
||
28 | ->shouldReceive('invalidateRoute')->once()->with('test_cached', array('id' => 'myhardcodedid')) |
||
29 | ->shouldReceive('invalidateRoute')->once()->with('tag_one', array('id' => '42')) |
||
30 | ->shouldReceive('flush')->once() |
||
31 | ; |
||
32 | |||
33 | $client->request('POST', '/invalidate/route/42'); |
||
34 | } |
||
35 | |||
36 | /** |
||
37 | * @dataProvider getStatusCodesThatTriggerInvalidation |
||
38 | */ |
||
39 | public function testInvalidatePath($statusCode) |
||
40 | { |
||
41 | $client = static::createClient(); |
||
42 | |||
43 | $client->getContainer()->mock( |
||
44 | 'fos_http_cache.cache_manager', |
||
45 | '\FOS\HttpCacheBundle\CacheManager' |
||
46 | ) |
||
47 | ->shouldReceive('supports')->andReturn(true) |
||
48 | ->shouldReceive('invalidatePath')->once()->with('/cached') |
||
49 | ->shouldReceive('invalidatePath')->once()->with( |
||
50 | sprintf('/invalidate/path/%s', $statusCode) |
||
51 | ) |
||
52 | ->shouldReceive('flush')->once() |
||
53 | ; |
||
54 | |||
55 | $client->request('POST', sprintf('/invalidate/path/%s', $statusCode)); |
||
56 | } |
||
57 | |||
58 | View Code Duplication | public function testErrorIsNotInvalidated() |
|
59 | { |
||
60 | $client = static::createClient(); |
||
61 | |||
62 | $client->getContainer()->mock( |
||
63 | 'fos_http_cache.cache_manager', |
||
64 | '\FOS\HttpCacheBundle\CacheManager' |
||
65 | ) |
||
66 | ->shouldReceive('supports')->andReturn(true) |
||
67 | ->shouldReceive('invalidatePath')->never() |
||
68 | ->shouldReceive('flush')->once() |
||
69 | ; |
||
70 | |||
71 | $client->request('POST', '/invalidate/error'); |
||
72 | } |
||
73 | |||
74 | public function getStatusCodesThatTriggerInvalidation() |
||
78 | |||
79 | protected function tearDown() |
||
80 | { |
||
81 | static::createClient()->getContainer()->unmock('fos_http_cache.cache_manager'); |
||
83 | } |
||
84 |
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.
This is most likely a typographical error or the method has been renamed.