├── .travis.yml ├── .gitignore ├── phpunit.xml.dist ├── LICENSE ├── composer.json ├── tests └── Faker │ └── YoutubeTest.php ├── src └── Youtube.php └── README.md /.travis.yml: -------------------------------------------------------------------------------- 1 | language: php 2 | 3 | php: 4 | - '7.1' 5 | - '7.2' 6 | - '7.3' 7 | - '7.4' 8 | - '8.0' 9 | 10 | before_script: 11 | - composer install --dev 12 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Created by .ignore support plugin (hsz.mobi) 2 | ### Composer template 3 | composer.phar 4 | vendor/ 5 | clover.xml 6 | phpunit.xml 7 | 8 | # Commit your application's lock file http://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file 9 | # You may choose to ignore a library lock file http://getcomposer.org/doc/02-libraries.md#lock-file 10 | composer.lock 11 | 12 | 13 | -------------------------------------------------------------------------------- /phpunit.xml.dist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | tests 5 | 6 | 7 | 8 | 9 | ./src 10 | 11 | 12 | 13 | 14 | 15 | 16 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE 2 | Version 2, December 2004 3 | 4 | Copyright (C) 2004 Sam Hocevar 5 | 6 | Everyone is permitted to copy and distribute verbatim or modified 7 | copies of this license document, and changing it is allowed as long 8 | as the name is changed. 9 | 10 | DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE 11 | TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION 12 | 13 | 0. You just DO WHAT THE FUCK YOU WANT TO. -------------------------------------------------------------------------------- /composer.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "aalaap/faker-youtube", 3 | "description": "Faker provider for generating fake YouTube video URLs", 4 | "license": "WTFPL", 5 | "authors": [ 6 | { 7 | "name": "Aalaap Ghag", 8 | "email": "aalaap@gmail.com" 9 | } 10 | ], 11 | "keywords": ["faker", "provider", "youtube"], 12 | "require": { 13 | "php": "^7.1 || ^8.0", 14 | "fakerphp/faker": "^1.10" 15 | }, 16 | "require-dev": { 17 | "phpunit/phpunit": "^7.5.20 || ^8.5.8 || ^9.4.2" 18 | }, 19 | "autoload": { 20 | "psr-4": { 21 | "Faker\\Provider\\": "src/" 22 | } 23 | }, 24 | "autoload-dev": { 25 | "psr-4": { 26 | "Faker\\Tests\\Provider\\": "tests/Faker" 27 | } 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /tests/Faker/YoutubeTest.php: -------------------------------------------------------------------------------- 1 | addProvider(new Youtube($faker)); 22 | $this->faker = $faker; 23 | } 24 | 25 | public function testYoutubeUri(): void 26 | { 27 | $this->assertRegExp('#(http(s)??\:\/\/)?(www\.)?(youtube\.com\/watch\?v=)(.+)#', $this->faker->youtubeUri()); 28 | } 29 | 30 | public function testYoutubeShortUri(): void 31 | { 32 | $this->assertRegExp('#(http(s)??\:\/\/)?(www\.)?(youtu.be\/)(.+)#', $this->faker->youtubeShortUri()); 33 | } 34 | 35 | public function testYoutubeEmbedUri(): void 36 | { 37 | $this->assertRegExp('#(http(s)??\:\/\/)?(www\.)?(youtube\.com\/embed\/)(.+)#', $this->faker->youtubeEmbedUri()); 38 | } 39 | 40 | public function testYoutubeChannelUri(): void 41 | { 42 | $this->assertRegExp('#(http(s)??\:\/\/)?(www\.)?(youtube\.com\/)(c\/|channel\/|user\/)([a-zA-Z0-9\-]{1,})#', $this->faker->youtubeChannelUri()); 43 | } 44 | 45 | public function testYoutubeEmbedCode(): void 46 | { 47 | $this->assertRegExp('#'; 37 | } 38 | 39 | public function youtubeChannelUri() 40 | { 41 | return sprintf('https://www.youtube.com/%s/%s', 42 | $this->randomElement(['channel', 'user']), 43 | $this->regexify(sprintf('[a-zA-Z0-9\-]{1,%s}', $this->numberBetween(1, 20))) 44 | ); 45 | } 46 | 47 | public function youtubeRandomUri() 48 | { 49 | switch ($this->numberBetween(1,3)) { 50 | case 1: 51 | return $this->youtubeUri(); 52 | 53 | break; 54 | 55 | case 2: 56 | return $this->youtubeShortUri(); 57 | 58 | break; 59 | 60 | case 3: 61 | return $this->youtubeEmbedUri(); 62 | 63 | break; 64 | 65 | default: 66 | return $this->youtubeUri(); 67 | 68 | break; 69 | } 70 | } 71 | } 72 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | YouTube Provider for Faker 2 | --- 3 | 4 | This package will allow [Faker](https://github.com/FakerPHP/Faker) to generate 5 | fake, but technically valid, YouTube URLs in various formats as well as an embed 6 | HTML. 7 | 8 | YouTube's hashing algorithm ensures that the possibility of collisions is really 9 | low, so the chances of a random URI generated by this packge being a real video 10 | is also really low, but not impossible. 11 | 12 | [![Build Status](https://travis-ci.org/aalaap/faker-youtube.svg?branch=master)](https://travis-ci.org/aalaap/faker-youtube) 13 | 14 | ## Upgrading to the new Faker? 15 | 16 | Since the [original Faker](https://github.com/fzaninotto/Faker) was [sunsetted](https://marmelab.com/blog/2020/10/21/sunsetting-faker.html), 17 | this package was updated to 2.0 to work with the new Faker, bringing along 18 | updated version requirements, which now apply to this package as well. 19 | 20 | - `php`: ^7.1 || ^8.0 21 | - `phpunit/phpunit`: ^7.5.20 || ^8.5.8 || ^9.4.2 22 | 23 | If you are still using the original Faker, you can continue to use versions 1.x 24 | of this package. 25 | 26 | ## Install 27 | 28 | To install, use composer: 29 | 30 | ```bash 31 | composer require aalaap/faker-youtube 32 | ``` 33 | 34 | ## Use 35 | 36 | ```php 37 | # When installed via composer 38 | require_once 'vendor/autoload.php'; 39 | 40 | $faker = \Faker\Factory::create(); 41 | $faker->addProvider(new \Faker\Provider\Youtube($faker)); 42 | ``` 43 | 44 | ``` 45 | echo $faker->youtubeUri(); 46 | // https://www.youtube.com/watch?v=KyXYWQ-B3zO 47 | 48 | echo $faker->youtubeShortUri(); 49 | // https://youtu.be/watch?v=rsPyiZSzj3g 50 | 51 | echo $faker->youtubeEmbedUri(); 52 | // https://www.youtube.com/embed/aUgKvcNS6en 53 | 54 | echo $faker->youtubeEmbedCode(); 55 | // 56 | 57 | echo $faker->youtubeRandomUri(); 58 | // https://youtu.be/watch?v=lctkDb05MKT 59 | ``` 60 | 61 | ## License 62 | 63 | This package is under the WTFPL license. Do whatever you want with it. 64 | 65 | [LICENSE](https://github.com/aalaap/faker-youtube/LICENSE) 66 | 67 | ## Reporting an issue or a feature request 68 | 69 | Fork it, send a PR. Issues and feature requests are tracked in the 70 | [GitHub issue tracker](https://github.com/aalaap/faker-youtube/issues). 71 | --------------------------------------------------------------------------------