112 lines
3.2 KiB
PHP
112 lines
3.2 KiB
PHP
<?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();
|
|
|
|
}
|
|
}
|