Completed
Push — master ( ab1063...454cba )
by smiley
05:29
created

ExtractUrlTest   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 73
Duplicated Lines 16.44 %

Coupling/Cohesion

Components 1
Dependencies 3

Importance

Changes 2
Bugs 0 Features 0
Metric Value
wmc 4
c 2
b 0
f 0
lcom 1
cbo 3
dl 12
loc 73
rs 10

How to fix   Duplicated Code   

Duplicated Code

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
2
/**
3
 *
4
 * @filesource   ExtractUrlTest.php
5
 * @created      16.02.2016
6
 * @package      chillerlan\TinyCurlTest
7
 * @author       Smiley <[email protected]>
8
 * @copyright    2016 Smiley
9
 * @license      MIT
10
 */
11
12
namespace chillerlan\TinyCurlTest;
13
14
use chillerlan\TinyCurl\Request;
15
use chillerlan\TinyCurl\RequestOptions;
16
17
class ExtractUrlTest extends \PHPUnit_Framework_TestCase{
18
19
	/**
20
	 * @var \chillerlan\TinyCurl\Request
21
	 */
22
	protected $requestWithCA;
23
24
	/**
25
	 * @var \chillerlan\TinyCurl\Request
26
	 */
27
	protected $requestNoCA;
28
29
	protected function setUp(){
30
		$co = [CURLOPT_FOLLOWLOCATION => false];
31
32
		$o1 = new RequestOptions;
33
		$o1->curl_options = $co;
34
		$o1->ca_info = __DIR__.'/test-cacert.pem';
35
		$this->requestWithCA = new Request($o1);
36
37
		$o2 = new RequestOptions;
38
		$o2->curl_options = $co;
39
		$this->requestNoCA = new Request($o2);
40
	}
41
42
	public function shortURLDataProvider(){
43
		return [
44
			[
45
				[
46
					'https://t.co/YK4EuyMbl3',
47
					'http://buff.ly/20TJh3q',
48
					'http://www.ebay.com/sch/gillianandersoncharity/m.html?utm_content=buffer5675f&utm_medium=social&utm_source=twitter.com&utm_campaign=buffer',
49
				]
50
			],
51
			[
52
				[
53
					'https://t.co/ZSS6nVOcVp', // i wonder how long twitter will store this URL since the test tweet has been deleted
54
					'http://bit.ly/1oesmr8',
55
					'http://tinyurl.com/jvc5y98',
56
					'https://api.guildwars2.com/v2/build',
57
				],
58
			],
59
			[
60
				[
61
					'http://curl.haxx.se/ca/cacert.pem',
62
					'https://curl.haxx.se/ca/cacert.pem',
63
64
					// grabbing the body is perhaps a little too greedy...
65
#					'http://hg.mozilla.org/releases/mozilla-release/raw-file/default/security/nss/lib/ckfw/builtins/certdata.txt',
66
#					'http://mozilla.org/MPL/2.0/',
67
#					'https://www.mozilla.org/MPL/2.0/',
68
#					'https://www.mozilla.org/en-US/MPL/2.0/',
69
#					'http://html5shim.googlecode.com/svn/trunk/html5.js',
70
				],
71
			],
72
		];
73
	}
74
75
	/**
76
	 * @dataProvider shortURLDataProvider
77
	 */
78
	public function testExtractShortUrlWithCA($expected){
79
			$this->assertEquals($expected, $this->requestWithCA->extractShortUrl($expected[0]));
80
		}
81
82
	/**
83
	 * @dataProvider shortURLDataProvider
84
	 */
85
		public function testExtractShortUrlNoCA($expected){
86
			$this->assertEquals($expected, $this->requestNoCA->extractShortUrl($expected[0]));
87
		}
88
89
}
90