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 |
||
| 9 | class VimeoProviderTest extends \PHPUnit_Framework_TestCase |
||
| 10 | { |
||
| 11 | public function testParseProviderReference() |
||
| 12 | { |
||
| 13 | $youtube = new VimeoProvider(); |
||
| 14 | $this->assertEquals('184376204', $youtube->parseProviderReference('https://vimeo.com/184376204')); |
||
| 15 | $this->assertEquals('184376204', $youtube->parseProviderReference('184376204')); |
||
| 16 | } |
||
| 17 | |||
| 18 | public function testParseInvalidProviderReference() |
||
| 19 | { |
||
| 20 | $this->setExpectedException(InvalidProviderUrlException::class); |
||
| 21 | $youtube = new VimeoProvider(); |
||
| 22 | $youtube->parseProviderReference('https://vimeo.com/'); |
||
| 23 | } |
||
| 24 | |||
| 25 | public function testParseInvalidProviderReference2() |
||
| 26 | { |
||
| 27 | $this->setExpectedException(InvalidProviderUrlException::class); |
||
| 28 | $youtube = new VimeoProvider(); |
||
| 29 | $youtube->parseProviderReference('https://vimeo.com/foobar'); |
||
| 30 | } |
||
| 31 | |||
| 32 | public function testSupports() |
||
| 33 | { |
||
| 34 | $provider = new VimeoProvider(); |
||
| 35 | $this->assertFalse($provider->supports(AbstractProvider::SUPPORT_DOWNLOAD)); |
||
| 36 | $this->assertTrue($provider->supports(AbstractProvider::SUPPORT_EMBED)); |
||
| 37 | $this->assertTrue($provider->supports(AbstractProvider::SUPPORT_IMAGE)); |
||
| 38 | $this->assertFalse($provider->supports('foo')); |
||
| 39 | } |
||
| 40 | } |
||
| 41 |