Permalink
Browse files

Create unittest with PHPUnit

  • Loading branch information...
Art4 committed May 24, 2017
1 parent 8571ce0 commit e417aebcbcbd16a2d7bf3d86ab63734e5b8de235
Showing with 102 additions and 0 deletions.
  1. +3 −0 .gitignore
  2. +31 −0 composer.json
  3. +27 −0 phpunit.xml.dist
  4. +41 −0 tests/YoutubeDownloaderTest.php
View
@@ -0,0 +1,3 @@
/vendor
composer.phar
composer.lock
View
@@ -0,0 +1,31 @@
{
"name": "jeckman/YouTube-Downloader",
"type": "library",
"description": "YouTube-Downloader",
"homepage": "https://github.com/jeckman/YouTube-Downloader",
"keywords": ["YouTube-Downloader", "YouTube", "Downloader"],
"license": "GPL2",
"authors": [
{
"name": "John Eckman",
"email": "eckman.john@gmail.com",
"homepage": "http://www.openparenthesis.org/"
}
],
"require": {
"php": "^5.4 || ^7.0"
},
"require-dev": {
"phpunit/phpunit": "^4.8.35 || ^6.0"
},
"autoload": {
"psr-4": {
"YoutubeDownloader\\": "src/"
}
},
"autoload-de": {
"psr-4": {
"YoutubeDownloader\\Tests\\": "tests/"
}
}
}
View
@@ -0,0 +1,27 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit backupGlobals="false"
backupStaticAttributes="false"
colors="true"
convertErrorsToExceptions="true"
convertNoticesToExceptions="true"
convertWarningsToExceptions="true"
processIsolation="false"
stopOnFailure="false"
syntaxCheck="false"
stopOnError="false"
stopOnIncomplete="false"
stopOnSkipped="false"
bootstrap="vendor/autoload.php"
>
<testsuites>
<testsuite name="all">
<directory suffix="Test.php">tests/</directory>
</testsuite>
</testsuites>
<filter>
<whitelist>
<directory suffix=".php">src/</directory>
</whitelist>
</filter>
</phpunit>
@@ -0,0 +1,41 @@
<?php
namespace YoutubeDownloader\Tests;
use YoutubeDownloader\YoutubeDownloader;
class YoutubeDownloaderTest extends \PHPUnit\Framework\TestCase
{
/**
* @test validateVideoId()
* @dataProvider VideoIdProvider
*/
public function validateVideoId($str, $expected)
{
$this->assertSame($expected, YoutubeDownloader::validateVideoId($str));
}
/**
* dataprovider for validateVideoId()
*/
public function VideoIdProvider()
{
$id = 'dQw4w9WgXcQ';
return [
['http://youtu.be/dQw4w9WgXcQ', $id],
['http://www.youtube.com/embed/dQw4w9WgXcQ', $id],
['http://www.youtube.com/watch?v=dQw4w9WgXcQ', $id],
['http://www.youtube.com/?v=dQw4w9WgXcQ', $id],
['http://www.youtube.com/v/dQw4w9WgXcQ', $id],
['http://www.youtube.com/e/dQw4w9WgXcQ', $id],
['http://www.youtube.com/user/username#p/u/11/dQw4w9WgXcQ', $id],
['http://www.youtube.com/sandalsResorts#p/c/54B8C800269D7C1B/0/dQw4w9WgXcQ', $id],
['http://www.youtube.com/watch?feature=player_embedded&v=dQw4w9WgXcQ', $id],
['http://www.youtube.com/?feature=player_embedded&v=dQw4w9WgXcQ', $id],
['http://www.youtube.com/v/dQw4w9WgXcQ?fs=1&hl=en_US', $id],
['https://www.youtube-nocookie.com/embed/dQw4w9WgXcQ', $id],
['<iframe width="560" height="315" src="https://www.youtube.com/embed/dQw4w9WgXcQ" frameborder="0" allowfullscreen></iframe>', $id],
];
}
}

0 comments on commit e417aeb

Please sign in to comment.