|
| 1 | +<?php declare(strict_types=1); |
| 2 | + |
| 3 | +namespace Alamirault\FFTTApi\Tests\Unit\Service\Operation; |
| 4 | + |
| 5 | +use Alamirault\FFTTApi\Service\FFTTClient; |
| 6 | +use Alamirault\FFTTApi\Service\Operation\ListRencontreOperation; |
| 7 | +use Alamirault\FFTTApi\Service\UriGenerator; |
| 8 | +use GuzzleHttp\Client; |
| 9 | +use GuzzleHttp\HandlerStack; |
| 10 | +use GuzzleHttp\Psr7\Response; |
| 11 | +use PHPUnit\Framework\TestCase; |
| 12 | + |
| 13 | +/** |
| 14 | + * @coversDefaultClass \Alamirault\FFTTApi\Service\Operation\ListRencontreOperation |
| 15 | + */ |
| 16 | +final class ListRencontreOperationTest extends TestCase |
| 17 | +{ |
| 18 | + /** |
| 19 | + * @covers ::listRencontrePouleByLienDivision |
| 20 | + * This test covers the special case of the beginning of phase : D3 teams are assigned in pools that are not yet finalized and therefore empty just for a few hours (hence the cx_poule parameter is not defined in the lien_division param) |
| 21 | + */ |
| 22 | + public function testListRencontrePouleByLienDivisionNoTours(): void |
| 23 | + { |
| 24 | + /** @var string $responseContent */ |
| 25 | + $responseContent = '<?xml version="1.0" encoding="ISO-8859-1"?><liste></liste>'; |
| 26 | + $mock = new MockHandlerStub([ |
| 27 | + new Response(200, [ |
| 28 | + 'content-type' => ['text/html; charset=UTF-8'], |
| 29 | + ], $responseContent), |
| 30 | + ]); |
| 31 | + |
| 32 | + $handlerStack = HandlerStack::create($mock); |
| 33 | + $client = new Client(['handler' => $handlerStack]); |
| 34 | + $FFTTClient = new FFTTClient($client, new UriGenerator('foo', 'bar')); |
| 35 | + |
| 36 | + $operation = new ListRencontreOperation($FFTTClient); |
| 37 | + |
| 38 | + $result = $operation->listRencontrePouleByLienDivision('cx_poule=&D1=106641&organisme_pere=105'); |
| 39 | + |
| 40 | + $this->assertCount(0, $result); |
| 41 | + $this->assertEquals([], $result); |
| 42 | + } |
| 43 | + |
| 44 | + /** |
| 45 | + * @covers ::listRencontrePouleByLienDivision |
| 46 | + */ |
| 47 | + public function testListRencontrePouleByLienDivisionWithTours(): void |
| 48 | + { |
| 49 | + /** @var string $responseContent */ |
| 50 | + $responseContent = file_get_contents(__DIR__.'/../fixtures/rencontres_by_lien_division.xml'); |
| 51 | + $mock = new MockHandlerStub([ |
| 52 | + new Response(200, [ |
| 53 | + 'content-type' => ['text/html; charset=UTF-8'], |
| 54 | + ], $responseContent), |
| 55 | + ]); |
| 56 | + |
| 57 | + $handlerStack = HandlerStack::create($mock); |
| 58 | + $client = new Client(['handler' => $handlerStack]); |
| 59 | + $FFTTClient = new FFTTClient($client, new UriGenerator('foo', 'bar')); |
| 60 | + |
| 61 | + $operation = new ListRencontreOperation($FFTTClient); |
| 62 | + |
| 63 | + $result = $operation->listRencontrePouleByLienDivision('cx_poule=450762&D1=112049&organisme_pere=16'); |
| 64 | + |
| 65 | + $this->assertCount(28, $result); |
| 66 | + |
| 67 | + $firstTour = $result[0]; |
| 68 | + $this->assertSame('Poule 4 - tour n°1 du 16/12/2022', $firstTour->getLibelle()); |
| 69 | + $this->assertSame('HERBLAY (2)', $firstTour->getNomEquipeA()); |
| 70 | + $this->assertSame('CHAMBLY (1)', $firstTour->getNomEquipeB()); |
| 71 | + $this->assertSame(82, $firstTour->getScoreEquipeA()); |
| 72 | + $this->assertSame(80, $firstTour->getScoreEquipeB()); |
| 73 | + $this->assertSame('renc_id=1568691&is_retour=0&phase=1&res_1=82&res_2=80&equip_1=HERBLAY+%282%29&equip_2=CHAMBLY+%281%29&equip_id1=19936&equip_id2=19995&clubnum_1=08950479&clubnum_2=08950092', $firstTour->getLien()); |
| 74 | + |
| 75 | + $fithTour = $result[4]; |
| 76 | + $this->assertSame('Poule 4 - tour n°2 du 27/01/2023', $fithTour->getLibelle()); |
| 77 | + $this->assertSame('MONTSOULT (1)', $fithTour->getNomEquipeA()); |
| 78 | + $this->assertSame('HERBLAY (2)', $fithTour->getNomEquipeB()); |
| 79 | + $this->assertSame(0, $fithTour->getScoreEquipeA()); |
| 80 | + $this->assertSame(0, $fithTour->getScoreEquipeB()); |
| 81 | + $this->assertSame('renc_id=1568695&is_retour=0&phase=1&res_1=&res_2=&equip_1=MONTSOULT+%281%29&equip_2=HERBLAY+%282%29&equip_id1=19929&equip_id2=19936&clubnum_1=08950531&clubnum_2=08950479', $fithTour->getLien()); |
| 82 | + } |
| 83 | +} |
0 commit comments