Skip to content

Commit

Permalink
update test
Browse files Browse the repository at this point in the history
  • Loading branch information
nkwtnb committed Mar 7, 2022
1 parent 53d5378 commit a976d46
Showing 1 changed file with 35 additions and 15 deletions.
50 changes: 35 additions & 15 deletions tests/OgparserTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,29 +2,49 @@

namespace nkwtnb\ogparser\test;

use Exception;
use nkwtnb\ogparser\Ogparser;
use PHPUnit\Framework\TestCase;

class OgparserTest extends TestCase {
protected static $ogp;
/**
* URLが存在する
*/
public function existsUrlTest() {
// URL形式ではない
public function testInvalidURL() {
$this->expectException(Exception::class);
new Ogparser("abcde");
}
/**
* タイトルが取得できる
*/
public function canGetTitleTest() {
// HTTPSではない
public function testNotHttpsURL() {
$this->expectException(Exception::class);
new Ogparser("http://localhost");
}
/**
* 説明が取得できる
*/
public function canGetDescriptionTest() {
// サイトが存在しない
public function testNotExistsURL() {
$this->expectException(Exception::class);
$ogp = new Ogparser("https://localhost-not-exists");
$ogp->fetch();
}
// ページが存在しない
public function testNotExistsPage() {
$this->expectException(Exception::class);
$ogp = new Ogparser("https://www.google.com/not-exists");
$ogp->fetch();
}
/**
* 画像が取得できる
* @doesNotPerformAssertions
*/
public function canGetImageTest() {
// OGPの取得処理が実行できる
public function testCanGetOGP() {
$_URL = getenv("URL");
throw new Exception("specify target url. ex)URL=https://www.example.com phpunit tests");
$ogp = new Ogparser($_URL);
$ogp->fetch();
var_dump(<<<EOM
{$ogp->get_url()}
{$ogp->get_title()}
{$ogp->get_description()}
{$ogp->get_image()}
{$ogp->get_site_name()}
EOM);
}
}

0 comments on commit a976d46

Please sign in to comment.