68 lines
2.3 KiB
PHP
68 lines
2.3 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace App\Tests\BusProNet\XmlParser;
|
|
|
|
use App\BusProNet\Constants;
|
|
use App\BusProNet\Model\Room;
|
|
use App\BusProNet\XmlParser\AvailabilitiesParser;
|
|
use PHPUnit\Framework\TestCase;
|
|
use Psr\Log\LoggerInterface;
|
|
use Symfony\Component\DomCrawler\Crawler;
|
|
|
|
class AvailabilitiesParserTest extends TestCase
|
|
{
|
|
private AvailabilitiesParser $parser;
|
|
|
|
protected function setUp(): void
|
|
{
|
|
$this->parser = new AvailabilitiesParser();
|
|
}
|
|
|
|
public function testParseRoomsNormalizesHotelAvailabilityStatuses(): void
|
|
{
|
|
$xml = <<<'XML'
|
|
<ergebnis>
|
|
<unterbringungen>
|
|
<unterbringung id_zimmer="1" bezeichnung="Room 1" kategorie="A" verpflegung="Board" frei="1" status="buchbar" preis="749,00" />
|
|
<unterbringung id_zimmer="2" bezeichnung="Room 2" kategorie="B" verpflegung="Board" frei="-900" status="anfrage" preis="849,00" />
|
|
<unterbringung id_zimmer="3" bezeichnung="Room 3" kategorie="C" verpflegung="Board" frei="0" status="stopp" preis="949,00" />
|
|
</unterbringungen>
|
|
</ergebnis>
|
|
XML;
|
|
|
|
$rooms = $this->parser->parseRooms(new Crawler($xml))->getItems();
|
|
|
|
$this->assertContainsOnlyInstancesOf(Room::class, $rooms);
|
|
$this->assertSame(Constants::STATUS_AVAILABLE, $rooms[1]->status);
|
|
$this->assertSame(Constants::STATUS_ON_REQUEST, $rooms[2]->status);
|
|
$this->assertSame(Constants::STATUS_BLOCKED, $rooms[3]->status);
|
|
}
|
|
|
|
public function testParseRoomsLogsUnrecognizedStatus(): void
|
|
{
|
|
$logger = $this->createMock(LoggerInterface::class);
|
|
$logger->expects($this->once())
|
|
->method('warning')
|
|
->with(
|
|
'Unrecognized room availability status from BusProNet XML',
|
|
['status' => 'foo']
|
|
);
|
|
|
|
$parser = new AvailabilitiesParser($logger);
|
|
|
|
$xml = <<<'XML'
|
|
<ergebnis>
|
|
<unterbringungen>
|
|
<unterbringung id_zimmer="1" bezeichnung="Room 1" kategorie="A" verpflegung="Board" frei="1" status="foo" preis="749,00" />
|
|
</unterbringungen>
|
|
</ergebnis>
|
|
XML;
|
|
|
|
$rooms = $parser->parseRooms(new Crawler($xml))->getItems();
|
|
|
|
$this->assertSame('foo', $rooms[1]->status);
|
|
}
|
|
}
|