Skip to content
This repository has been archived by the owner on Jul 10, 2022. It is now read-only.

Commit

Permalink
PHPUnit Test
Browse files Browse the repository at this point in the history
  • Loading branch information
GoneTone committed Jun 10, 2021
1 parent 7799ffc commit e8683c1
Show file tree
Hide file tree
Showing 5 changed files with 164 additions and 0 deletions.
30 changes: 30 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
name: CI

on: [push]

jobs:
test:
runs-on: ${{ matrix.operating-system }}

strategy:
matrix:
operating-system: [ubuntu-latest]
php-versions: ['7.2', '7.3', '7.4']

name: PHP ${{ matrix.php-versions }} Test on ${{ matrix.operating-system }}
steps:
- name: Checkout
uses: actions/checkout@v2

- name: Install Dependencies
uses: php-actions/composer@v5
with:
php_version: ${{ matrix.php-versions }}

- name: PHPUnit Tests
uses: php-actions/phpunit@v2
with:
version: 8.0.0
php_version: ${{ matrix.php-versions }}
configuration: phpunit.xml
bootstrap: vendor/autoload.php
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/.idea/
/vendor/
/composer.lock
/.phpunit.result.cache
4 changes: 4 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,10 @@
}
},
"scripts": {
"test": "phpunit -c phpunit.xml",
"example": "@php ./examples/cli/all_demo.php"
},
"require-dev": {
"phpunit/phpunit": "8"
}
}
8 changes: 8 additions & 0 deletions phpunit.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit colors="true">
<testsuites>
<testsuite name="main">
<directory>tests</directory>
</testsuite>
</testsuites>
</phpunit>
121 changes: 121 additions & 0 deletions tests/HiNetHichannelTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,121 @@
<?php
/**
* Copyright 2021 GoneTone
*
* HiNet hichannel 台灣電台
* https://github.com/GoneToneStudio/php-hinet-hichannel-taiwan-radio
*
* @author 張文相 Zhang Wenxiang (旋風之音 GoneTone) <https://blog.reh.tw>
* @license MIT <https://github.com/GoneToneStudio/php-hinet-hichannel-taiwan-radio/blob/master/LICENSE>
*
* HiNetHichannel Test
*/

use GoneTone\HiNetHichannel;
use PHPUnit\Framework\TestCase;

/**
* Class ShrinkURLTest
*/
class HiNetHichannelTest extends TestCase
{
protected $_hichannel;

/**
* @throws Exception
*/
protected function setUp(): void {
$this->_hichannel = new HiNetHichannel("KISS RADIO 大眾廣播電台");
$this->_hichannel->loadApi();
}

/**
* 測試取得播放網址 (m3u8)
*
* @throws Exception
*/
public function testGetPlayUrl() {
$playUrl = $this->_hichannel->playUrl();
$this->assertRegExp("/https?:\/\/(([a-zA-Z]|[a-zA-Z][a-zA-Z0-9\-]*[a-zA-Z0-9])\.)*([A-Za-z]|[A-Za-z][A-Za-z0-9\-]*[A-Za-z0-9])\/live\/[a-zA-Z0-9]+\/chunklist\.m3u8\?token=(.*)&expires=(.*)/i", $playUrl);
}

/**
* 測試取得頻道名稱
*
* @throws Exception
*/
public function testGetTitle() {
$title = $this->_hichannel->title();
$this->assertIsString($title);
}

/**
* 測試取得頻道 ID
*
* @throws Exception
*/
public function testGetId() {
$id = $this->_hichannel->id();
$this->assertIsString($id);
}

/**
* 測試取得頻道描述
*
* @throws Exception
*/
public function testGetDesc() {
$desc = $this->_hichannel->desc();
$this->assertIsString($desc);
}

/**
* 測試取得頻道區域
*
* @throws Exception
*/
public function testGetArea() {
$area = $this->_hichannel->area();
$this->assertIsString($area);
}

/**
* 測試取得頻道類型
*
* @throws Exception
*/
public function testGetType() {
$type = $this->_hichannel->type();
$this->assertIsString($type);
}

/**
* 測試取得頻道圖片網址
*
* @throws Exception
*/
public function testGetImageUrl() {
$imageUrl = $this->_hichannel->imageUrl();
$this->assertRegExp("/https?:\/\/(www\.)?[-a-zA-Z0-9@:%._\+~#=]{1,256}\.[a-zA-Z0-9()]{1,6}\b([-a-zA-Z0-9()@:%_\+.~#?&\/=]*)/i", $imageUrl);
}

/**
* 測試取得頻道目前節目名稱
*
* @throws Exception
*/
public function testGetNowProgramName() {
$nowProgramName = $this->_hichannel->nowProgramName();
$this->assertIsString($nowProgramName);
}

/**
* 測試取得頻道節目表
*
* @throws Exception
*/
public function testGetProgramList() {
$programList = $this->_hichannel->programList();
$this->assertIsArray($programList);
}
}

0 comments on commit e8683c1

Please sign in to comment.