From d4c9824dfa1300c474397b9b5ad08f6e09318cab Mon Sep 17 00:00:00 2001 From: StephSako Date: Mon, 9 Jan 2023 20:00:55 +0100 Subject: [PATCH] Fix/d3 teams in unfinalized pool (#13) Fix : empty unfinalized pool's list of tours for D3 teams --- .gitignore | 3 +- .../Operation/ListRencontreOperation.php | 59 ++++++------- .../Operation/ListRencontreOperationTest.php | 83 +++++++++++++++++++ .../fixtures/rencontres_by_lien_division.xml | 1 + 4 files changed, 117 insertions(+), 29 deletions(-) create mode 100644 tests/Unit/Service/Operation/ListRencontreOperationTest.php create mode 100644 tests/Unit/Service/fixtures/rencontres_by_lien_division.xml diff --git a/.gitignore b/.gitignore index 2987bc8..acb30cb 100644 --- a/.gitignore +++ b/.gitignore @@ -2,4 +2,5 @@ bin test.php vendor -composer.lock \ No newline at end of file +composer.lock +.php-cs-fixer.cache \ No newline at end of file diff --git a/src/Service/Operation/ListRencontreOperation.php b/src/Service/Operation/ListRencontreOperation.php index 9c9062f..7dd2b80 100644 --- a/src/Service/Operation/ListRencontreOperation.php +++ b/src/Service/Operation/ListRencontreOperation.php @@ -17,36 +17,39 @@ public function __construct( */ public function listRencontrePouleByLienDivision(string $lienDivision): array { - /** @var array|string, equb: array|string, dateprevue:string, datereelle: ?string, libelle: string, scorea: string, scoreb: string, lien: string }> $data */ - $data = $this->client->get('xml_result_equ', [], $lienDivision)['tour']; + $data = $this->client->get('xml_result_equ', [], $lienDivision); $result = []; - foreach ($data as $dataRencontre) { - $equipeA = $dataRencontre['equa']; - $equipeB = $dataRencontre['equb']; - - /** @var string $nomEquipeA */ - $nomEquipeA = is_array($equipeA) ? '' : $equipeA; - - /** @var string $nomEquipeB */ - $nomEquipeB = is_array($equipeB) ? '' : $equipeB; - - /** @var \DateTime $datePrevue */ - $datePrevue = \DateTime::createFromFormat('d/m/Y', $dataRencontre['dateprevue']); - - /** @var \DateTime|null $dateReelle */ - $dateReelle = empty($dataRencontre['datereelle']) ? null : \DateTime::createFromFormat('d/m/Y', $dataRencontre['datereelle']); - - $result[] = new Rencontre( - $dataRencontre['libelle'], - $nomEquipeA, - $nomEquipeB, - (int) $dataRencontre['scorea'], - (int) $dataRencontre['scoreb'], - $dataRencontre['lien'], - $datePrevue, - $dateReelle - ); + if (array_key_exists('tour', $data)) { + /** @var array|string, equb: array|string, dateprevue:string, datereelle: ?string, libelle: string, scorea: string, scoreb: string, lien: string }> $data */ + $data = $data['tour']; + foreach ($data as $dataRencontre) { + $equipeA = $dataRencontre['equa']; + $equipeB = $dataRencontre['equb']; + + /** @var string $nomEquipeA */ + $nomEquipeA = is_array($equipeA) ? '' : $equipeA; + + /** @var string $nomEquipeB */ + $nomEquipeB = is_array($equipeB) ? '' : $equipeB; + + /** @var \DateTime $datePrevue */ + $datePrevue = \DateTime::createFromFormat('d/m/Y', $dataRencontre['dateprevue']); + + /** @var \DateTime|null $dateReelle */ + $dateReelle = empty($dataRencontre['datereelle']) ? null : \DateTime::createFromFormat('d/m/Y', $dataRencontre['datereelle']); + + $result[] = new Rencontre( + $dataRencontre['libelle'], + $nomEquipeA, + $nomEquipeB, + (int) $dataRencontre['scorea'], + (int) $dataRencontre['scoreb'], + $dataRencontre['lien'], + $datePrevue, + $dateReelle + ); + } } return $result; diff --git a/tests/Unit/Service/Operation/ListRencontreOperationTest.php b/tests/Unit/Service/Operation/ListRencontreOperationTest.php new file mode 100644 index 0000000..00f8554 --- /dev/null +++ b/tests/Unit/Service/Operation/ListRencontreOperationTest.php @@ -0,0 +1,83 @@ +'; + $mock = new MockHandlerStub([ + new Response(200, [ + 'content-type' => ['text/html; charset=UTF-8'], + ], $responseContent), + ]); + + $handlerStack = HandlerStack::create($mock); + $client = new Client(['handler' => $handlerStack]); + $FFTTClient = new FFTTClient($client, new UriGenerator('foo', 'bar')); + + $operation = new ListRencontreOperation($FFTTClient); + + $result = $operation->listRencontrePouleByLienDivision('cx_poule=&D1=106641&organisme_pere=105'); + + $this->assertCount(0, $result); + $this->assertEquals([], $result); + } + + /** + * @covers ::listRencontrePouleByLienDivision + */ + public function testListRencontrePouleByLienDivisionWithTours(): void + { + /** @var string $responseContent */ + $responseContent = file_get_contents(__DIR__.'/../fixtures/rencontres_by_lien_division.xml'); + $mock = new MockHandlerStub([ + new Response(200, [ + 'content-type' => ['text/html; charset=UTF-8'], + ], $responseContent), + ]); + + $handlerStack = HandlerStack::create($mock); + $client = new Client(['handler' => $handlerStack]); + $FFTTClient = new FFTTClient($client, new UriGenerator('foo', 'bar')); + + $operation = new ListRencontreOperation($FFTTClient); + + $result = $operation->listRencontrePouleByLienDivision('cx_poule=450762&D1=112049&organisme_pere=16'); + + $this->assertCount(28, $result); + + $firstTour = $result[0]; + $this->assertSame('Poule 4 - tour n°1 du 16/12/2022', $firstTour->getLibelle()); + $this->assertSame('HERBLAY (2)', $firstTour->getNomEquipeA()); + $this->assertSame('CHAMBLY (1)', $firstTour->getNomEquipeB()); + $this->assertSame(82, $firstTour->getScoreEquipeA()); + $this->assertSame(80, $firstTour->getScoreEquipeB()); + $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()); + + $fithTour = $result[4]; + $this->assertSame('Poule 4 - tour n°2 du 27/01/2023', $fithTour->getLibelle()); + $this->assertSame('MONTSOULT (1)', $fithTour->getNomEquipeA()); + $this->assertSame('HERBLAY (2)', $fithTour->getNomEquipeB()); + $this->assertSame(0, $fithTour->getScoreEquipeA()); + $this->assertSame(0, $fithTour->getScoreEquipeB()); + $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()); + } +} diff --git a/tests/Unit/Service/fixtures/rencontres_by_lien_division.xml b/tests/Unit/Service/fixtures/rencontres_by_lien_division.xml new file mode 100644 index 0000000..626d22c --- /dev/null +++ b/tests/Unit/Service/fixtures/rencontres_by_lien_division.xml @@ -0,0 +1 @@ +Poule 4 - tour n°1 du 16/12/2022HERBLAY (2)CHAMBLY (1)828016/12/202216/12/2022Poule 4 - tour n°1 du 16/12/2022MAISONS-LAF. US (1)MONTSOULT (1)926416/12/202216/12/2022Poule 4 - tour n°1 du 16/12/2022ARGENTEUIL (1)FRANCONVILLE (1)6010116/12/202216/12/2022Poule 4 - tour n°1 du 16/12/2022LA FRETTE (1)STAINS ES (1)778516/12/202216/12/2022Poule 4 - tour n°2 du 27/01/2023MONTSOULT (1)HERBLAY (2)27/01/202327/01/2023Poule 4 - tour n°2 du 27/01/2023FRANCONVILLE (1)MAISONS-LAF. US (1)27/01/202327/01/2023Poule 4 - tour n°2 du 27/01/2023STAINS ES (1)ARGENTEUIL (1)27/01/202327/01/2023Poule 4 - tour n°2 du 27/01/2023CHAMBLY (1)LA FRETTE (1)27/01/202327/01/2023Poule 4 - tour n°3 du 10/02/2023HERBLAY (2)FRANCONVILLE (1)10/02/202310/02/2023Poule 4 - tour n°3 du 10/02/2023MAISONS-LAF. US (1)STAINS ES (1)10/02/202310/02/2023Poule 4 - tour n°3 du 10/02/2023ARGENTEUIL (1)LA FRETTE (1)10/02/202310/02/2023Poule 4 - tour n°3 du 10/02/2023CHAMBLY (1)MONTSOULT (1)10/02/202310/02/2023Poule 4 - tour n°4 du 24/03/2023STAINS ES (1)HERBLAY (2)24/03/202324/03/2023Poule 4 - tour n°4 du 24/03/2023LA FRETTE (1)MAISONS-LAF. US (1)24/03/202324/03/2023Poule 4 - tour n°4 du 24/03/2023ARGENTEUIL (1)CHAMBLY (1)24/03/202324/03/2023Poule 4 - tour n°4 du 24/03/2023FRANCONVILLE (1)MONTSOULT (1)24/03/202324/03/2023Poule 4 - tour n°5 du 07/04/2023HERBLAY (2)LA FRETTE (1)07/04/202307/04/2023Poule 4 - tour n°5 du 07/04/2023MAISONS-LAF. US (1)ARGENTEUIL (1)07/04/202307/04/2023Poule 4 - tour n°5 du 07/04/2023MONTSOULT (1)STAINS ES (1)07/04/202307/04/2023Poule 4 - tour n°5 du 07/04/2023CHAMBLY (1)FRANCONVILLE (1)07/04/202307/04/2023Poule 4 - tour n°6 du 19/05/2023ARGENTEUIL (1)HERBLAY (2)19/05/202319/05/2023Poule 4 - tour n°6 du 19/05/2023MAISONS-LAF. US (1)CHAMBLY (1)19/05/202319/05/2023Poule 4 - tour n°6 du 19/05/2023LA FRETTE (1)MONTSOULT (1)19/05/202319/05/2023Poule 4 - tour n°6 du 19/05/2023STAINS ES (1)FRANCONVILLE (1)19/05/202319/05/2023Poule 4 - tour n°7 du 02/06/2023HERBLAY (2)MAISONS-LAF. US (1)02/06/202302/06/2023Poule 4 - tour n°7 du 02/06/2023MONTSOULT (1)ARGENTEUIL (1)02/06/202302/06/2023Poule 4 - tour n°7 du 02/06/2023FRANCONVILLE (1)LA FRETTE (1)02/06/202302/06/2023Poule 4 - tour n°7 du 02/06/2023CHAMBLY (1)STAINS ES (1)02/06/202302/06/2023 \ No newline at end of file