добавил несколько парсеров

This commit is contained in:
2024-11-04 20:12:41 +03:00
parent 5344b31f97
commit 1117bd5ddc
2022 changed files with 2235 additions and 190924 deletions

View File

@ -1,91 +0,0 @@
<?php
use ContingentParser\Parser\ContingentParser;
use PHPUnit\Framework\TestCase;
class ContingentParserTest extends TestCase
{
private $parser;
protected function setUp(): void
{
$html = <<< HTML
<table>
<tr itemprop="eduChislen">
<td itemprop="eduCode">09.03.01</td>
<td itemprop="eduName">Информатика и вычислительная техника</td>
<td itemprop="eduLevel">Бакалавриат</td>
<td itemprop="eduForm">Очная</td>
<td itemprop="numberAll">98</td>
</tr>
<tr itemprop="eduChislen">
<td itemprop="eduCode">09.03.04</td>
<td itemprop="eduName">Программная инженерия</td>
<td itemprop="eduLevel">Бакалавриат</td>
<td itemprop="eduForm">Очная</td>
<td itemprop="numberAll">198</td>
</tr>
</table>
HTML;
$this->parser = new ContingentParser($html);
}
public function testParse()
{
$data = $this->parser->getDataTable();
$this->assertArrayHasKey('spec_code', $data[0]);
$this->assertArrayHasKey('spec_name', $data[0]);
$this->assertArrayHasKey('edu_level', $data[0]);
$this->assertArrayHasKey('edu_forms', $data[0]);
$this->assertArrayHasKey('contingent', $data[0]);
}
public function testGetDataTable()
{
$dataTable = $this->parser->getDataTable();
$this->assertCount(2, $dataTable);
$this->assertEquals([
'spec_code' => '09.03.01',
'spec_name' => 'Информатика и вычислительная техника',
'edu_level' => 'Бакалавриат',
'edu_forms' => 'Очная',
'contingent' => 98,
], $dataTable[0]);
$this->assertEquals([
'spec_code' => '09.03.04',
'spec_name' => 'Программная инженерия',
'edu_level' => 'Бакалавриат',
'edu_forms' => 'Очная',
'contingent' => 198,
], $dataTable[1]);
}
public function testGetDataTableEmpty()
{
$parser = new ContingentParser('');
$dataTable = $parser->getDataTable();
$this->assertCount(0, $dataTable);
}
public function testGetDataTableDifferentLengths()
{
$html = <<< HTML
<table>
<tr itemprop="eduChislen">
<td itemprop="eduCode">123</td>
<td itemprop="eduName">Test Edu Name</td>
<td itemprop="eduLevel">Test Edu Level</td>
<td itemprop="eduForm">Test Edu Form</td>
</tr>
<tr itemprop="eduChislen">
<td itemprop="eduCode">456</td>
<td itemprop="eduName">Test Edu Name 2</td>
<td itemprop="eduLevel">Test Edu Level 2</td>
</tr>
</table>
HTML;
$parser = new ContingentParser($html);
$dataTable = $parser->getDataTable();
$this->assertCount(0, $dataTable);
}
}

View File

@ -1,50 +0,0 @@
<?php
use PHPUnit\Framework\TestCase;
use ContingentParser\Parser\ContingentRow;
class ContingentRowTest extends TestCase
{
#[Test]
public function testValidConstructorArguments()
{
$contingentRow = new ContingentRow('eduCode', 'eduName', 'eduLevel', 'eduForm', 10);
$this->assertInstanceOf(ContingentRow::class, $contingentRow);
}
#[Test]
public function testInvalidContingentValue()
{
$this->expectException(\Exception::class);
$this->expectExceptionMessage("Недействительная численность обучающихся!");
new ContingentRow('eduCode', 'eduName', 'eduLevel', 'eduForm', -1);
}
#[Test]
public function testGetDataReturnsExpectedArray()
{
$contingentRow = new ContingentRow('eduCode', 'eduName', 'eduLevel', 'eduForm', 10);
$data = $contingentRow->getData();
$this->assertEquals([
"spec_code" => 'eduCode',
"spec_name" => 'eduName',
"edu_level" => 'eduLevel',
"edu_forms" => 'eduForm',
"contingent" => 10
], $data);
}
#[Test]
public function testConstructorTrimsInputValues()
{
$contingentRow = new ContingentRow(' eduCode ', ' eduName ', ' eduLevel ', ' eduForm ', 10);
$data = $contingentRow->getData();
$this->assertEquals([
"spec_code" => 'eduCode',
"spec_name" => 'eduName',
"edu_level" => 'eduLevel',
"edu_forms" => 'eduForm',
"contingent" => 10
], $data);
}
}

36
tests/test.php Normal file
View File

@ -0,0 +1,36 @@
<?php
use SvedenParser\Color;
use SvedenParser\ContingentParser\ContingentRepository;
use SvedenParser\ContingentParser\ContingentService;
use SvedenParser\Http\HttpClient;
use SvedenParser\Printer;
use Symfony\Component\Console\Output\ConsoleOutput;
define('SVEDEN_PARSER', '/home/developer/sveden_parser');
require_once SVEDEN_PARSER . "/vendor/autoload.php";
use Symfony\Component\Console\Helper\ProgressBar;
$output = new ConsoleOutput();
// creates a new progress bar (50 units)
$progressBar = new ProgressBar($output, 50);
// starts and displays the progress bar
$progressBar->start();
$i = 0;
while ($i++ < 50) {
// ... do some wor
sleep(1);
echo "\r$i \n";
// advances the progress bar 1 unit
$progressBar->advance();
// you can also advance the progress bar by more than 1 unit
// $progressBar->advance(3);
}
// ensures that the progress bar is at 100%
$progressBar->finish();
echo PHP_EOL;

30
tests/test_client.php Normal file
View File

@ -0,0 +1,30 @@
<?php
use SvedenParser\ContingentParser\ContingentManager;
use SvedenParser\ContingentParser\ContingentParser;
use SvedenParser\ContingentParser\ContingentRepository;
use SvedenParser\ContingentParser\ContingentService;
use SvedenParser\EmployeesParser\EmployeesParser;
use SvedenParser\Http\CurlHelper;
use SvedenParser\Http\HttpClient;
use SvedenParser\PriemParser\PriemManager;
use SvedenParser\PriemParser\PriemParser;
define('SVEDEN_PARSER', '/home/developer/sveden_parser');
require_once SVEDEN_PARSER . "/vendor/autoload.php";
// $client = new HttpClient();
// $html = $client->getContentOfSite('https://amchs.ru/', [], '/sveden/education/priem');
$html = file_get_contents(SVEDEN_PARSER . '/data/emp.html');
// $curl = new CurlHelper('https://www.rgiis.ru/sveden/education/', []);
// $html = $curl->getContent();
// echo $html;
$parser = new EmployeesParser($html);
$data = $parser->getDataTable();
// (new ContingentService())->getData(html);
print_r($data);
// print_r();
// (new ContingentRepository())->save($data);
// $manager = new ContingentManager();
// $manager->collectData(['org_id' => 410, 'site' => 'http://www.volgatech.net']);

19
tests/test_conf.php Normal file
View File

@ -0,0 +1,19 @@
<?php
class A {
public $a;
public function y() {
$this->a = new class {
public readonly string $x;
public function d(): void {
$this->x = '1';
}
};
$this->a->d();
echo $this->a->x;
}
}
$a = new A();
$a->y();