-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
293 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
<?php | ||
|
||
namespace RNEClient; | ||
|
||
use GuzzleHttp\Exception\GuzzleException; | ||
|
||
/** | ||
* Class SearchActs | ||
* | ||
* @package RNEClient | ||
*/ | ||
class SearchActs extends RNEClient implements SearchActsInterface | ||
{ | ||
/** | ||
* Search a company acts by its siren number | ||
* Exact search only | ||
* | ||
* @param string $siren | ||
* | ||
* @throws GuzzleException | ||
* @return array | ||
*/ | ||
public function searchBySiren(string $siren): array | ||
{ | ||
// error if the siren is not 9 length number | ||
if (!preg_match('/^\d{9}$/', $siren)) { | ||
throw new \Exception('Invalid input siren, please use a 9 length number.'); | ||
} | ||
return $this->requestApi("get", "api/companies/{$siren}/attachments", ['headers' => $this->getAuthorizationHeaderArray()]); | ||
} | ||
|
||
/** | ||
* Search a act metadata by its id | ||
* Exact search only | ||
* | ||
* @param string $siren | ||
* | ||
* @throws GuzzleException | ||
* @return array | ||
*/ | ||
public function getMetadataById(string $id): array | ||
{ | ||
return $this->requestApi("get", "api/actes/{$id}", ['headers' => $this->getAuthorizationHeaderArray()]); | ||
} | ||
|
||
/** | ||
* Search a act file by its id | ||
* Exact search only | ||
* | ||
* @param string $siren | ||
* | ||
* @throws GuzzleException | ||
* @return resource | ||
*/ | ||
public function getFileById(string $id): string | ||
{ | ||
return $this->requestFileApi("get", "api/actes/{$id}/download", ['headers' => $this->getAuthorizationHeaderArray()]); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
<?php | ||
|
||
namespace RNEClient; | ||
|
||
interface SearchActsInterface | ||
{ | ||
public function searchBySiren(string $siren): array; | ||
public function getMetadataById(string $id): array; | ||
public function getFileById(string $id): string; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
<?php | ||
|
||
namespace RNEClient; | ||
|
||
|
||
use GuzzleHttp\Client; | ||
use GuzzleHttp\Handler\MockHandler; | ||
use GuzzleHttp\HandlerStack; | ||
use GuzzleHttp\Psr7\Response; | ||
use PHPUnit\Framework\TestCase; | ||
|
||
class GetFileByIdTest extends TestCase | ||
{ | ||
private SearchActs $RNEClient; | ||
|
||
protected function setUp(): void | ||
{ | ||
$this->RNEClient = new SearchActs(); | ||
} | ||
|
||
public function testGetFileById(): void | ||
{ | ||
// get from file | ||
$fakeBinaryFile = 'fake_binary_file'; | ||
|
||
$mockHandler = new MockHandler([new Response(200, [], $fakeBinaryFile)]); | ||
$handlerStack = HandlerStack::create($mockHandler); | ||
$mockedClient = new Client(['handler' => $handlerStack]); | ||
|
||
$this->RNEClient = new SearchActs('fake_token', $mockedClient); | ||
|
||
$data = $this->RNEClient->getFileById('idnumberzzz'); | ||
|
||
$this->assertEquals($fakeBinaryFile, $data); | ||
} | ||
|
||
public function testGetFileByIdWithBadId(): void | ||
{ | ||
$mockHandler = new MockHandler([new Response(404, [], '[]')]); | ||
$handlerStack = HandlerStack::create($mockHandler); | ||
$mockedClient = new Client(['handler' => $handlerStack]); | ||
|
||
$this->RNEClient = new SearchActs('fake_token', $mockedClient); | ||
|
||
$this->expectException(\Exception::class); | ||
$this->expectExceptionMessage('Not found'); | ||
$this->RNEClient->getFileById('bad_id'); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
<?php | ||
|
||
namespace RNEClient; | ||
|
||
|
||
use GuzzleHttp\Client; | ||
use GuzzleHttp\Handler\MockHandler; | ||
use GuzzleHttp\HandlerStack; | ||
use GuzzleHttp\Psr7\Response; | ||
use PHPUnit\Framework\TestCase; | ||
|
||
class GetMetadataByIdTest extends TestCase | ||
{ | ||
private SearchActs $RNEClient; | ||
|
||
protected function setUp(): void | ||
{ | ||
$this->RNEClient = new SearchActs(); | ||
} | ||
|
||
public function testGetMetadataById(): void | ||
{ | ||
// get from file | ||
$fakeResponse = file_get_contents(__DIR__ . '/../../fixtures/SearchActs/getMetadataById.json'); | ||
|
||
$mockHandler = new MockHandler([new Response(200, [], $fakeResponse)]); | ||
$handlerStack = HandlerStack::create($mockHandler); | ||
$mockedClient = new Client(['handler' => $handlerStack]); | ||
|
||
$this->RNEClient = new SearchActs('fake_token', $mockedClient); | ||
|
||
$data = $this->RNEClient->getMetadataById('idnumberzzz'); | ||
$this->assertIsArray($data); | ||
$this->assertEquals('idnumberzzz', $data['id']); | ||
$this->assertEquals('NNNNNNNNN', $data['siren']); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
<?php | ||
|
||
namespace RNEClient; | ||
|
||
|
||
use GuzzleHttp\Client; | ||
use GuzzleHttp\Handler\MockHandler; | ||
use GuzzleHttp\HandlerStack; | ||
use GuzzleHttp\Psr7\Response; | ||
use PHPUnit\Framework\TestCase; | ||
|
||
class SearchBySirenTest extends TestCase | ||
{ | ||
private SearchActs $RNEClient; | ||
|
||
protected function setUp(): void | ||
{ | ||
$this->RNEClient = new SearchActs(); | ||
} | ||
|
||
public function testSearchBySiren(): void | ||
{ | ||
// get from file | ||
$fakeResponse = file_get_contents(__DIR__ . '/../../fixtures/SearchActs/searchBySiren.json'); | ||
|
||
$mockHandler = new MockHandler([new Response(200, [], $fakeResponse)]); | ||
$handlerStack = HandlerStack::create($mockHandler); | ||
$mockedClient = new Client(['handler' => $handlerStack]); | ||
|
||
$this->RNEClient = new SearchActs('fake_token', $mockedClient); | ||
|
||
// Testez le comportement de recherche | ||
$result = $this->RNEClient->searchBySiren('113277693'); | ||
|
||
$this->assertIsArray($result); | ||
} | ||
|
||
public function testSearchBySirenWithBadSiren(): void | ||
{ | ||
$mockHandler = new MockHandler([new Response(200, [], '[]')]); | ||
$handlerStack = HandlerStack::create($mockHandler); | ||
$mockedClient = new Client(['handler' => $handlerStack]); | ||
|
||
$this->RNEClient = new SearchActs('fake_token', $mockedClient); | ||
|
||
$this->expectException(\Exception::class); | ||
$this->expectExceptionMessage('Invalid input siren, please use a 9 length number.'); | ||
$this->RNEClient->searchBySiren('1234567890'); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
{ | ||
"id": "idnumberzzz", | ||
"siren": "NNNNNNNNN", | ||
"denomination": "Nom Société", | ||
"dateDepot": "2022-12-25", | ||
"typeRdd": [{ | ||
"typeActe": "Proces-verbal d'assemblee generale ordinaire" | ||
}] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
{ | ||
"actes": [ | ||
{ | ||
"id": "6385db8b901325760b0c0d71", | ||
"idOdrncs": 1409112, | ||
"siren": "113277693", | ||
"denomination": "VITALAC RUMINANT", | ||
"dateDepot": "2021-08-02", | ||
"nomDocument": "GU_ACTE_113277693_20221118_ENT21-000004478_1", | ||
"nomDocumentOrigine": "GU_ACTE_113277693_20221118_ENT21-000004478_1", | ||
"confidentiality": "Public", | ||
"dateReceptionRne": "2022-11-18", | ||
"tailleFichier": "56257", | ||
"documentExtension": "PDF", | ||
"nbPages": 1, | ||
"natureArchive": "A", | ||
"path": "/rne/Actes_PDF/2022/11/18/GU_ACTE_113277693_20221118_ENT21-000004478_1/", | ||
"pathOrigine": | ||
"/opendatarncs/public/Actes_PDF/flux/2022/11/18/GU_ACTE_113277693_20221118_ENT21-000004478_1/", | ||
"typeDocument": "original électronique", | ||
"numNat": "ENT21-000004478", | ||
"numNatChrono": "1", | ||
"valideParCfe": "oui", | ||
"nomDocumentDeposant": "testPub.pdf", | ||
"typeRdd": [ | ||
{ | ||
"typeActe": "Copie des statuts" | ||
} | ||
] | ||
}, | ||
{ | ||
"id": "6385db8b901325760b0c0d73", | ||
"idOdrncs": 1409113, | ||
"siren": "113277693", | ||
"denomination": "VITALAC RUMINANT", | ||
"dateDepot": "2021-08-02", | ||
"nomDocument": "GU_ACTE_113277693_20221118_ENT21-000004478_2", | ||
"nomDocumentOrigine": "GU_ACTE_113277693_20221118_ENT21-000004478_2", | ||
"confidentiality": "Public", | ||
"dateReceptionRne": "2022-11-18", | ||
"tailleFichier": "56257", | ||
"documentExtension": "PDF", | ||
"nbPages": 1, | ||
"natureArchive": "A", | ||
"path": "/rne/Actes_PDF/2022/11/18/GU_ACTE_113277693_20221118_ENT21-000004478_2/", | ||
"pathOrigine": | ||
"/opendatarncs/public/Actes_PDF/flux/2022/11/18/GU_ACTE_113277693_20221118_ENT21-000004478_2/", | ||
"typeDocument": "original électronique", | ||
"numNat": "ENT21-000004478", | ||
"numNatChrono": "2", | ||
"valideParCfe": "oui", | ||
"nomDocumentDeposant": "testPubStats.pdf", | ||
"typeRdd": [ | ||
{ | ||
"typeActe": "Copie des statuts" | ||
} | ||
] | ||
} | ||
], | ||
"bilans": [], | ||
"bilansSaisis": [] | ||
} |