Skip to content

Commit 0499371

Browse files
author
Dominik Jansen
committed
test: skip facebook and instagram test when tokens are not provided
1 parent e5841e0 commit 0499371

File tree

2 files changed

+24
-5
lines changed

2 files changed

+24
-5
lines changed

tests/PagesTest.php

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@ public function testPages()
3333
$this->assertEmbed('http://www.hookem.com/story/texas-shortstop-joe-baker-arrested-public-intoxication/');
3434
$this->assertEmbed('http://i.imgur.com/X6rkCc5.jpg');
3535
$this->assertEmbed('https://infogr.am/7743c36a-f3ca-4465-9a80-a8abbd5d8dc4');
36-
$this->assertEmbed('https://www.instagram.com/p/ySl7G9tO_q/');
3736
$this->assertEmbed('http://output.jsbin.com/vonesu/10');
3837
$this->assertEmbed('http://jsfiddle.net/zhm5rjnz/');
3938
$this->assertEmbed('https://www.kickstarter.com/projects/1452363698/good-seed-craft-veggie-burgers');
@@ -91,7 +90,11 @@ public function testArchiveOrg()
9190

9291
public function testInstagram()
9392
{
94-
$this->assertEmbed('http://instagram.com/p/ySl7G9tO_q/');
93+
if ($_ENV['INSTAGRAM_TOKEN'] ?? false) {
94+
$this->assertEmbed('http://instagram.com/p/ySl7G9tO_q/');
95+
} else {
96+
self::markTestSkipped('Environment variable `INSTAGRAM_TOKEN` must be provided to test instagram. See https://developers.facebook.com/docs/instagram/oembed/');
97+
}
9598
}
9699

97100
public function testMeetup()
@@ -127,8 +130,12 @@ public function testFlickr()
127130

128131
public function testFacebook()
129132
{
130-
$this->assertEmbed('https://www.facebook.com/permalink.php?story_fbid=827163017327807&id=149460691764713');
131-
$this->assertEmbed('https://www.facebook.com/acolono/videos/10154107990797381/');
133+
if ($_ENV['FACEBOOK_TOKEN'] ?? false) {
134+
$this->assertEmbed('https://www.facebook.com/permalink.php?story_fbid=827163017327807&id=149460691764713');
135+
$this->assertEmbed('https://www.facebook.com/acolono/videos/10154107990797381/');
136+
} else {
137+
self::markTestSkipped('Environment variable `FACEBOOK_TOKEN` must be provided to test facebook. See https://developers.facebook.com/docs/plugins/oembed');
138+
}
132139
}
133140

134141
public function testGithub()

tests/PagesTestCase.php

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
use Datetime;
88
use Embed\Embed;
99
use Embed\Extractor;
10+
use Embed\ExtractorFactory;
1011
use Embed\Http\Crawler;
1112
use JsonSerializable;
1213
use PHPUnit\Framework\TestCase;
@@ -50,7 +51,7 @@ private static function getEmbed(): Embed
5051
$dispatcher = new FileClient(__DIR__.'/cache');
5152
$dispatcher->setMode(static::CACHE);
5253

53-
return self::$embed = new Embed(new Crawler($dispatcher));
54+
return self::$embed = new Embed(new Crawler($dispatcher), self::getExtractorFactory());
5455
}
5556

5657
protected function assertEmbed(string $url)
@@ -65,6 +66,7 @@ protected function assertEmbed(string $url)
6566
if (!$expected || static::FIXTURES === 1) {
6667
self::writeData($uri, $data);
6768
echo PHP_EOL."Save fixture: {$url}";
69+
$this->markTestSkipped('Skipped assertion for '.$url);
6870
} else {
6971
$this->assertEquals($expected, $data, $url);
7072
}
@@ -133,4 +135,14 @@ private static function convert($value)
133135

134136
return $value;
135137
}
138+
139+
private static function getExtractorFactory()
140+
{
141+
$settings = [
142+
'instagram:token' => $_ENV['INSTAGRAM_TOKEN'] ?? null,
143+
'facebook:token' => $_ENV['FACEBOOK_TOKEN'] ?? null,
144+
];
145+
146+
return new ExtractorFactory($settings);
147+
}
136148
}

0 commit comments

Comments
 (0)