-
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
1 parent
4f5d206
commit 146e33c
Showing
7 changed files
with
637 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
<?php | ||
|
||
namespace RNEClient; | ||
|
||
use GuzzleHttp\Exception\GuzzleException; | ||
|
||
/** | ||
* Class SearchFinancialStatements | ||
* | ||
* @package RNEClient | ||
*/ | ||
class SearchFinancialStatements extends RNEClient implements SearchFinancialStatementsInterface | ||
{ | ||
|
||
/** | ||
* Search a company financial statements 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 balance sheet data by its id | ||
* Exact search only | ||
* | ||
* @param string $id | ||
* | ||
* @throws GuzzleException | ||
* @return array | ||
*/ | ||
public function searchById(string $id): array | ||
{ | ||
return $this->requestApi("get", "api/bilan-saisis/{$id}", ['headers' => $this->getAuthorizationHeaderArray()]); | ||
} | ||
|
||
/** | ||
* Get balance sheet metadata by its id | ||
* Exact search only | ||
* | ||
* @param string $id | ||
* | ||
* @throws GuzzleException | ||
* @return array | ||
*/ | ||
public function getMetadataById(string $id): array | ||
{ | ||
return $this->requestApi("get", "api/bilans/{$id}", ['headers' => $this->getAuthorizationHeaderArray()]); | ||
} | ||
|
||
/** | ||
* Get a balance sheet PDF file by its id | ||
* Exact search only | ||
* | ||
* @param string $id | ||
* | ||
* @throws GuzzleException | ||
* @return resource | ||
*/ | ||
public function getFileById(string $id): string | ||
{ | ||
return $this->requestFileApi("get", "api/bilans/{$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,11 @@ | ||
<?php | ||
|
||
namespace RNEClient; | ||
|
||
interface SearchFinancialStatementsInterface | ||
{ | ||
public function searchBySiren(string $siren): array; | ||
public function searchById(string $id): array; | ||
public function getMetadataById(string $id): array; | ||
public function getFileById(string $id): string; | ||
} |
50 changes: 50 additions & 0 deletions
50
tests/features/SearchFinancialStatements/SearchBySirenTest.php
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 SearchFinancialStatementsInterface $RNEClient; | ||
|
||
protected function setUp(): void | ||
{ | ||
$this->RNEClient = new SearchFinancialStatements(); | ||
} | ||
|
||
public function testSearchBySiren(): void | ||
{ | ||
// get from file | ||
$fakeResponse = file_get_contents(__DIR__ . '/../../fixtures/SearchFinancialStatements/searchBySiren.json'); | ||
|
||
$mockHandler = new MockHandler([new Response(200, [], $fakeResponse)]); | ||
$handlerStack = HandlerStack::create($mockHandler); | ||
$mockedClient = new Client(['handler' => $handlerStack]); | ||
|
||
$this->RNEClient = new SearchFinancialStatements('fake_token', $mockedClient); | ||
|
||
$data = $this->RNEClient->searchBySiren('113277693'); | ||
|
||
$this->assertIsArray($data); | ||
$this->assertIsArray($data['bilans']); | ||
$this->assertIsArray($data['bilansSaisis']); | ||
} | ||
|
||
public function testSearchBySirenWithBadSiren(): void | ||
{ | ||
$mockHandler = new MockHandler([new Response(200, [], '[]')]); | ||
$handlerStack = HandlerStack::create($mockHandler); | ||
$mockedClient = new Client(['handler' => $handlerStack]); | ||
|
||
$this->RNEClient = new SearchFinancialStatements('fake_token', $mockedClient); | ||
|
||
$this->expectException(\Exception::class); | ||
$this->expectExceptionMessage('Invalid input siren, please use a 9 length number.'); | ||
$this->RNEClient->searchBySiren('1234567890'); | ||
} | ||
} |
8 changes: 8 additions & 0 deletions
8
tests/fixtures/SearchFinancialStatements/getMetadataById.json
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,8 @@ | ||
{ | ||
"id": " idnumberxyz", | ||
"siren": "NNNNNNNNN", | ||
"denomination": "Nom Société", | ||
"dateDepot": "2022-12-25", | ||
"dateCloture": "2022-12-31", | ||
"typeBilan": "C" | ||
} |
Oops, something went wrong.