Skip to content

Commit a98c091

Browse files
tests
1 parent 4221bde commit a98c091

File tree

2 files changed

+75
-3
lines changed

2 files changed

+75
-3
lines changed

test/Adapter/VimeoServiceAdapterTest.php

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -117,8 +117,8 @@ public function testGetEmbedUrl($url)
117117
*/
118118
public function testIfIsEmbeddable($url)
119119
{
120-
$facebookVideo = $this->getMockingObject($url);
121-
$this->assertTrue($facebookVideo->isEmbeddable());
120+
$vimeoVideo = $this->getMockingObject($url);
121+
$this->assertTrue($vimeoVideo->isEmbeddable());
122122
}
123123

124124
/**
@@ -128,7 +128,8 @@ public function exampleUrlDataProvider()
128128
{
129129
return array(
130130
array(
131-
'https://vimeo.com/8733915'
131+
'https://vimeo.com/8733915',
132+
'https://vimeo.com/channels/staffpicks/154766467',
132133
),
133134
);
134135
}

test/Container/ServicesContainerTest.php

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,79 @@
1010

1111

1212
use PHPUnit_Framework_TestCase;
13+
use RicardoFiorani\Container\ServicesContainer;
14+
use stdClass;
1315

1416
class ServicesContainerTest extends PHPUnit_Framework_TestCase
1517
{
18+
public function testServiceContainerServiceRegistrationByArray()
19+
{
20+
$config = $this->getMockConfig();
21+
$serviceContainer = $this->createServiceContainer($config);
22+
$this->assertTrue($serviceContainer->hasService('Youtube'));
23+
$this->assertInstanceOf('\\RicardoFiorani\\Renderer\\DefaultRenderer', $serviceContainer->getRenderer());
24+
}
1625

26+
public function testServiceContainerServiceRegistrationByInjection()
27+
{
28+
$serviceContainer = $this->createServiceContainer();
29+
$serviceContainer->registerService('TestService', array('#testPattern#'), function () {
30+
// @todo test the injected service maybe ?
31+
});
32+
33+
$this->assertContains('TestService', $serviceContainer->getServiceNameList());
34+
$this->setExpectedException('\\RicardoFiorani\\Exception\\DuplicatedServiceNameException');
35+
$serviceContainer->registerService('TestService', array('#testPattern#'), function () {
36+
});
37+
}
38+
39+
public function testServicesList()
40+
{
41+
$config = $this->getMockConfig();
42+
$serviceContainer = $this->createServiceContainer($config);
43+
$this->assertInternalType('array', $serviceContainer->getServices());
44+
$this->assertContains('Youtube', $serviceContainer->getServices());
45+
}
46+
47+
public function testIfReturnsAlreadyInstantiatedFactory(){
48+
$config = $this->getMockConfig();
49+
$serviceContainer = $this->createServiceContainer($config);
50+
$factory = $serviceContainer->getFactory('Youtube');
51+
$this->assertInstanceOf('\\RicardoFiorani\\Adapter\\Youtube\\Factory\\YoutubeServiceAdapterFactory',$factory);
52+
53+
$alreadyInstantiatedFactory = $serviceContainer->getFactory('Youtube');
54+
$this->assertEquals($factory,$alreadyInstantiatedFactory);
55+
}
56+
57+
/**
58+
* @return ServicesContainer
59+
*/
60+
private function createServiceContainer(array $constructArray = array())
61+
{
62+
$serviceContainer = new ServicesContainer($constructArray);
63+
64+
return $serviceContainer;
65+
}
66+
67+
/**
68+
* @return array
69+
*/
70+
private function getMockConfig()
71+
{
72+
return array(
73+
'services' => array(
74+
'Youtube' => array(
75+
'patterns' => array(
76+
'#(?:<\>]+href=\")?(?:http://)?((?:[a-zA-Z]{1,4}\.)?youtube.com/(?:watch)?\?v=(.{11}?))[^"]*(?:\"[^\<\>]*>)?([^\<\>]*)(?:)?#',
77+
'%(?:youtube\.com/(?:[^/]+/.+/|(?:v|e(?:mbed)?)/|.*[?&]v=)|youtu\.be/)([^"&?/ ]{11})%i',
78+
),
79+
'factory' => '\\RicardoFiorani\\Adapter\\Youtube\\Factory\\YoutubeServiceAdapterFactory',
80+
),
81+
),
82+
'renderer' => array(
83+
'name' => 'DefaultRenderer',
84+
'factory' => '\\RicardoFiorani\\Renderer\\Factory\\DefaultRendererFactory',
85+
)
86+
);
87+
}
1788
}

0 commit comments

Comments
 (0)