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);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user