WIP
This commit is contained in:
113
tests/Core/IniFileTest.php
Normal file
113
tests/Core/IniFileTest.php
Normal file
@@ -0,0 +1,113 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* Copyright (c) 2025, Антон Аксенов
|
||||
* This file is part of m3u.su project
|
||||
* MIT License: https://git.axenov.dev/IPTV/web/src/branch/master/LICENSE
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Tests\Core;
|
||||
|
||||
use App\Core\IniFile;
|
||||
use App\Exceptions\FileReadException;
|
||||
use App\Exceptions\IniParsingException;
|
||||
use App\Exceptions\PlaylistNotFoundException;
|
||||
use Tests\BaseTestCase;
|
||||
use Tests\FixtureHandler;
|
||||
|
||||
class IniFileTest extends BaseTestCase
|
||||
{
|
||||
use FixtureHandler;
|
||||
|
||||
/**
|
||||
* Проверяет успешное создание объекта, чтение и парсинг файла
|
||||
*
|
||||
* @return void
|
||||
* @throws FileReadException
|
||||
* @throws IniParsingException
|
||||
*/
|
||||
public function testMain(): void
|
||||
{
|
||||
$ini = $this->makeIni();
|
||||
$ini = new IniFile($ini);
|
||||
|
||||
$this->assertNotNull($ini->updatedAt());
|
||||
}
|
||||
|
||||
/**
|
||||
* Проверяет исключение при попытке чтения ini-файла по некорректнмоу пути
|
||||
*
|
||||
* @return void
|
||||
* @throws FileReadException
|
||||
* @throws IniParsingException
|
||||
*/
|
||||
public function testFileReadException(): void
|
||||
{
|
||||
$this->expectException(FileReadException::class);
|
||||
$this->expectExceptionMessage('Ошибка чтения файла');
|
||||
$ini = '';
|
||||
|
||||
new IniFile($ini);
|
||||
}
|
||||
|
||||
/**
|
||||
* Проверяет исключение при попытке парсинга битого ini-файла
|
||||
*
|
||||
* @return void
|
||||
* @throws FileReadException
|
||||
* @throws IniParsingException
|
||||
*/
|
||||
public function testIniParsingException(): void
|
||||
{
|
||||
$this->expectException(IniParsingException::class);
|
||||
$this->expectExceptionMessage('Ошибка разбора файла');
|
||||
$ini = $this->makeIni('z]');
|
||||
|
||||
new IniFile($ini);
|
||||
}
|
||||
|
||||
/**
|
||||
* Проверяет успешное получение определение плейлиста из ini-файла
|
||||
*
|
||||
* @return void
|
||||
* @throws FileReadException
|
||||
* @throws IniParsingException
|
||||
* @throws PlaylistNotFoundException
|
||||
*/
|
||||
public function testGetPlaylist(): void
|
||||
{
|
||||
$ini = $this->makeIni();
|
||||
$ini = new IniFile($ini);
|
||||
$isset = isset($ini['foo']);
|
||||
$foo = $ini->playlist('foo');
|
||||
$foo2 = $ini['foo'];
|
||||
|
||||
$this->assertTrue($isset);
|
||||
$this->assertIsArray($foo);
|
||||
$this->assertSame('foo name', $foo['name']);
|
||||
$this->assertSame('foo description', $foo['desc']);
|
||||
$this->assertSame('http://example.com/foo.m3u', $foo['url']);
|
||||
$this->assertSame('http://example.com/', $foo['src']);
|
||||
$this->assertSame($foo, $foo2);
|
||||
}
|
||||
|
||||
/**
|
||||
* Проверяет исключение при попытке парсинга битого ini-файла
|
||||
*
|
||||
* @return void
|
||||
* @throws FileReadException
|
||||
* @throws PlaylistNotFoundException
|
||||
* @throws IniParsingException
|
||||
*/
|
||||
public function testPlaylistNotFoundException(): void
|
||||
{
|
||||
$code = 'test';
|
||||
$this->expectException(PlaylistNotFoundException::class);
|
||||
$this->expectExceptionMessage("Плейлист '{$code}' не найден");
|
||||
$ini = $this->makeIni();
|
||||
|
||||
(new IniFile($ini))->playlist($code);
|
||||
}
|
||||
}
|
||||
111
tests/Core/PlaylistTest.php
Normal file
111
tests/Core/PlaylistTest.php
Normal file
@@ -0,0 +1,111 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* Copyright (c) 2025, Антон Аксенов
|
||||
* This file is part of m3u.su project
|
||||
* MIT License: https://git.axenov.dev/IPTV/web/src/branch/master/LICENSE
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Tests\Core;
|
||||
|
||||
use App\Core\IniFile;
|
||||
use App\Core\Playlist;
|
||||
use App\Exceptions\FileReadException;
|
||||
use App\Exceptions\IniParsingException;
|
||||
use App\Exceptions\PlaylistNotFoundException;
|
||||
use App\Exceptions\PlaylistWithoutUrlException;
|
||||
use Redis;
|
||||
use Tests\BaseTestCase;
|
||||
use Tests\FixtureHandler;
|
||||
|
||||
class PlaylistTest extends BaseTestCase
|
||||
{
|
||||
use FixtureHandler;
|
||||
|
||||
/**
|
||||
* Проверяет успешное создание объекта
|
||||
*
|
||||
* @return void
|
||||
* @throws FileReadException
|
||||
* @throws IniParsingException
|
||||
* @throws PlaylistNotFoundException
|
||||
*/
|
||||
public function testMain(): void
|
||||
{
|
||||
$code = 'foo';
|
||||
$ini = new IniFile($this->makeIni());
|
||||
$definition = $ini->playlist($code);
|
||||
|
||||
$pls = new Playlist($code, $definition);
|
||||
|
||||
$this->assertSame($code, $pls->code);
|
||||
$this->assertSame($definition['name'], $pls->name);
|
||||
$this->assertSame($definition['desc'], $pls->desc);
|
||||
$this->assertSame($definition['url'], $pls->url);
|
||||
$this->assertSame($definition['src'], $pls->src);
|
||||
}
|
||||
|
||||
/**
|
||||
* Проверяет успешное создание объекта при отсутствии значений опциональных параметров
|
||||
*
|
||||
* @return void
|
||||
* @throws FileReadException
|
||||
* @throws IniParsingException
|
||||
* @throws PlaylistNotFoundException
|
||||
*/
|
||||
public function testOptionalParams(): void
|
||||
{
|
||||
$code = 'foo';
|
||||
$ini = new IniFile($this->makeIni());
|
||||
$definition = $ini->playlist($code);
|
||||
unset($definition['name']);
|
||||
unset($definition['desc']);
|
||||
unset($definition['src']);
|
||||
|
||||
$pls = new Playlist($code, $definition);
|
||||
|
||||
$this->assertSame($code, $pls->code);
|
||||
$this->assertNull($pls->name);
|
||||
$this->assertNull($pls->desc);
|
||||
$this->assertSame($definition['url'], $pls->url);
|
||||
$this->assertNull($pls->src);
|
||||
}
|
||||
|
||||
/**
|
||||
* Проверяет исключение при попытке чтения ini-файла по некорректнмоу пути
|
||||
*
|
||||
* @return void
|
||||
* @throws FileReadException
|
||||
* @throws IniParsingException
|
||||
* @throws PlaylistNotFoundException
|
||||
*/
|
||||
public function testPlaylistWithoutUrlException(): void
|
||||
{
|
||||
$code = 'foo';
|
||||
$this->expectException(PlaylistWithoutUrlException::class);
|
||||
$this->expectExceptionMessage("Плейлист '{$code}' имеет неверный url");
|
||||
$ini = new IniFile($this->makeIni());
|
||||
$definition = $ini->playlist($code);
|
||||
unset($definition['url']);
|
||||
|
||||
new Playlist($code, $definition);
|
||||
}
|
||||
|
||||
public function testGetCheckResult(): void
|
||||
{
|
||||
$code = 'foo';
|
||||
$ini = new IniFile($this->makeIni());
|
||||
|
||||
$definition = $ini->playlist($code);
|
||||
$pls = new Playlist($code, $definition);
|
||||
|
||||
$redis = $this->createPartialMock(Redis::class, ['get']);
|
||||
$redis->expects($this->once())->method('get')->with($code)->willReturn(null);
|
||||
|
||||
|
||||
$pls->getCheckResult();
|
||||
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user