Skip to content

Commit e073f5a

Browse files
Better tests
1 parent afcb2a9 commit e073f5a

File tree

2 files changed

+65
-19
lines changed

2 files changed

+65
-19
lines changed

src/Detector/VideoServiceDetector.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ public function getServiceContainer()
6767
/**
6868
* @param ServicesContainer $serviceContainer
6969
*/
70-
public function setServiceContainer($serviceContainer)
70+
public function setServiceContainer(ServicesContainer $serviceContainer)
7171
{
7272
$this->serviceContainer = $serviceContainer;
7373
}

test/Detector/ServiceDetectorTest.php

Lines changed: 64 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -9,62 +9,108 @@
99
namespace RicardoFiorani\Test;
1010

1111
use PHPUnit_Framework_TestCase;
12+
use RicardoFiorani\Container\Factory\ServicesContainerFactory;
1213
use RicardoFiorani\Detector\VideoServiceDetector;
1314
use RicardoFiorani\Exception\ServiceNotAvailableException;
1415

1516
class ServiceDetectorTest extends PHPUnit_Framework_TestCase
1617
{
1718
/**
18-
* @dataProvider youtubeDataProvider
19+
* @dataProvider videoUrlProvider
1920
* @param $url
20-
* @param $expectedEmbedCode
21+
* @param $expectedServiceName
2122
* @throws ServiceNotAvailableException
2223
*/
23-
public function testCanParseYoutubeUrl($url, $expectedEmbedCode)
24+
public function testCanParseUrl($url, $expectedServiceName)
2425
{
2526
$detector = new VideoServiceDetector();
2627
$video = $detector->parse($url);
27-
$this->assertEquals($video->getEmbedUrl(), $expectedEmbedCode);
28+
$this->assertInstanceOf($expectedServiceName, $video);
2829
}
2930

30-
public function youtubeDataProvider()
31+
/**
32+
* @return array
33+
*/
34+
public function videoUrlProvider()
3135
{
3236

3337
return array(
3438
'Normal Youtube URL' => array(
3539
'https://www.youtube.com/watch?v=mWRsgZuwf_8',
36-
'http://www.youtube.com/embed/mWRsgZuwf_8',
40+
'\\RicardoFiorani\\Adapter\\Youtube\\YoutubeServiceAdapter',
3741
),
3842
'Short Youtube URL' => array(
3943
'https://youtu.be/JMLBOKVfHaA',
40-
'http://www.youtube.com/embed/JMLBOKVfHaA',
44+
'RicardoFiorani\\Adapter\\Youtube\\YoutubeServiceAdapter',
4145
),
4246
'Embed Youtube URL' => array(
4347
'<iframe width="420" height="315" src="https://www.youtube.com/embed/vwp9JkaESdg" frameborder="0" allowfullscreen></iframe>',
44-
'http://www.youtube.com/embed/vwp9JkaESdg',
48+
'\\RicardoFiorani\\Adapter\\Youtube\\YoutubeServiceAdapter',
49+
),
50+
'Common Vimeo URL' => array(
51+
'https://vimeo.com/137781541',
52+
'\\RicardoFiorani\\Adapter\\Vimeo\\VimeoServiceAdapter',
53+
),
54+
'Commom Dailymotion URL' => array(
55+
'http://www.dailymotion.com/video/x332a71_que-categoria-jogador-lucas-lima-faz-golaco-em-treino-do-santos_sport',
56+
'\\RicardoFiorani\\Adapter\\Dailymotion\\DailyMotionServiceAdapter',
4557
),
4658
);
4759
}
4860

4961
/**
50-
* @dataProvider vimeoDataProvider
51-
* @param string $url
52-
* @param string $expectedEmbedCode
62+
* @throws ServiceNotAvailableException
63+
* @dataProvider invalidVideoUrlProvider
5364
*/
54-
public function testCanParseVimeoUrl($url, $expectedEmbedCode)
65+
public function testThrowsExceptionOnInvalidUrl($url)
5566
{
5667
$detector = new VideoServiceDetector();
68+
$this->setExpectedException('\\RicardoFiorani\\Exception\\ServiceNotAvailableException');
5769
$video = $detector->parse($url);
58-
$this->assertEquals($video->getEmbedUrl(), $expectedEmbedCode);
5970
}
6071

61-
public function vimeoDataProvider()
72+
/**
73+
* @return array
74+
*/
75+
public function invalidVideoUrlProvider($url)
6276
{
6377
return array(
64-
'Common Vimeo URL' => array(
65-
'https://vimeo.com/137781541',
66-
'http://player.vimeo.com/video/137781541'
67-
)
78+
array(
79+
'http://tvuol.uol.com.br/video/dirigindo-pelo-mundo-de-final-fantasy-xv-0402CC9B3764E4A95326',
80+
),
81+
array(
82+
'https://www.google.com.br/',
83+
),
84+
array(
85+
'https://www.youtube.com/',
86+
),
6887
);
6988
}
89+
90+
/**
91+
* @dataProvider videoUrlProvider
92+
*/
93+
public function testServiceDetectorDontReparseSameUrl($url)
94+
{
95+
$detector = new VideoServiceDetector();
96+
$video = $detector->parse($url);
97+
98+
$this->assertSame($video, $detector->parse($url));
99+
}
100+
101+
public function testServiceContainerGetter()
102+
{
103+
$detector = new VideoServiceDetector();
104+
$this->assertInstanceOf('RicardoFiorani\\Container\\ServicesContainer', $detector->getServiceContainer());
105+
}
106+
107+
public function testServiceContainerSetter()
108+
{
109+
$detector = new VideoServiceDetector();
110+
$serviceContainer = ServicesContainerFactory::createNewServiceDetector();
111+
$detector->setServiceContainer($serviceContainer);
112+
$this->assertSame($serviceContainer, $detector->getServiceContainer());
113+
}
114+
115+
70116
}

0 commit comments

Comments
 (0)