diff --git a/.github/workflows/static.yml b/.github/workflows/static.yml new file mode 100644 index 0000000..7b5f7d4 --- /dev/null +++ b/.github/workflows/static.yml @@ -0,0 +1,75 @@ +name: Static Analysis + +on: + push: + pull_request: + +jobs: + composer: + name: Composer validation + runs-on: ubuntu-20.04 + + steps: + - name: Checkout code + uses: actions/checkout@v2 + + - name: Setup PHP + uses: shivammathur/setup-php@v2 + with: + php-version: '8.0' + tools: composer:2.4.3 + coverage: none + + - name: Execute composer validate + run: composer validate --strict + + phpcs: + name: PHPCs + runs-on: ubuntu-20.04 + + steps: + - name: Checkout code + uses: actions/checkout@v2 + + - name: Setup PHP + uses: shivammathur/setup-php@v2 + with: + php-version: '8.0' + tools: composer:2.4.3 + coverage: none + + - name: Install Dependencies + uses: nick-invision/retry@v1 + with: + timeout_minutes: 5 + max_attempts: 5 + command: composer update --no-interaction --no-progress + + - name: Execute PHPCs + run: vendor/bin/phpcs src tests + + + phpstan: + name: PHPStan + runs-on: ubuntu-20.04 + + steps: + - name: Checkout code + uses: actions/checkout@v2 + + - name: Setup PHP + uses: shivammathur/setup-php@v2 + with: + php-version: '8.0' + tools: composer:2.4.3 + coverage: none + + - name: Install Dependencies + uses: nick-invision/retry@v1 + with: + timeout_minutes: 5 + max_attempts: 5 + command: composer update --no-interaction --no-progress + + - name: Execute PHPStan + run: vendor/bin/phpstan analyze -c phpstan.neon src tests --no-progress diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml new file mode 100644 index 0000000..3b7d1f5 --- /dev/null +++ b/.github/workflows/tests.yml @@ -0,0 +1,66 @@ +name: Tests + +on: + push: + pull_request: + +jobs: + tests: + name: PHP ${{ matrix.php }} + runs-on: ubuntu-20.04 + + strategy: + matrix: + php: ['8.0', '8.1', '8.2'] + + steps: + - name: Checkout Code + uses: actions/checkout@v2 + + - name: Setup PHP + uses: shivammathur/setup-php@v2 + with: + php-version: ${{ matrix.php }} + tools: composer:2.4.3 + coverage: none + + - name: Install Dependencies + uses: nick-invision/retry@v1 + with: + timeout_minutes: 5 + max_attempts: 5 + command: composer update --no-interaction --no-progress + + - name: Execute PHPUnit + run: vendor/bin/phpunit + + coverage: + name: Test Coverage + runs-on: ubuntu-20.04 + + steps: + - name: Checkout Code + uses: actions/checkout@v2 + + - name: Setup PHP + uses: shivammathur/setup-php@v2 + with: + php-version: '8.0' + tools: composer:2.4.3 + coverage: pcov + + - name: Install Dependencies + uses: nick-invision/retry@v1 + with: + timeout_minutes: 5 + max_attempts: 5 + command: composer update --no-interaction --no-progress + + - name: Execute PHPUnit + run: vendor/bin/phpunit --coverage-clover=./coverage.xml + + - name: Upload to Codecov + uses: codecov/codecov-action@v3 + with: + files: ./coverage.xml + verbose: true diff --git a/.php-cs-fixer.php b/.php-cs-fixer.php new file mode 100644 index 0000000..ffb5fe8 --- /dev/null +++ b/.php-cs-fixer.php @@ -0,0 +1,25 @@ +in('./src') + ->in('./tests'); +; + +$config = new PhpCsFixer\Config(); +return $config->setRules([ + '@Symfony' => true, + 'array_syntax' => ['syntax' => 'short'], + 'phpdoc_add_missing_param_annotation' => true, + 'linebreak_after_opening_tag' => true, + 'phpdoc_summary' => false, + 'phpdoc_no_package' => false, + 'phpdoc_order' => true, + 'phpdoc_align' => true, + 'ordered_imports' => true, + 'native_function_invocation' => true, + '@PSR12' => true, + 'strict_param' => true, + 'declare_strict_types' => true, +]) + ->setFinder($finder) + ; diff --git a/.php_cs.dist b/.php_cs.dist deleted file mode 100644 index e73c39a..0000000 --- a/.php_cs.dist +++ /dev/null @@ -1,19 +0,0 @@ -in('./src') - ->in('./tests'); - -return PhpCsFixer\Config::create() - ->setRules([ - '@Symfony' => true, - 'array_syntax' => ['syntax' => 'short'], - 'phpdoc_add_missing_param_annotation' => true, - 'linebreak_after_opening_tag' => true, - 'phpdoc_summary' => false, - 'phpdoc_no_package' => false, - 'phpdoc_order' => true, - 'phpdoc_align' => true, - 'ordered_imports' => true, - 'native_function_invocation' => true, - ]) - ->setFinder($finder); diff --git a/.styleci.yml b/.styleci.yml index 939a023..ac8d606 100644 --- a/.styleci.yml +++ b/.styleci.yml @@ -1,5 +1 @@ -preset: recommended - -disabled: - - align_double_arrow - - no_multiline_whitespace_before_semicolons \ No newline at end of file +preset: psr12 diff --git a/.travis.yml b/.travis.yml deleted file mode 100644 index 3007d5c..0000000 --- a/.travis.yml +++ /dev/null @@ -1,27 +0,0 @@ -language: php - -php: - - 7.1 - - 7.2 - - 7.3 - - 7.4 - - 8.0 - -allow_failures: - php: nightly - -cache: - directories: - - $HOME/.composer/cache - -install: - - composer install --no-interaction --no-progress || composer remove --dev friendsofphp/php-cs-fixer --no-interaction --no-progress - -script: - - composer validate --strict - - vendor/bin/phpstan analyze -c phpstan.neon -l max src - - vendor/bin/phpcs src tests - - vendor/bin/phpunit --coverage-clover=coverage.xml - -after_success: - - bash <(curl -s https://codecov.io/bash) diff --git a/README.md b/README.md index 979e1f9..5f54183 100644 --- a/README.md +++ b/README.md @@ -20,48 +20,19 @@ composer require gusapi/gusapi Supported Versions ================== -|Version|PHP version | BIR service version | Support | Doc | -|-------|------------|--------|----------------------------------|------| -|5.x | >= 7.1 | BIR1.1 (available since May 2019) | Support ends on December 1, 2020 | [Doc](https://github.com/johnzuk/GusApi/blob/master/README.md)| -|4.x | >= 7.1 | BIR1 | Support ends on December 1, 2019 | [Doc](https://github.com/johnzuk/GusApi/tree/4.0.2/README.md)| -|3.3.x | >= 5.6 | BIR1 | Support ends on December 1, 2018 | [Doc](https://github.com/johnzuk/GusApi/blob/3.3/README.md) | -|3.2.x | >= 5.4 | BIR1 | Support ended on April 1, 2018 | [Doc](https://github.com/johnzuk/GusApi/blob/3.2/README.md) | - -If you still use PHP <= 7.0 see documentation for 3.3.x version [HERE](https://github.com/johnzuk/GusApi/blob/3.3/README.md) +| Version | PHP version | BIR service version | Support | Doc | +|---------|-------------|---------------------------------------|----------------------------------|------| +| 6.x | >= 8.0 | BIR1.1 (available since October 2022) | Support ends on April 1, 2023 | [Doc](https://github.com/johnzuk/GusApi/blob/master/README.md)| +| 5.x | >= 7.1 | BIR1.1 (available since May 2019) | Support ends on December 1, 2020 | [Doc](https://github.com/johnzuk/GusApi/blob/5.0.0/README.md)| + +If you still use PHP <= 8.0 see documentation for 5.x version [HERE](https://github.com/johnzuk/GusApi/blob/5.0.0/README.md) ------------------- -New in 5.x (this version support BIR1.1) -======================================== -* New properties in `SearchReport`: - * nip - * nipStatus - * propertyNumber - * apartmentNumber - * activityEndDate - - **Till version 5.x you dont need to get full report to find property number and apartment number** - -* Method getFullReport throws `InvalidReportTypeException` for invalid report name -* Method dataStatus now return `DateTimeImmutable` instead of `DateTime` and throws `InvalidServerResponseException` -* New method getBulkReport - new search type in BIR1.1 (mode documentation [here](https://api.stat.gov.pl/Home/RegonApi)) - with `BulkReportTypes` -* New supported report types for `getBulkReport` method (based on BIR1.1 documentation): - ```php - public const REPORT_NEW_LEGAL_ENTITY_AND_NATURAL_PERSON = 'BIR11NowePodmiotyPrawneOrazDzialalnosciOsFizycznych'; - public const REPORT_UPDATED_LEGAL_ENTITY_AND_NATURAL_PERSON = 'BIR11AktualizowanePodmiotyPrawneOrazDzialalnosciOsFizycznych'; - public const REPORT_DELETED_LEGAL_ENTITY_AND_NATURAL_PERSON = 'BIR11SkreslonePodmiotyPrawneOrazDzialalnosciOsFizycznych'; - public const REPORT_NEW_LOCAL_UNITS = 'BIR11NoweJednostkiLokalne'; - public const REPORT_UPDATED_LOCAL_UNITS = 'BIR11AktualizowaneJednostkiLokalne'; - public const REPORT_DELETED_LOCAL_UNITS = 'BIR11SkresloneJednostkiLokalne'; - ``` - -* Remove `ReportTypeMapper` - -Upgrade from 4.x to 5.x +Upgrade from 5.x to 6.x ========================= For more information see [UPGRADE.md](UPGRADE.md). -Example for 5.x +Example for 6.x ====================== See file [examples/readmeExample.php](examples/readmeExample.php). @@ -88,14 +59,15 @@ try { var_dump($gus->dataStatus()); var_dump($gus->getBulkReport( new DateTimeImmutable('2019-05-31'), - BulkReportTypes::REPORT_DELETED_LOCAL_UNITS)); + BulkReportTypes::REPORT_DELETED_LOCAL_UNITS + )); foreach ($gusReports as $gusReport) { //you can change report type to other one $reportType = ReportTypes::REPORT_PERSON; echo $gusReport->getName(); - echo 'Address: '. $gusReport->getStreet(). ' ' . $gusReport->getPropertyNumber() . '/' . $gusReport->getApartmentNumber(); - + echo 'Address: ' . $gusReport->getStreet() . ' ' . $gusReport->getPropertyNumber() . '/' . $gusReport->getApartmentNumber(); + $fullReport = $gus->getFullReport($gusReport, $reportType); var_dump($fullReport); } @@ -104,7 +76,12 @@ try { } catch (NotFoundException $e) { echo 'No data found
'; echo 'For more information read server message below:
'; - echo $gus->getResultSearchMessage(); + echo sprintf( + "StatusSesji:%s\nKomunikatKod:%s\nKomunikatTresc:%s\n", + $gus->getSessionStatus(), + $gus->getMessageCode(), + $gus->getMessage() + ); } ``` diff --git a/UPGRADE.md b/UPGRADE.md index fbe46af..30dcbb0 100644 --- a/UPGRADE.md +++ b/UPGRADE.md @@ -1,43 +1,41 @@ -# UPGRADE FROM 4.x to 5.0 +# UPGRADE FROM 5.x to 6.0 Installation ------------ -Before upgrading this package make sure you are using [PHP 7.1](http://php.net/migration71) or newer as it is required to run version 5.0 of this library. +Before upgrading this package make sure you are using [PHP 8.0](http://php.net/migration80) or newer as it is required to run version 5.0 of this library. To upgrade, simply run: ```bash -composer require gusapi/gusapi ^5.0 +composer require gusapi/gusapi ^6.0 ``` -Everything should work the same as in versions 4.x - +Everything should work the same as in versions 5.x - GusApi ------- -* The `GusApi::getFullReport` now throws `InvalidReportTypeException` for invalid report name. +* The `GusApi::getUserKey` has been removed. -* The `getBulkReport` method added. +* The `GusApi::setUserKey` has been removed. -* The `GusApi::dataStatus` now returns `DateTimeImmutable` instead of `DateTime`. +* The `GusApi::setSessionId` has been removed. -* The `GusApi::dataStatus` now throws `InvalidServerResponseException` exception. +* The `GusApi::getResultSearchMessage` has been removed. -SearchReport +ReportTypes ----- - -* Property `SearchReport::$regon14` has been removed. - -* The `SearchReport::$nip` `$nipStatus` `$propertyNumber` `$apartmentNumber` `$activityEndDate` properties have been added. - -BulkReportTypes ------- -* The `BulkReportTypes` has been added. - -ReportTypeMapper ------- -* The `ReportTypeMapper` has been removed. - -Request ------ -* The `GetValue::setPNazwaParametru` method has been removed. - -* The `GetFullReport::setPRegon` and `setPNazwaRaportu` methods have been removed. +* Const `ReportTypes::REPORT_ACTIVITY_PHYSIC_PERSON` has been removed and replaced by `ReportTypes::REPORT_PERSON`. +* Const `ReportTypes::REPORT_ACTIVITY_PHYSIC_CEIDG` has been removed and replaced by `ReportTypes::REPORT_PERSON_CEIDG`. +* Const `ReportTypes::REPORT_ACTIVITY_PHYSIC_AGRO` has been removed and replaced by `ReportTypes::REPORT_PERSON_AGRO`. +* Const `ReportTypes::REPORT_ACTIVITY_PHYSIC_OTHER_PUBLIC` has been removed and replaced by `ReportTypes::REPORT_PERSON_OTHER`. +* Const `ReportTypes::REPORT_ACTIVITY_LOCAL_PHYSIC_WKR_PUBLIC` has been removed and replaced by `ReportTypes::REPORT_PERSON_DELETED_BEFORE_20141108`. +* Const `ReportTypes::REPORT_LOCALS_PHYSIC_PUBLIC` has been removed and replaced by `ReportTypes::REPORT_PERSON_LOCALS`. +* Const `ReportTypes::REPORT_LOCAL_PHYSIC_PUBLIC` has been removed and replaced by `ReportTypes::REPORT_PERSON_LOCAL`. +* Const `ReportTypes::REPORT_ACTIVITY_PHYSIC_PUBLIC` has been removed and replaced by `ReportTypes::REPORT_PERSON_ACTIVITY`. +* Const `ReportTypes::REPORT_ACTIVITY_LOCAL_PHYSIC_PUBLIC` has been removed and replaced by `ReportTypes::REPORT_PERSON_LOCAL_ACTIVITY`. +* Const `ReportTypes::REPORT_PUBLIC_LAW` has been removed and replaced by `ReportTypes::REPORT_ORGANIZATION`. +* Const `ReportTypes::REPORT_ACTIVITY_LAW_PUBLIC` has been removed and replaced by `ReportTypes::REPORT_ORGANIZATION_ACTIVITY`. +* Const `ReportTypes::REPORT_LOCALS_LAW_PUBLIC` has been removed and replaced by `ReportTypes::REPORT_ORGANIZATION_LOCALS`. +* Const `ReportTypes::REPORT_LOCAL_LAW_PUBLIC` has been removed and replaced by `ReportTypes::REPORT_ORGANIZATION_LOCAL`. +* Const `ReportTypes::REPORT_ACTIVITY_LOCAL_LAW_PUBLIC` has been removed and replaced by `ReportTypes::REPORT_ORGANIZATION_LOCAL_ACTIVITY`. +* Const `ReportTypes::REPORT_COMMON_LAW_PUBLIC` has been removed and replaced by `ReportTypes::REPORT_ORGANIZATION_PARTNERS`. +* Const `ReportTypes::REPORT_UNIT_TYPE_PUBLIC` has been removed and replaced by `ReportTypes::REPORT_UNIT_TYPE`. diff --git a/composer.json b/composer.json index f5e10d5..7edfd6e 100644 --- a/composer.json +++ b/composer.json @@ -11,16 +11,18 @@ } ], "require": { - "php" : "^7.1|^8.0", + "php" : "^8.0", "ext-soap": "*", "ext-simplexml": "*", "ext-json": "*" }, "require-dev": { - "phpunit/phpunit": "^7.0 | ^8.0", - "squizlabs/php_codesniffer": "^3.4", - "friendsofphp/php-cs-fixer": "^2.11", - "phpstan/phpstan": "^0.12.58" + "phpunit/phpunit": "^9.0", + "squizlabs/php_codesniffer": "^3.7", + "friendsofphp/php-cs-fixer": "^3.11", + "phpstan/phpstan": "^1.8", + "phpstan/phpstan-phpunit": "^1.1", + "rector/rector": "^0.14.6" }, "autoload":{ "psr-4": { diff --git a/examples/readmeExample.php b/examples/readmeExample.php index 3a26787..5aeb690 100644 --- a/examples/readmeExample.php +++ b/examples/readmeExample.php @@ -28,7 +28,7 @@ //you can change report type to other one $reportType = ReportTypes::REPORT_PERSON; echo $gusReport->getName(); - echo 'Address: '.$gusReport->getStreet().' '.$gusReport->getPropertyNumber().'/'.$gusReport->getApartmentNumber(); + echo 'Address: ' . $gusReport->getStreet() . ' ' . $gusReport->getPropertyNumber() . '/' . $gusReport->getApartmentNumber(); $fullReport = $gus->getFullReport($gusReport, $reportType); var_dump($fullReport); @@ -38,5 +38,10 @@ } catch (NotFoundException $e) { echo 'No data found
'; echo 'For more information read server message below:
'; - echo $gus->getResultSearchMessage(); + echo sprintf( + "StatusSesji:%s\nKomunikatKod:%s\nKomunikatTresc:%s\n", + $gus->getSessionStatus(), + $gus->getMessageCode(), + $gus->getMessage() + ); } diff --git a/phpcs.xml.dist b/phpcs.xml.dist index 0999be7..bba8ce4 100644 --- a/phpcs.xml.dist +++ b/phpcs.xml.dist @@ -2,5 +2,29 @@ - - \ No newline at end of file + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/phpstan.neon b/phpstan.neon index e731139..f94aa64 100644 --- a/phpstan.neon +++ b/phpstan.neon @@ -1,7 +1,8 @@ parameters: + level: max reportUnmatchedIgnoredErrors: false checkMissingIterableValueType: false - excludes_analyse: - - src/GusApi/Client/SoapClient.php ignoreErrors: - - '#Method GusApi\\Client\\GusApiClient::call\(\) has no return typehint specified#' + - "#^Method GusApi\\\\Client\\\\GusApiClient\\:\\:call\\(\\) has no return type specified\\.$#" +includes: + - vendor/phpstan/phpstan-phpunit/extension.neon diff --git a/phpunit.xml.dist b/phpunit.xml.dist index d0f58e7..8e57f10 100644 --- a/phpunit.xml.dist +++ b/phpunit.xml.dist @@ -1,22 +1,17 @@ - - - - - tests - - - - - src - - - - - + + + + src + + + + + + + + tests + + diff --git a/rector.php b/rector.php new file mode 100644 index 0000000..d0e90cc --- /dev/null +++ b/rector.php @@ -0,0 +1,16 @@ +paths([ + __DIR__ . '/src' + ]); + + $rectorConfig->sets([ + LevelSetList::UP_TO_PHP_80 + ]); +}; diff --git a/src/GusApi/BulkReportTypes.php b/src/GusApi/BulkReportTypes.php index 8be59b4..d210737 100644 --- a/src/GusApi/BulkReportTypes.php +++ b/src/GusApi/BulkReportTypes.php @@ -1,12 +1,14 @@ environment = $environment; - $this->gusApiClient = $gusApiClient; } /** * @throws SoapFault - * - * @return GusApiClient */ public function build(): GusApiClient { diff --git a/src/GusApi/Client/BuilderInterface.php b/src/GusApi/Client/BuilderInterface.php index 100d743..0a0c637 100644 --- a/src/GusApi/Client/BuilderInterface.php +++ b/src/GusApi/Client/BuilderInterface.php @@ -1,11 +1,10 @@ soapClient = $soapClient; - $this->streamContext = $streamContext; - $this->setLocation($location); - } - - /** - * @return string - */ - public function getLocation(): string - { - return $this->location; - } - - /** - * @param string $location - */ - public function setLocation(string $location): void - { - $this->location = $location; - $this->soapClient->__setLocation($location); - } - - /** - * @return \SoapClient - */ - public function getSoapClient(): \SoapClient - { - return $this->soapClient; - } - - /** - * @param \SoapClient $soapClient - */ - public function setSoapClient(\SoapClient $soapClient): void - { - $this->soapClient = $soapClient; - } + public const ADDRESSING_NAMESPACE = 'http://www.w3.org/2005/08/addressing'; - /** - * @return ContextInterface - */ - public function getStreamContext(): ContextInterface - { - return $this->streamContext; - } - - /** - * @param ContextInterface $streamContext - */ - public function setStreamContext(ContextInterface $streamContext): void + public function __construct(private \SoapClient $soapClient, private string $location, private ContextInterface $streamContext) { - $this->streamContext = $streamContext; } - /** - * @param Login $login - * - * @return LoginResponse - */ public function login(Login $login): LoginResponse { - return $this->call('Zaloguj', [ - $login, - ]); + return $this->call('Zaloguj', $login); } - /** - * @param Logout $logout - * - * @return LogoutResponse - */ public function logout(Logout $logout): LogoutResponse { - return $this->call('Wyloguj', [ - $logout, - ]); + return $this->call('Wyloguj', $logout); } - /** - * @param GetValue $getValue - * @param null|string $sessionId - * - * @return GetValueResponse - */ public function getValue(GetValue $getValue, ?string $sessionId = null): GetValueResponse { - return $this->call('GetValue', [ - $getValue, - ], $sessionId); + return $this->call('GetValue', $getValue, $sessionId); } /** - * @param SearchData $searchData - * @param string $sessionId - * * @throws NotFoundException - * - * @return SearchDataResponse */ public function searchData(SearchData $searchData, string $sessionId): SearchDataResponse { /** - * @var SearchResponseRaw + * @var SearchResponseRaw $result */ - $result = $this->call('DaneSzukajPodmioty', [ - $searchData, - ], $sessionId); + $result = $this->call('DaneSzukajPodmioty', $searchData, $sessionId); if ('' === $result->getDaneSzukajPodmiotyResult()) { throw new NotFoundException('No data found'); @@ -163,65 +63,44 @@ public function searchData(SearchData $searchData, string $sessionId): SearchDat return DataSearchDecoder::decode($result); } - /** - * @param GetFullReport $getFullReport - * @param string $sessionId - * - * @return GetFullReportResponse - */ public function getFullReport(GetFullReport $getFullReport, string $sessionId): GetFullReportResponse { - $rawResponse = $this->call('DanePobierzPelnyRaport', [ - $getFullReport, - ], $sessionId); + $rawResponse = $this->call('DanePobierzPelnyRaport', $getFullReport, $sessionId); return FullReportResponseDecoder::decode($rawResponse); } - /** - * @param GetBulkReport $getBulkReport - * @param string $sessionId - * - * @return array - */ public function getBulkReport(GetBulkReport $getBulkReport, string $sessionId): array { - $rawResponse = $this->call('DanePobierzRaportZbiorczy', [ - $getBulkReport, - ], $sessionId); + $rawResponse = $this->call('DanePobierzRaportZbiorczy', $getBulkReport, $sessionId); return BulkReportResponseDecoder::decode($rawResponse); } - /** - * @param array $options - */ - public function setHttpOptions(array $options): void + private function setHttpOptions(array $options): void { $this->streamContext->setOptions([ 'http' => $options, ]); } - protected function call(string $functionName, array $arguments, ?string $sid = null) + private function call(string $functionName, RequestInterface $request, ?string $sid = null) { $action = SoapActionMapper::getAction($functionName); $soapHeaders = $this->getRequestHeaders($action, $this->location); + $this->soapClient->__setLocation($this->location); $this->setHttpOptions([ - 'header' => 'sid: '.$sid, + 'header' => 'sid: ' . $sid, 'user_agent' => 'PHP GusApi', ]); - return $this->soapClient->__soapCall($functionName, $arguments, [], $soapHeaders); + return $this->soapClient->__soapCall($functionName, [$request->toArray()], [], $soapHeaders); } /** - * @param string $action - * @param string $to - * * @return \SoapHeader[] */ - protected function getRequestHeaders(string $action, string $to): array + private function getRequestHeaders(string $action, string $to): array { return [ new \SoapHeader(self::ADDRESSING_NAMESPACE, 'Action', $action), diff --git a/src/GusApi/Client/MultipartResponseDecoder.php b/src/GusApi/Client/MultipartResponseDecoder.php index 7003702..c63a5ec 100644 --- a/src/GusApi/Client/MultipartResponseDecoder.php +++ b/src/GusApi/Client/MultipartResponseDecoder.php @@ -1,16 +1,13 @@ ', true).''; + return stristr((string) stristr($response, '', true) . ''; } } diff --git a/src/GusApi/Client/SoapActionMapper.php b/src/GusApi/Client/SoapActionMapper.php index 5766b71..9076e5d 100644 --- a/src/GusApi/Client/SoapActionMapper.php +++ b/src/GusApi/Client/SoapActionMapper.php @@ -1,5 +1,7 @@ context = \stream_context_create(); + $this->context = stream_context_create(); } public function setOptions(array $options): bool { - return \stream_context_set_option($this->context, $options); + return stream_context_set_option($this->context, $options); } public function setParameters(array $parameters): bool { - return \stream_context_set_params($this->context, $parameters); + return stream_context_set_params($this->context, $parameters); } public function getOptions(): array { - return \stream_context_get_options($this->context); + return stream_context_get_options($this->context); } public function getParameters(): array { - return \stream_context_get_params($this->context); + return stream_context_get_params($this->context); } public function getContext() diff --git a/src/GusApi/Context/ContextInterface.php b/src/GusApi/Context/ContextInterface.php index af30f11..123a65d 100644 --- a/src/GusApi/Context/ContextInterface.php +++ b/src/GusApi/Context/ContextInterface.php @@ -1,31 +1,17 @@ @@ -31,90 +33,34 @@ class GusApi protected const SERVICE_TIME_ZONE = 'Europe/Warsaw'; protected const SERVICE_STATUS_DATE_FORMAT = 'd-m-Y'; + private GusApiClient $apiClient; + private string $sessionId; - /** - * @var string user key - */ - protected $userKey; - - /** - * @var GusApiClient - */ - protected $apiClient; - - /** - * @var string - */ - protected $sessionId; - - /** - * GusApi constructor. - * - * @param string $userKey - * @param string $env - * @param BuilderInterface|null $builder - */ - public function __construct(string $userKey, string $env = 'prod', ?BuilderInterface $builder = null) + public function __construct(private string $userKey, string $env = 'prod', ?BuilderInterface $builder = null) { $builder = $builder ?: new Builder($env); $this->apiClient = $builder->build(); - $this->userKey = $userKey; } - /** - * @param string $userKey - * @param GusApiClient $apiClient - * - * @return GusApi - */ public static function createWithApiClient(string $userKey, GusApiClient $apiClient): self { return new self($userKey, 'prod', new Builder('prod', $apiClient)); } - /** - * @return string - */ - public function getUserKey(): string - { - return $this->userKey; - } - - /** - * @param string $userKey - */ - public function setUserKey(string $userKey): void - { - $this->userKey = $userKey; - } - - /** - * @return string - */ public function getSessionId(): string { return $this->sessionId; } - /** - * @param string $sessionId - */ - public function setSessionId(string $sessionId): void - { - $this->sessionId = $sessionId; - } - /** * @throws InvalidUserKeyException - * - * @return bool */ public function login(): bool { $result = $this->apiClient->login(new Login($this->userKey)); if (empty($result->getZalogujResult())) { - throw new InvalidUserKeyException(\sprintf("User key '%s' is invalid", $this->userKey)); + throw new InvalidUserKeyException(sprintf("User key '%s' is invalid", $this->userKey)); } $this->sessionId = $result->getZalogujResult(); @@ -122,19 +68,11 @@ public function login(): bool return true; } - /** - * @return bool - */ public function logout(): bool { - $response = $this->apiClient->logout(new Logout($this->sessionId)); - - return $response->getWylogujResult(); + return $this->apiClient->logout(new Logout($this->sessionId))->getWylogujResult(); } - /** - * @return bool - */ public function isLogged(): bool { return (bool) $this->getSessionStatus(); @@ -142,8 +80,6 @@ public function isLogged(): bool /** * @throws InvalidServerResponseException - * - * @return DateTimeImmutable */ public function dataStatus(): DateTimeImmutable { @@ -159,13 +95,7 @@ public function dataStatus(): DateTimeImmutable ); if (false === $dataStatus) { - throw new InvalidServerResponseException( - \sprintf( - 'Invalid response, expected date in format "%s" given %s', - self::SERVICE_STATUS_DATE_FORMAT, - $result->getGetValueResult() - ) - ); + throw new InvalidServerResponseException(sprintf('Invalid response, expected date in format "%s" given %s', self::SERVICE_STATUS_DATE_FORMAT, $result->getGetValueResult())); } return $dataStatus; @@ -188,50 +118,51 @@ public function serviceStatus(): int return (int) $result->getGetValueResult(); } - /** - * @return string - */ public function serviceMessage(): string { - $result = $this->apiClient->getValue(new GetValue(ParamName::SERVICE_MESSAGE)); - - return $result->getGetValueResult(); + return $this->apiClient->getValue(new GetValue(ParamName::SERVICE_MESSAGE))->getGetValueResult(); } /** - * @param string $nip - * * @throws NotFoundException * * @return SearchReport[] */ public function getByNip(string $nip): array { - return $this->search(SearchType::NIP, $nip); + return $this->search( + new SearchData( + new SearchParameters(null, null, $nip, null, null, null, null) + ) + ); } /** - * @param string $regon - * * @throws NotFoundException * * @return array|SearchReport[] */ public function getByRegon(string $regon): array { - return $this->search(SearchType::REGON, $regon); + return $this->search( + new SearchData( + new SearchParameters(null, null, null, null, $regon, null, null) + ) + ); } /** - * @param string $krs - * * @throws NotFoundException * * @return array|SearchReport[] */ public function getByKrs(string $krs): array { - return $this->search(SearchType::KRS, $krs); + return $this->search( + new SearchData( + new SearchParameters($krs, null, null, null, null, null, null) + ) + ); } /** @@ -245,7 +176,11 @@ public function getByNips(array $nips): array { $this->checkIdentifiersCount($nips); - return $this->search(SearchType::NIPS, \implode(',', $nips)); + return $this->search( + new SearchData( + new SearchParameters(null, null, null, implode(',', $nips), null, null, null) + ) + ); } /** @@ -259,7 +194,11 @@ public function getByKrses(array $krses): array { $this->checkIdentifiersCount($krses); - return $this->search(SearchType::KRSES, \implode(',', $krses)); + return $this->search( + new SearchData( + new SearchParameters(null, implode(',', $krses), null, null, null, null, null) + ) + ); } /** @@ -273,7 +212,11 @@ public function getByRegons9(array $regons): array { $this->checkIdentifiersCount($regons); - return $this->search(SearchType::REGONS_9, \implode(',', $regons)); + return $this->search( + new SearchData( + new SearchParameters(null, null, null, null, null, null, implode(',', $regons)) + ) + ); } /** @@ -287,16 +230,17 @@ public function getByregons14(array $regons): array { $this->checkIdentifiersCount($regons); - return $this->search(SearchType::REGONS_14, \implode(',', $regons)); + return $this->search( + new SearchData( + new SearchParameters(null, null, null, null, null, implode(',', $regons), null) + ) + ); } /** - * @param SearchReport $searchReport - * @param string $reportName - * * @throws InvalidReportTypeException * - * @return array[] + * @return array> */ public function getFullReport(SearchReport $searchReport, string $reportName): array { @@ -312,23 +256,12 @@ public function getFullReport(SearchReport $searchReport, string $reportName): a } /** - * @param DateTimeImmutable $date - * @param string $reportName - * * @throws InvalidReportTypeException - * - * @return array */ public function getBulkReport(DateTimeImmutable $date, string $reportName): array { if (!\in_array($reportName, BulkReportTypes::REPORTS, true)) { - throw new InvalidReportTypeException( - \sprintf( - 'Invalid report type: "%s", use one of allowed type: (%s)', - $reportName, - \implode(', ', BulkReportTypes::REPORTS) - ) - ); + throw new InvalidReportTypeException(sprintf('Invalid report type: "%s", use one of allowed type: (%s)', $reportName, implode(', ', BulkReportTypes::REPORTS))); } return $this->apiClient->getBulkReport( @@ -337,25 +270,8 @@ public function getBulkReport(DateTimeImmutable $date, string $reportName): arra ); } - /** - * Get message about search if you don't get data. - * - * @return string - */ - public function getResultSearchMessage(): string - { - return \sprintf( - "StatusSesji:%s\nKomunikatKod:%s\nKomunikatTresc:%s\n", - $this->getSessionStatus(), - $this->getMessageCode(), - $this->getMessage() - ); - } - /** * Return message code if search not found record. - * - * @return int */ public function getMessageCode(): int { @@ -369,8 +285,6 @@ public function getMessageCode(): int /** * Return message text id search not found record. - * - * @return string */ public function getMessage(): string { @@ -379,9 +293,6 @@ public function getMessage(): string return $result->getGetValueResult(); } - /** - * @return int - */ public function getSessionStatus(): int { $response = $this->apiClient->getValue( @@ -392,39 +303,21 @@ public function getSessionStatus(): int return (int) $response->getGetValueResult(); } - /** - * @param string[] $identifiers - * - * @throws \InvalidArgumentException - */ - protected function checkIdentifiersCount(array $identifiers): void + private function checkIdentifiersCount(array $identifiers): void { if (\count($identifiers) > self::MAX_IDENTIFIERS) { - throw new \InvalidArgumentException(\sprintf( - 'Too many identifiers. Maximum allowed is %d.', - self::MAX_IDENTIFIERS - )); + throw new \InvalidArgumentException(sprintf('Too many identifiers. Maximum allowed is %d.', self::MAX_IDENTIFIERS)); } } /** - * @param string $searchType - * @param string $parameters - * * @throws NotFoundException - * * @return SearchReport[] */ - private function search(string $searchType, string $parameters): array + private function search(SearchData $searchData): array { - $method = 'set'.$searchType; - $searchParameters = new SearchParameters(); - $searchParameters->$method($parameters); - - $result = $this->apiClient->searchData(new SearchData($searchParameters), $this->sessionId); + $result = $this->apiClient->searchData($searchData, $this->sessionId); - return \array_map(function (SearchResponseCompanyData $company) { - return new SearchReport($company); - }, $result->getDaneSzukajResult()); + return array_map(static fn (SearchResponseCompanyData $company): SearchReport => new SearchReport($company), $result->getDaneSzukajResult()); } } diff --git a/src/GusApi/ParamName.php b/src/GusApi/ParamName.php index 51344a1..a11d205 100644 --- a/src/GusApi/ParamName.php +++ b/src/GusApi/ParamName.php @@ -1,21 +1,23 @@ regon = $data->getRegon(); @@ -121,190 +67,108 @@ public function __construct(SearchResponseCompanyData $data) $this->apartmentNumber = $data->getNrLokalu(); $this->type = $this->makeType($data->getTyp()); $this->regon14 = $this->makeRegon14($this->getRegon()); - $this->silo = $data->getSilosID(); + $this->silo = (int) $data->getSilosID(); $this->activityEndDate = $data->getDataZakonczeniaDzialalnosci(); $this->postCity = $data->getMiejscowoscPoczty(); } - /** - * Get REGON number. - * - * @return string REGON number - */ public function getRegon(): string { return $this->regon; } - /** - * Get subject name. - * - * @return string name - */ public function getName(): string { return $this->name; } - /** - * Get province name. - * - * @return string province name - */ public function getProvince(): string { return $this->province; } - /** - * Get distinct name. - * - * @return string distinct name - */ public function getDistrict(): string { return $this->district; } - /** - * Get community name. - * - * @return string community name - */ public function getCommunity(): string { return $this->community; } - /** - * Get city. - * - * @return string city name - */ public function getCity(): string { return $this->city; } - /** - * Get zip code. - * - * @return string zip code - */ public function getZipCode(): string { return $this->zipCode; } - /** - * Get street name. - * - * @return string street name - */ public function getStreet(): string { return $this->street; } - /** - * Get type name. - * - * @return string type name - */ public function getType(): string { return $this->type; } - /** - * @return string - */ public function getRegon14(): string { return $this->regon14; } - /** - * @return int - */ public function getSilo(): int { return $this->silo; } - /** - * @return string - */ public function getNip(): string { return $this->nip; } - /** - * @return string - */ public function getNipStatus(): string { return $this->nipStatus; } - /** - * @return string - */ public function getPropertyNumber(): string { return $this->propertyNumber; } - /** - * @return string - */ public function getApartmentNumber(): string { return $this->apartmentNumber; } - /** - * @return string - */ public function getActivityEndDate(): string { return $this->activityEndDate; } - /** - * @return string - */ public function getPostCity(): string { return $this->postCity; } - /** - * @param string $regon - * - * @return string - */ private function makeRegon14(string $regon): string { - return \str_pad($regon, 14, '0'); + return str_pad($regon, 14, '0'); } - /** - * @param string $type - * - * @return string - */ - private function makeType($type): string + private function makeType(string $type): string { - return \trim(\strtolower($type)); + return trim(strtolower($type)); } - /** - * @return array - */ public function jsonSerialize(): array { - return \get_object_vars($this); + return get_object_vars($this); } } diff --git a/src/GusApi/SearchType.php b/src/GusApi/SearchType.php index b367549..868664d 100644 --- a/src/GusApi/SearchType.php +++ b/src/GusApi/SearchType.php @@ -1,15 +1,17 @@ pDataRaportu = $pDataRaportu; - $this->pNazwaRaportu = $pNazwaRaportu; - } - - /** - * @return string - */ - public function getPDataRaportu(): string +final class GetBulkReport implements RequestInterface +{ + public function __construct(private string $pDataRaportu, private string $pNazwaRaportu) { - return $this->pDataRaportu; } - /** - * @return string - */ - public function getPNazwaRaportu(): string + public function toArray(): array { - return $this->pNazwaRaportu; + return [ + ParamName::REPORT_DATE => $this->pDataRaportu, + ParamName::REPORT_NAME => $this->pNazwaRaportu, + ]; } } diff --git a/src/GusApi/Type/Request/GetFullReport.php b/src/GusApi/Type/Request/GetFullReport.php index e4a22b2..d703992 100644 --- a/src/GusApi/Type/Request/GetFullReport.php +++ b/src/GusApi/Type/Request/GetFullReport.php @@ -1,42 +1,22 @@ pRegon = $pRegon; - $this->pNazwaRaportu = $pNazwaRaportu; - } - - /** - * @return string - */ - public function getPRegon(): string +final class GetFullReport implements RequestInterface +{ + public function __construct(public string $pRegon, public string $pNazwaRaportu) { - return $this->pRegon; } - /** - * @return string - */ - public function getPNazwaRaportu(): string + public function toArray(): array { - return $this->pNazwaRaportu; + return [ + ParamName::REGON => $this->pRegon, + ParamName::REPORT_NAME => $this->pNazwaRaportu, + ]; } } diff --git a/src/GusApi/Type/Request/GetValue.php b/src/GusApi/Type/Request/GetValue.php index 86ff766..a928e26 100644 --- a/src/GusApi/Type/Request/GetValue.php +++ b/src/GusApi/Type/Request/GetValue.php @@ -1,27 +1,21 @@ pNazwaParametru = $pNazwaParametru; } - /** - * @return string - */ - public function getPNazwaParametru(): string + public function toArray(): array { - return $this->pNazwaParametru; + return [ + ParamName::PARAM_NAME => $this->pNazwaParametru, + ]; } } diff --git a/src/GusApi/Type/Request/Login.php b/src/GusApi/Type/Request/Login.php index d806fb7..93f44a3 100644 --- a/src/GusApi/Type/Request/Login.php +++ b/src/GusApi/Type/Request/Login.php @@ -1,27 +1,21 @@ pKluczUzytkownika = $pKluczUzytkownika; } - /** - * @return string - */ - public function getPKluczUzytkownika(): string + public function toArray(): array { - return $this->pKluczUzytkownika; + return [ + ParamName::USER_KEY => $this->userKey, + ]; } } diff --git a/src/GusApi/Type/Request/Logout.php b/src/GusApi/Type/Request/Logout.php index b7162a1..8283703 100644 --- a/src/GusApi/Type/Request/Logout.php +++ b/src/GusApi/Type/Request/Logout.php @@ -1,27 +1,21 @@ pIdentyfikatorSesji = $pIdentyfikatorSesji; } - /** - * @return string - */ - public function getPIdentyfikatorSesji(): string + public function toArray(): array { - return $this->pIdentyfikatorSesji; + return [ + ParamName::SESSION_ID => $this->sessionId, + ]; } } diff --git a/src/GusApi/Type/Request/RequestInterface.php b/src/GusApi/Type/Request/RequestInterface.php new file mode 100644 index 0000000..b6c6542 --- /dev/null +++ b/src/GusApi/Type/Request/RequestInterface.php @@ -0,0 +1,13 @@ + + */ + public function toArray(): array; +} diff --git a/src/GusApi/Type/Request/SearchData.php b/src/GusApi/Type/Request/SearchData.php index 22eb9a4..91014a5 100644 --- a/src/GusApi/Type/Request/SearchData.php +++ b/src/GusApi/Type/Request/SearchData.php @@ -1,29 +1,21 @@ pParametryWyszukiwania = $pParametryWyszukiwania; } - /** - * @return SearchParameters - */ - public function getPParametryWyszukiwania(): SearchParameters + public function toArray(): array { - return $this->pParametryWyszukiwania; + return [ + ParamName::SEARCH => $this->pParametryWyszukiwania->toArray(), + ]; } } diff --git a/src/GusApi/Type/Request/SearchParameters.php b/src/GusApi/Type/Request/SearchParameters.php new file mode 100644 index 0000000..6322e21 --- /dev/null +++ b/src/GusApi/Type/Request/SearchParameters.php @@ -0,0 +1,25 @@ + $this->Krs, + 'Krsy' => $this->Krsy, + 'Nip' => $this->Nip, + 'Nipy' => $this->Nipy, + 'Regon' => $this->Regon, + 'Regony9zn' => $this->Regony9zn, + 'Regony14zn' => $this->Regony14zn, + ]; + } +} diff --git a/src/GusApi/Type/Response/GetBulkReportResponseRaw.php b/src/GusApi/Type/Response/GetBulkReportResponseRaw.php index 331ce7c..a616acf 100644 --- a/src/GusApi/Type/Response/GetBulkReportResponseRaw.php +++ b/src/GusApi/Type/Response/GetBulkReportResponseRaw.php @@ -1,25 +1,15 @@ DanePobierzRaportZbiorczyResult = $DanePobierzRaportZbiorczyResult; } - /** - * @return string - */ public function getDanePobierzRaportZbiorczyResult(): string { return $this->DanePobierzRaportZbiorczyResult; diff --git a/src/GusApi/Type/Response/GetFullReportResponse.php b/src/GusApi/Type/Response/GetFullReportResponse.php index 129ddee..525ab12 100644 --- a/src/GusApi/Type/Response/GetFullReportResponse.php +++ b/src/GusApi/Type/Response/GetFullReportResponse.php @@ -1,26 +1,20 @@ > $report */ - public function __construct(array $report = []) + public function __construct(public array $report = []) { - $this->report = $report; } /** - * @return array[] + * @return array> */ public function getReport(): array { diff --git a/src/GusApi/Type/Response/GetFullReportResponseRaw.php b/src/GusApi/Type/Response/GetFullReportResponseRaw.php index a796033..0b2af53 100644 --- a/src/GusApi/Type/Response/GetFullReportResponseRaw.php +++ b/src/GusApi/Type/Response/GetFullReportResponseRaw.php @@ -1,25 +1,15 @@ DanePobierzPelnyRaportResult = $DanePobierzPelnyRaportResult; } - /** - * @return string - */ public function getDanePobierzPelnyRaportResult(): string { return $this->DanePobierzPelnyRaportResult; diff --git a/src/GusApi/Type/Response/GetValueResponse.php b/src/GusApi/Type/Response/GetValueResponse.php index 0330823..8102938 100644 --- a/src/GusApi/Type/Response/GetValueResponse.php +++ b/src/GusApi/Type/Response/GetValueResponse.php @@ -1,25 +1,15 @@ GetValueResult = $GetValueResult; } - /** - * @return string - */ public function getGetValueResult(): string { return $this->GetValueResult; diff --git a/src/GusApi/Type/Response/LoginResponse.php b/src/GusApi/Type/Response/LoginResponse.php index a0542e6..d383d43 100644 --- a/src/GusApi/Type/Response/LoginResponse.php +++ b/src/GusApi/Type/Response/LoginResponse.php @@ -1,25 +1,15 @@ ZalogujResult = $ZalogujResult; } - /** - * @return string - */ public function getZalogujResult(): string { return $this->ZalogujResult; diff --git a/src/GusApi/Type/Response/LogoutResponse.php b/src/GusApi/Type/Response/LogoutResponse.php index c097b1b..ab16b1d 100644 --- a/src/GusApi/Type/Response/LogoutResponse.php +++ b/src/GusApi/Type/Response/LogoutResponse.php @@ -1,25 +1,15 @@ WylogujResult = $WylogujResult; } - /** - * @return bool - */ public function getWylogujResult(): bool { return $this->WylogujResult; diff --git a/src/GusApi/Type/Response/SearchDataResponse.php b/src/GusApi/Type/Response/SearchDataResponse.php index fe1e874..0aa74d3 100644 --- a/src/GusApi/Type/Response/SearchDataResponse.php +++ b/src/GusApi/Type/Response/SearchDataResponse.php @@ -1,20 +1,16 @@ DaneSzukajResult = $DaneSzukajResult; } /** diff --git a/src/GusApi/Type/Response/SearchResponseCompanyData.php b/src/GusApi/Type/Response/SearchResponseCompanyData.php index ff51909..55be2ec 100644 --- a/src/GusApi/Type/Response/SearchResponseCompanyData.php +++ b/src/GusApi/Type/Response/SearchResponseCompanyData.php @@ -1,211 +1,103 @@ Regon; } - /** - * @return string - */ public function getNip(): string { return $this->Nip; } - /** - * @return string - */ public function getStatusNip(): string { return $this->StatusNip; } - /** - * @return string - */ public function getNazwa(): string { return $this->Nazwa; } - /** - * @return string - */ public function getWojewodztwo(): string { return $this->Wojewodztwo; } - /** - * @return string - */ public function getPowiat(): string { return $this->Powiat; } - /** - * @return string - */ public function getGmina(): string { return $this->Gmina; } - /** - * @return string - */ public function getMiejscowosc(): string { return $this->Miejscowosc; } - /** - * @return string - */ public function getKodPocztowy(): string { return $this->KodPocztowy; } - /** - * @return string - */ public function getUlica(): string { return $this->Ulica; } - /** - * @return string - */ public function getNrNieruchomosci(): string { return $this->NrNieruchomosci; } - /** - * @return string - */ public function getNrLokalu(): string { return $this->NrLokalu; } - /** - * @return string - */ public function getTyp(): string { return $this->Typ; } - /** - * @return int - */ - public function getSilosID(): int + public function getSilosID(): string { return $this->SilosID; } - /** - * @return string - */ public function getDataZakonczeniaDzialalnosci(): string { return $this->DataZakonczeniaDzialalnosci; } - /** - * @return string - */ public function getMiejscowoscPoczty(): string { return $this->MiejscowoscPoczty; diff --git a/src/GusApi/Type/Response/SearchResponseRaw.php b/src/GusApi/Type/Response/SearchResponseRaw.php index 4a112e5..58ece8d 100644 --- a/src/GusApi/Type/Response/SearchResponseRaw.php +++ b/src/GusApi/Type/Response/SearchResponseRaw.php @@ -1,25 +1,15 @@ DaneSzukajPodmiotyResult = $DaneSzukajPodmiotyResult; } - /** - * @return string - */ public function getDaneSzukajPodmiotyResult(): string { return $this->DaneSzukajPodmiotyResult; diff --git a/src/GusApi/Type/SearchParameters.php b/src/GusApi/Type/SearchParameters.php deleted file mode 100644 index a57a59d..0000000 --- a/src/GusApi/Type/SearchParameters.php +++ /dev/null @@ -1,125 +0,0 @@ -Krs; - } - - public function setKrs(?string $Krs): self - { - $this->Krs = $Krs; - - return $this; - } - - public function getKrsy(): ?string - { - return $this->Krsy; - } - - public function setKrsy(?string $Krsy): self - { - $this->Krsy = $Krsy; - - return $this; - } - - public function getNip(): ?string - { - return $this->Nip; - } - - public function setNip(?string $Nip): self - { - $this->Nip = $Nip; - - return $this; - } - - public function getNipy(): ?string - { - return $this->Nipy; - } - - public function setNipy(?string $Nipy): self - { - $this->Nipy = $Nipy; - - return $this; - } - - public function getRegon(): ?string - { - return $this->Regon; - } - - public function setRegon(?string $Regon): self - { - $this->Regon = $Regon; - - return $this; - } - - public function getRegony14zn(): ?string - { - return $this->Regony14zn; - } - - public function setRegony14zn(?string $Regony14zn): self - { - $this->Regony14zn = $Regony14zn; - - return $this; - } - - public function getRegony9zn(): ?string - { - return $this->Regony9zn; - } - - public function setRegony9zn(?string $Regony9zn): self - { - $this->Regony9zn = $Regony9zn; - - return $this; - } -} diff --git a/src/GusApi/Util/BulkReportResponseDecoder.php b/src/GusApi/Util/BulkReportResponseDecoder.php index c8e3b18..16d941d 100644 --- a/src/GusApi/Util/BulkReportResponseDecoder.php +++ b/src/GusApi/Util/BulkReportResponseDecoder.php @@ -1,5 +1,7 @@ getDaneSzukajPodmiotyResult()); } catch (\Exception $e) { - throw new InvalidServerResponseException('Invalid server response'); + throw new InvalidServerResponseException('Invalid server response', 0, $e); } $elements = []; foreach ($xmlElementsResponse->dane as $resultData) { - $elements[] = static::decodeSingleResult($resultData); + $elements[] = self::decodeSingleResult($resultData); } return new SearchDataResponse($elements); @@ -39,7 +41,7 @@ public static function decode(SearchResponseRaw $searchResponseRaw): SearchDataR /** * @throws NotFoundException */ - protected static function decodeSingleResult(SimpleXMLElement $element): SearchResponseCompanyData + private static function decodeSingleResult(SimpleXMLElement $element): SearchResponseCompanyData { $result = new SearchResponseCompanyData(); diff --git a/src/GusApi/Util/FullReportResponseDecoder.php b/src/GusApi/Util/FullReportResponseDecoder.php index 65a37e7..85f3081 100644 --- a/src/GusApi/Util/FullReportResponseDecoder.php +++ b/src/GusApi/Util/FullReportResponseDecoder.php @@ -1,5 +1,7 @@ > $elements */ $elements = []; if ('' === $fullReportResponseRaw->getDanePobierzPelnyRaportResult()) { @@ -24,6 +27,7 @@ public static function decode(GetFullReportResponseRaw $fullReportResponseRaw): $xmlElementsResponse = new SimpleXMLElement($fullReportResponseRaw->getDanePobierzPelnyRaportResult()); foreach ($xmlElementsResponse->dane as $resultData) { + /** @var array $element */ $element = []; foreach ($resultData as $key => $item) { $element[$key] = (string) $item; @@ -33,7 +37,7 @@ public static function decode(GetFullReportResponseRaw $fullReportResponseRaw): return new GetFullReportResponse($elements); } catch (\Exception $e) { - throw new InvalidServerResponseException('Invalid server response'); + throw new InvalidServerResponseException('Invalid server response', 0, $e); } } } diff --git a/tests/Client/BuilderTest.php b/tests/Client/BuilderTest.php index ccb848c..46bd78a 100644 --- a/tests/Client/BuilderTest.php +++ b/tests/Client/BuilderTest.php @@ -1,5 +1,7 @@ build(); - $soapClient = $client->getSoapClient(); - - $this->assertInstanceOf(GusApiClient::class, $client); - $this->assertSame($location, $client->getLocation()); - $this->assertSame(2, $soapClient->_soap_version); - $this->assertIsResource($soapClient->_stream_context); - $this->assertSame($client->getStreamContext()->getContext(), $soapClient->_stream_context); - } - - public function testBuildWithInvalidEnvironmentName() + public function testBuildWithInvalidEnvironmentName(): void { $builder = new Builder('random'); $this->expectException(InvalidEnvironmentNameException::class); $builder->build(); } - public function testBuildWithApiClient() + public function testBuildWithApiClient(): void { $options = [ 'soap_version' => SOAP_1_1, ]; $client = new GusApiClient( - new SoapClient(__DIR__.'/../UslugaBIRzewnPubl.xsd', $options), + new SoapClient(__DIR__ . '/../UslugaBIRzewnPubl.xsd', $options), 'Location', new Context() ); @@ -48,12 +34,4 @@ public function testBuildWithApiClient() $this->assertSame($client, $builder->build()); } - - public function envProvider() - { - return [ - ['prod', 'https://wyszukiwarkaregon.stat.gov.pl/wsBIR/UslugaBIRzewnPubl.svc'], - ['dev', 'https://Wyszukiwarkaregontest.stat.gov.pl/wsBIR/UslugaBIRzewnPubl.svc'], - ]; - } } diff --git a/tests/Client/GusApiClientTest.php b/tests/Client/GusApiClientTest.php index 58cf287..52c077a 100644 --- a/tests/Client/GusApiClientTest.php +++ b/tests/Client/GusApiClientTest.php @@ -1,17 +1,21 @@ soap = $this->getMockFromWsdl(__DIR__.'/../UslugaBIRzewnPubl.xsd'); - + $this->soap = $this->getMockFromWsdl(__DIR__ . '/../UslugaBIRzewnPubl.xsd', SoapClient::class, '', [], false); $this->gusApiClient = new GusApiClient($this->soap, 'Location', new Context()); } - public function testCallWithValidFunctionName() + public function testLogin(): void { - $this->expectSoapCall('Zaloguj', [new Login('1234567890')], new LoginResponse('0987654321')); + $this->expectSoapCall( + 'Zaloguj', + [ + [ + 'pKluczUzytkownika' => '1234567890', + ], + ], + new LoginResponse('0987654321') + ); - $this->assertEquals( + self::assertEquals( new LoginResponse('0987654321'), $this->gusApiClient->login(new Login('1234567890')) ); } - public function testLogin() + public function testLogout(): void { - $this->expectSoapCall('Zaloguj', [new Login('1234567890')], new LoginResponse('0987654321')); - - $this->assertEquals( - new LoginResponse('0987654321'), - $this->gusApiClient->login(new Login('1234567890')) + $this->expectSoapCall( + 'Wyloguj', + [ + [ + 'pIdentyfikatorSesji' => '1234567890', + ], + ], + new LogoutResponse(true) ); - } - public function testLogout() - { - $this->expectSoapCall('Wyloguj', [new Logout('1234567890')], new LogoutResponse(true)); $logoutResult = $this->gusApiClient->logout(new Logout('1234567890')); - - $this->assertTrue($logoutResult->getWylogujResult()); + self::assertTrue($logoutResult->getWylogujResult()); } public function testGetValue(): void { $this->expectSoapCall( 'GetValue', - [new GetValue('StanDanych')], + [ + [ + 'pNazwaParametru' => 'StanDanych', + ] + ], new GetValueResponse('stan danych response'), false ); $value = $this->gusApiClient->getValue(new GetValue(ParamName::STATUS_DATE_STATE)); - $this->assertSame('stan danych response', $value->getGetValueResult()); + self::assertSame('stan danych response', $value->getGetValueResult()); } public function testSearchDataWithSingleResponse(): void { - $searchRawResponse = \file_get_contents(__DIR__.'/../resources/response/searchDataResponseResultSingle.xsd'); - $searchData = new SearchData((new SearchParameters())->setNip('0099112233')); - $this->expectSoapCall('DaneSzukajPodmioty', [$searchData], new SearchResponseRaw($searchRawResponse)); + $searchRawResponse = self::getContent(__DIR__ . '/../resources/response/searchDataResponseResultSingle.xsd'); + $searchData = new SearchData(new SearchParameters(null, null, '0099112233', null, null, null, null)); + + $this->expectSoapCall( + 'DaneSzukajPodmioty', + [ + [ + 'pParametryWyszukiwania' => [ + 'Krs' => null, + 'Krsy' => null, + 'Nip' => '0099112233', + 'Nipy' => null, + 'Regon' => null, + 'Regony9zn' => null, + 'Regony14zn' => null, + ], + ], + ], + new SearchResponseRaw($searchRawResponse) + ); $companyData = new SearchResponseCompanyData(); $companyData->Regon = '02092251199990'; @@ -106,21 +132,37 @@ public function testSearchDataWithSingleResponse(): void $companyData->NrNieruchomosci = '208'; $companyData->NrLokalu = ''; $companyData->Typ = 'P'; - $companyData->SilosID = 6; + $companyData->SilosID = '6'; $companyData->DataZakonczeniaDzialalnosci = ''; $expected = new SearchDataResponse([ $companyData, ]); - $this->assertEquals($expected, $this->gusApiClient->searchData($searchData, '1234567890')); + self::assertEquals($expected, $this->gusApiClient->searchData($searchData, '1234567890')); } public function testSearchDataWithMultipleResponse(): void { - $searchRawResponse = \file_get_contents(__DIR__.'/../resources/response/searchDataReponseResultMulti.xsd'); - $searchData = new SearchData((new SearchParameters())->setNip('0099112233')); - $this->expectSoapCall('DaneSzukajPodmioty', [$searchData], new SearchResponseRaw($searchRawResponse)); + $searchRawResponse = self::getContent(__DIR__ . '/../resources/response/searchDataReponseResultMulti.xsd'); + $searchData = new SearchData(new SearchParameters(null, null, '0099112233', null, null, null, null)); + $this->expectSoapCall( + 'DaneSzukajPodmioty', + [ + [ + 'pParametryWyszukiwania' => [ + 'Krs' => null, + 'Krsy' => null, + 'Nip' => '0099112233', + 'Nipy' => null, + 'Regon' => null, + 'Regony9zn' => null, + 'Regony14zn' => null, + ], + ], + ], + new SearchResponseRaw($searchRawResponse) + ); $firstCompanyData = new SearchResponseCompanyData(); $firstCompanyData->Regon = '02092251199990'; @@ -136,7 +178,7 @@ public function testSearchDataWithMultipleResponse(): void $firstCompanyData->NrNieruchomosci = '208'; $firstCompanyData->NrLokalu = ''; $firstCompanyData->Typ = 'P'; - $firstCompanyData->SilosID = 6; + $firstCompanyData->SilosID = '6'; $firstCompanyData->DataZakonczeniaDzialalnosci = ''; $secondCompanyData = new SearchResponseCompanyData(); @@ -153,7 +195,7 @@ public function testSearchDataWithMultipleResponse(): void $secondCompanyData->NrNieruchomosci = '12'; $secondCompanyData->NrLokalu = '33'; $secondCompanyData->Typ = 'F'; - $secondCompanyData->SilosID = 2; + $secondCompanyData->SilosID = '2'; $secondCompanyData->DataZakonczeniaDzialalnosci = ''; $expected = new SearchDataResponse([ @@ -161,13 +203,29 @@ public function testSearchDataWithMultipleResponse(): void $secondCompanyData, ]); - $this->assertEquals($expected, $this->gusApiClient->searchData($searchData, '1234567890')); + self::assertEquals($expected, $this->gusApiClient->searchData($searchData, '1234567890')); } public function testSearchDataNotFound(): void { - $searchData = new SearchData((new SearchParameters())->setNip('0011223344')); - $this->expectSoapCall('DaneSzukajPodmioty', [$searchData], new SearchResponseRaw('')); + $searchData = new SearchData(new SearchParameters(null, null, '0099112233', null, null, null, null)); + $this->expectSoapCall( + 'DaneSzukajPodmioty', + [ + [ + 'pParametryWyszukiwania' => [ + 'Krs' => null, + 'Krsy' => null, + 'Nip' => '0099112233', + 'Nipy' => null, + 'Regon' => null, + 'Regony9zn' => null, + 'Regony14zn' => null, + ], + ], + ], + new SearchResponseRaw('') + ); $this->expectException(NotFoundException::class); $this->gusApiClient->searchData($searchData, '1234567890'); @@ -175,16 +233,21 @@ public function testSearchDataNotFound(): void public function testGetBulkReport(): void { - $searchRawResponse = \file_get_contents(__DIR__.'/../resources/response/bulkReportResponse.xsd'); + $searchRawResponse = self::getContent(__DIR__ . '/../resources/response/bulkReportResponse.xsd'); $searchData = new GetBulkReport('2019-01-01', 'BIR11NowePodmiotyPrawneOrazDzialalnosciOsFizycznych'); $this->expectSoapCall( 'DanePobierzRaportZbiorczy', - [$searchData], + [ + [ + 'pDataRaportu' => '2019-01-01', + 'pNazwaRaportu' => 'BIR11NowePodmiotyPrawneOrazDzialalnosciOsFizycznych', + ], + ], new GetBulkReportResponseRaw($searchRawResponse) ); - $this->assertEquals([ + self::assertEquals([ '022399999', '147210456', '243544401', @@ -194,15 +257,20 @@ public function testGetBulkReport(): void public function testGetFullReport(): void { - $searchRawResponse = \file_get_contents(__DIR__.'/../resources/response/fullSearchResponse.xsd'); + $searchRawResponse = self::getContent(__DIR__ . '/../resources/response/fullSearchResponse.xsd'); $searchData = new GetFullReport('00112233445566', 'PublDaneRaportTypJednostki'); $this->expectSoapCall( 'DanePobierzPelnyRaport', - [$searchData], + [ + [ + 'pRegon' => '00112233445566', + 'pNazwaRaportu' => 'PublDaneRaportTypJednostki', + ], + ], new GetFullReportResponseRaw($searchRawResponse) ); - $this->assertEquals( + self::assertEquals( new GetFullReportResponse([ [ 'fiz_regon9' => '666666666', @@ -252,13 +320,18 @@ public function testGetFullReport(): void ); } - public function testGetFullReportMultiple() + public function testGetFullReportMultiple(): void { - $searchRawResponse = \file_get_contents(__DIR__.'/../resources/response/fullSearchMultipleResponse.xsd'); + $searchRawResponse = self::getContent(__DIR__ . '/../resources/response/fullSearchMultipleResponse.xsd'); $searchData = new GetFullReport('00112233445566', 'PublDaneRaportDzialalnosciPrawnej'); $this->expectSoapCall( 'DanePobierzPelnyRaport', - [$searchData], + [ + [ + 'pRegon' => '00112233445566', + 'pNazwaRaportu' => 'PublDaneRaportDzialalnosciPrawnej', + ], + ], new GetFullReportResponseRaw($searchRawResponse) ); @@ -284,7 +357,7 @@ public function testGetFullReportMultiple() ); } - protected function getHeaders($action, $to) + private function getHeaders(string $action, string $to): array { return [ new \SoapHeader('http://www.w3.org/2005/08/addressing', 'Action', $action), @@ -292,12 +365,12 @@ protected function getHeaders($action, $to) ]; } - protected function expectSoapCall(string $action, array $arguments, $result, bool $public = true) + private function expectSoapCall(string $action, array $arguments, object $result, bool $public = true): void { $baseUrl = $public ? 'http://CIS/BIR/PUBL/2014/07/IUslugaBIRzewnPubl' : 'http://CIS/BIR/2014/07/IUslugaBIR'; - $headers = $this->getHeaders(\sprintf('%s/%s', $baseUrl, $action), 'Location'); + $headers = $this->getHeaders(sprintf('%s/%s', $baseUrl, $action), 'Location'); $this->soap - ->expects($this->once()) + ->expects(self::once()) ->method('__soapCall') ->with($action, $arguments, [], $headers) ->willReturn($result); diff --git a/tests/Client/RequestDecoderTest.php b/tests/Client/RequestDecoderTest.php index c331a04..7746971 100644 --- a/tests/Client/RequestDecoderTest.php +++ b/tests/Client/RequestDecoderTest.php @@ -1,36 +1,41 @@ assertEquals('', $result); } - public function testDecodeValidSOAPResponse() + public function testDecodeValidSOAPResponse(): void { - $content = \file_get_contents(__DIR__.'/../resources/validSOAPResponse.xsd'); + $content = self::getContent(__DIR__ . '/../resources/validSOAPResponse.xsd'); $result = MultipartResponseDecoder::decode($content); - $this->assertEquals(\trim($content), $result); + $this->assertEquals(trim($content), $result); } - public function testDecodeRawSOAPResponse() + public function testDecodeRawSOAPResponse(): void { - $content = \file_get_contents(__DIR__.'/../resources/rawSOAPResponse.xsd'); - $valid = \file_get_contents(__DIR__.'/../resources/validSOAPResponse.xsd'); + $content = self::getContent(__DIR__ . '/../resources/rawSOAPResponse.xsd'); + $valid = self::getContent(__DIR__ . '/../resources/validSOAPResponse.xsd'); $result = MultipartResponseDecoder::decode($content); - $this->assertEquals(\trim($valid), $result); + $this->assertEquals(trim($valid), $result); } - public function testDecodeRawEnvelopeString() + public function testDecodeRawEnvelopeString(): void { $result = MultipartResponseDecoder::decode('Test'); $this->assertEquals('Test', $result); diff --git a/tests/Client/SoapActionMapperTest.php b/tests/Client/SoapActionMapperTest.php index 86d51bd..baaee67 100644 --- a/tests/Client/SoapActionMapperTest.php +++ b/tests/Client/SoapActionMapperTest.php @@ -1,5 +1,7 @@ assertSame($expected, $action); } - public function testGetActionWithInvalidName() + public function testGetActionWithInvalidName(): void { $this->expectException(InvalidActionNameException::class); SoapActionMapper::getAction('BadFunctionName'); } - public function actionProvider() + public function actionProvider(): array { return [ [ diff --git a/tests/Context/ContextTest.php b/tests/Context/ContextTest.php index 62cb938..488c549 100644 --- a/tests/Context/ContextTest.php +++ b/tests/Context/ContextTest.php @@ -1,23 +1,22 @@ context = new Context(); } - public function testSetOptions() + public function testSetOptions(): void { $options = [ 'http' => [ @@ -27,10 +26,10 @@ public function testSetOptions() $this->context->setOptions($options); $this->assertSame($options, $this->context->getOptions()); - $this->assertSame($options, \stream_context_get_options($this->context->getContext())); + $this->assertSame($options, stream_context_get_options($this->context->getContext())); } - public function testSetParameters() + public function testSetParameters(): void { $params = [ 'notification' => function () { @@ -41,6 +40,6 @@ public function testSetParameters() $this->context->setParameters($params); $this->assertSame($params, $this->context->getParameters()); - $this->assertSame($params, \stream_context_get_params($this->context->getContext())); + $this->assertSame($params, stream_context_get_params($this->context->getContext())); } } diff --git a/tests/Environment/EnvironmentFactoryTest.php b/tests/Environment/EnvironmentFactoryTest.php new file mode 100644 index 0000000..0b996e9 --- /dev/null +++ b/tests/Environment/EnvironmentFactoryTest.php @@ -0,0 +1,30 @@ +expectException(InvalidEnvironmentNameException::class); + EnvironmentFactory::create('asdf'); + } +} diff --git a/tests/ExampleCompanyTrait.php b/tests/ExampleCompanyTrait.php index 07a2857..d5b336e 100644 --- a/tests/ExampleCompanyTrait.php +++ b/tests/ExampleCompanyTrait.php @@ -1,5 +1,7 @@ assertSame('610188201', $report->getRegon()); $this->assertSame('61018820100000', $report->getRegon14()); diff --git a/tests/GetContentTrait.php b/tests/GetContentTrait.php new file mode 100644 index 0000000..e88acae --- /dev/null +++ b/tests/GetContentTrait.php @@ -0,0 +1,20 @@ +apiClient = $this->createMock(GusApiClient::class); - $this->api = GusApi::createWithApiClient($this->userKey, $this->apiClient); + $this->api = GusApi::createWithApiClient('123absdefg123', $this->apiClient); } - public function testLogin() + public function testLoginWillReturnTrueWhenLoginCorrectly(): void { - $this->assertSame($this->userKey, $this->api->getUserKey()); - $this->assertTrue($this->login()); - $this->assertSame($this->sessionId, $this->api->getSessionId()); - } - - public function testLogout() - { - $this->apiClient - ->expects($this->once()) - ->method('logout') - ->with(new Logout($this->sessionId)) - ->willReturn(new LogoutResponse(true)); - - $this->api->setSessionId($this->sessionId); - $this->assertTrue($this->api->logout()); + $this->loginApiWithSessionId('12sessionid21'); + self::assertTrue($this->api->login()); } - public function testGetSessionStatus() + public function testLoginWillSetSessionId(): void { - $this->apiClient - ->expects($this->exactly(2)) - ->method('getValue') - ->with(new GetValue('StatusSesji'), $this->sessionId) - ->willReturn(new GetValueResponse('1')); + $this->loginApiWithSessionId('12sessionid21'); + $this->api->login(); - $this->api->setSessionId($this->sessionId); - $this->assertSame(1, $this->api->getSessionStatus()); - $this->assertTrue($this->api->isLogged()); + self::assertSame($this->api->getSessionId(), '12sessionid21'); } - public function testInvalidLogin() + public function testLoginWillThrowExceptionWhenResponseIsEmpty(): void { $this->expectException(InvalidUserKeyException::class); $this->apiClient - ->expects($this->once()) + ->expects(self::once()) ->method('login') - ->with(new Login('invalid-key')) + ->with(new Login('123absdefg123')) ->willReturn(new LoginResponse('')); - $this->api->setUserKey('invalid-key'); $this->api->login(); } - /** - * @dataProvider searchParameterProvider - * - * @param string $method GusApi method to call - * @param string $parameter search parameter name - * @param mixed $value parameter value - */ - public function testSearchByParameter(string $method, string $parameter, $value) + public function testLogout(): void { - $this->login(); - $parameters = $this->getSearchParameters($parameter, $value); - $this->expectSearchWithParameters($parameters); - - $result = $this->api->$method($value); - $this->assertCount(1, $result); - $this->assertInstanceOf(SearchReport::class, $result[0]); - $this->assertValidExampleCompany($result[0]); + $this->loginApiWithSessionId('12sessionid21'); + $this->apiClient + ->expects(self::once()) + ->method('logout') + ->with(new Logout('12sessionid21')) + ->willReturn(new LogoutResponse(true)); + + self::assertTrue($this->api->logout()); } - public function testGetFullReportWithInvalidReportType(): void + public function testIsLogged(): void { - $this->expectException(InvalidReportTypeException::class); - $searchReport = $this->createMock(SearchReport::class); - $searchReport->method('getRegon')->willReturn('610188201'); + $this->expectGetValueCall('StatusSesji', '1'); + self::assertTrue($this->api->isLogged()); + } - $this->api->getFullReport($searchReport, 'invalid-report-name'); + public function testGetDataStatus(): void + { + $this->expectGetValueCall('StanDanych', '31-12-2014'); + self::assertEquals( + DateTimeImmutable::createFromFormat( + 'd-m-Y', + '31-12-2014', + new DateTimeZone('Europe/Warsaw') + ), + $this->api->dataStatus() + ); } - public function testGetFullReportWithRegon14ReportType(): void + public function testGetDataStatusWillThrowExceptionWhenInvalidDataFormatReturned(): void { - $searchReport = $this->createMock(SearchReport::class); - $searchReport->method('getRegon14')->willReturn('61018820100000'); + $this->expectException(InvalidServerResponseException::class); - $this->login(); - $this->api->getFullReport($searchReport, ReportTypes::REPORT_UNIT_TYPE_PUBLIC); + $this->expectGetValueCall('StanDanych', ''); + $this->api->dataStatus(); } - public function testGetBulkReport(): void + public function testGetServiceStatus(): void { - $this->apiClient - ->expects($this->once()) - ->method('getBulkReport') - ->with( - new GetBulkReport('2019-01-01', BulkReportTypes::REPORT_NEW_LOCAL_UNITS), - $this->sessionId - ) - ->willReturn([ - '000111234', - '111999023', - ]); - - $this->login(); - $actual = $this->api->getBulkReport( - new DateTimeImmutable('2019-01-01'), - BulkReportTypes::REPORT_NEW_LOCAL_UNITS - ); - $this->assertEquals(['000111234', '111999023'], $actual); + $this->expectGetValueCall('StatusUslugi', '1'); + $this->assertSame(1, $this->api->serviceStatus()); } - public function testGetGetBulkReportWithInvalidReportName(): void + public function testGetServiceMessage(): void { - $this->expectException(InvalidReportTypeException::class); - $this->api->getBulkReport(new DateTimeImmutable('2019-01-01'), 'invalid-report-name'); + $this->expectGetValueCall('KomunikatUslugi', 'Example service message'); + $this->assertSame('Example service message', $this->api->serviceMessage()); } - public function testGetFullReport(): void + public function testGetByNip(): void { - $searchReport = $this->createMock(SearchReport::class); - $searchReport->method('getRegon')->willReturn('610188201'); + $this->loginApiWithSessionId('12sessionid21'); + $this->setUpSearchParameters(new SearchParameters(null, null, '123123123', null, null, null, null)); + + self::assertEquals( + [ + new SearchReport( + new SearchResponseCompanyData() + ) + ], + $this->api->getByNip('123123123') + ); + } - $this->apiClient - ->expects($this->once()) - ->method('getFullReport') - ->with(new GetFullReport('610188201', 'BIR11OsPrawna'), $this->sessionId) - ->willReturn(new GetFullReportResponse([ - [ - 'fiz_regon9' => '666666666', - 'fiz_nazwa' => 'NIEPUBLICZNY ZAKŁAD OPIEKI ZDROWOTNEJ xxxxxxxxxxxxx', - 'fiz_nazwaSkrocona' => '', - 'fiz_dataPowstania' => '1993-03-20', - 'fiz_dataRozpoczeciaDzialalnosci' => '1999-10-20', - 'fiz_dataWpisuDoREGONDzialalnosci' => '', - 'fiz_dataZawieszeniaDzialalnosci' => '', - 'fiz_dataWznowieniaDzialalnosci' => '', - 'fiz_dataZaistnieniaZmianyDzialalnosci' => '2011-08-16', - 'fiz_dataZakonczeniaDzialalnosci' => '', - 'fiz_dataSkresleniazRegonDzialalnosci' => '', - 'fiz_adSiedzKraj_Symbol' => '', - 'fiz_adSiedzWojewodztwo_Symbol' => '30', - 'fiz_adSiedzPowiat_Symbol' => '22', - 'fiz_adSiedzGmina_Symbol' => '059', - 'fiz_adSiedzKodPocztowy' => '69000', - 'fiz_adSiedzMiejscowoscPoczty_Symbol' => '0198380', - 'fiz_adSiedzMiejscowosc_Symbol' => '0198380', - 'fiz_adSiedzUlica_Symbol' => '1240', - 'fiz_adSiedzNumerNieruchomosci' => '99', - 'fiz_adSiedzNumerLokalu' => '', - 'fiz_adSiedzNietypoweMiejsceLokalizacji' => '', - 'fiz_numerTelefonu' => '', - 'fiz_numerWewnetrznyTelefonu' => '', - 'fiz_numerFaksu' => '9999999999', - 'fiz_adresEmail' => '', - 'fiz_adresStronyinternetowej' => '', - 'fiz_adresEmail2' => '', - 'fiz_adSiedzKraj_Nazwa' => '', - 'fiz_adSiedzWojewodztwo_Nazwa' => 'WIELKOPOLSKIE', - 'fiz_adSiedzPowiat_Nazwa' => 'xxxxxxxxxx', - 'fiz_adSiedzGmina_Nazwa' => 'Yyyyyyyy', - 'fiz_adSiedzMiejscowosc_Nazwa' => 'Yyyyyyyy', - 'fiz_adSiedzMiejscowoscPoczty_Nazwa' => 'Yyyyyyyy', - 'fiz_adSiedzUlica_Nazwa' => 'ul. Adama Mickiewicza', - 'fizP_dataWpisuDoRejestruEwidencji' => '', - 'fizP_numerwRejestrzeEwidencji' => '', - 'fizP_OrganRejestrowy_Symbol' => '', - 'fizP_OrganRejestrowy_Nazwa' => '', - 'fizP_RodzajRejestru_Symbol' => '099', - 'fizP_RodzajRejestru_Nazwa' => 'PODMIOTY NIE PODLEGAJĄCE WPISOM DO REJESTRU LUB EWIDENCJI', - ], - ])) - ; - - $this->login(); - $fullReport = $this->api->getFullReport($searchReport, ReportTypes::REPORT_ORGANIZATION); - - $this->assertIsArray($fullReport); + public function testGetByRegon(): void + { + $this->loginApiWithSessionId('12sessionid21'); + $this->setUpSearchParameters(new SearchParameters(null, null, null, null, '123123123', null, null)); + + self::assertEquals( + [ + new SearchReport( + new SearchResponseCompanyData() + ) + ], + $this->api->getByRegon('123123123') + ); } - public function testTooManyNipsRaisesAnException() + public function testGetByKrs(): void { - $this->expectException(\InvalidArgumentException::class); - $this->api->getByNips(\array_fill(0, 21, '7740001454')); + $this->loginApiWithSessionId('12sessionid21'); + $this->setUpSearchParameters(new SearchParameters('123123123', null, null, null, null, null, null)); + + self::assertEquals( + [ + new SearchReport( + new SearchResponseCompanyData() + ) + ], + $this->api->getByKrs('123123123') + ); } - public function testGetResultSearchMessage(): void + public function testGetByNips(): void { - $this->apiClient - ->expects($this->at(0)) - ->method('getValue') - ->with(new GetValue('StatusSesji'), $this->sessionId) - ->willReturn(new GetValueResponse('1')); + $this->loginApiWithSessionId('12sessionid21'); + $this->setUpSearchParameters(new SearchParameters(null, null, null, '123123123,123123124', null, null, null)); + + self::assertEquals( + [ + new SearchReport( + new SearchResponseCompanyData() + ) + ], + $this->api->getByNips(['123123123', '123123124']) + ); + } - $this->apiClient - ->expects($this->at(1)) - ->method('getValue') - ->with(new GetValue('KomunikatKod'), $this->sessionId) - ->willReturn(new GetValueResponse('1')); + public function testGetByNipsWillThrowExceptionWhenToManyIdentifiersProvided(): void + { + $this->loginApiWithSessionId('12sessionid21'); + $this->expectException(InvalidArgumentException::class); + $this->api->getByNips(array_fill(0, 21, '123123123')); + } - $this->apiClient - ->expects($this->at(2)) - ->method('getValue') - ->with(new GetValue('KomunikatTresc'), $this->sessionId) - ->willReturn(new GetValueResponse('Server Test Error')); + public function testGetByKrses(): void + { + $this->loginApiWithSessionId('12sessionid21'); + $this->setUpSearchParameters(new SearchParameters(null, '123123123,123123124', null, null, null, null, null)); + + self::assertEquals( + [ + new SearchReport( + new SearchResponseCompanyData() + ) + ], + $this->api->getByKrses(['123123123', '123123124']) + ); + } - $this->api->setSessionId($this->sessionId); - $message = $this->api->getResultSearchMessage(); - $expects = "StatusSesji:1\nKomunikatKod:1\nKomunikatTresc:Server Test Error\n"; - $this->assertSame($expects, $message); + public function testGetByRegons9(): void + { + $this->loginApiWithSessionId('12sessionid21'); + $this->setUpSearchParameters(new SearchParameters(null, null, null, null, null, null, '123123123,123123124')); + + self::assertEquals( + [ + new SearchReport( + new SearchResponseCompanyData() + ) + ], + $this->api->getByRegons9(['123123123', '123123124']) + ); } - public function testGetDataStatus(): void + public function testGetByregons14(): void { - $this->expectGetValueCall('StanDanych', '31-12-2014'); - $this->assertInstanceOf(DateTimeImmutable::class, $this->api->dataStatus()); + $this->loginApiWithSessionId('12sessionid21'); + $this->setUpSearchParameters(new SearchParameters(null, null, null, null, null, '123123123,123123124', null)); + + self::assertEquals( + [ + new SearchReport( + new SearchResponseCompanyData() + ) + ], + $this->api->getByregons14(['123123123', '123123124']) + ); } - public function testGetDataStatusWithInvalidDateFormat(): void + public function testGetFullReport(): void { - $this->expectException(InvalidServerResponseException::class); + $this->loginApiWithSessionId('12sessionid21'); + $this->apiClient + ->expects(self::once()) + ->method('getFullReport') + ->willReturn(new GetFullReportResponse([['test' => '1234']])); - $this->expectGetValueCall('StanDanych', 'random-format'); - $this->api->dataStatus(); + + self::assertSame( + [['test' => '1234']], + $this->api->getFullReport( + new SearchReport(new SearchResponseCompanyData()), + 'BIR11OsFizycznaDaneOgolne' + ) + ); } - public function testGetServiceStatus() + public function testGetBulkReportWillThrowExceptionWhenInvalidReportTypeProvided(): void { - $this->expectGetValueCall('StatusUslugi', '1'); - $this->assertSame(1, $this->api->serviceStatus()); + $this->expectException(InvalidReportTypeException::class); + $this->api->getBulkReport(new DateTimeImmutable(), 'asdf'); } - public function testGetServiceMessage() + public function testGetBulkReport(): void { - $this->expectGetValueCall('KomunikatUslugi', 'Example service message'); - $this->assertSame('Example service message', $this->api->serviceMessage()); + $this->loginApiWithSessionId('12sessionid21'); + $this->apiClient->expects(self::once())->method('getBulkReport')->willReturn(['test' => 'test']); + + self::assertSame( + [ + 'test' => 'test', + ], + $this->api->getBulkReport(new DateTimeImmutable(), 'BIR11NowePodmiotyPrawneOrazDzialalnosciOsFizycznych') + ); } - public function testGetMessage() + public function testGetMessageCode(): void { - $this->expectGetValueCall('KomunikatTresc', 'Example message'); - $this->assertSame('Example message', $this->api->getMessage()); + $this->expectGetValueCall('KomunikatKod', '3'); + self::assertSame(3, $this->api->getMessageCode()); } - public function testGetMessageCode() + public function testGetMessage(): void { - $this->expectGetValueCall('KomunikatKod', '1'); - $this->assertSame(1, $this->api->getMessageCode()); + $this->expectGetValueCall('KomunikatTresc', 'Invalid Test'); + self::assertSame('Invalid Test', $this->api->getMessage()); } - public function searchParameterProvider() + public function testGetSessionStatus(): void { - return [ - ['getByKrs', 'krs', '28860'], - ['getByKrses', 'krsy', ['28860']], - ['getByNip', 'nip', '7740001454'], - ['getByNips', 'nipy', ['7740001454']], - ['getByRegon', 'regon', '610188201'], - ['getByRegons9', 'regony9zn', ['610188201']], - ['getByRegons14', 'regony14zn', ['61018820100000']], - ]; + $this->expectGetValueCall('StatusSesji', '1'); + self::assertSame(1, $this->api->getSessionStatus()); } - protected function expectGetValueCall(string $parameter, string $value) + private function expectGetValueCall(string $parameter, string $value): void { + $this->loginApiWithSessionId('12sessionid21'); $this->apiClient - ->expects($this->once()) + ->expects(self::once()) ->method('getValue') ->with(new GetValue($parameter)) ->willReturn(new GetValueResponse($value)); } - /** - * @param mixed $value - */ - protected function getSearchParameters(string $parameter, $value): SearchParameters - { - $setter = 'set'.\ucfirst($parameter); - $value = \is_array($value) ? \implode(',', $value) : $value; - - return (new SearchParameters())->$setter($value); - } - - protected function expectSearchWithParameters(SearchParameters $parameters) + private function setUpSearchParameters(SearchParameters $parameters): void { - $response = $this->createMock(SearchDataResponse::class); - $response->method('getDaneSzukajResult')->willReturn([$this->getExampleResponseData()]); $this->apiClient - ->expects($this->once()) + ->expects(self::once()) ->method('searchData') - ->with(new SearchData($parameters), $this->sessionId) - ->willReturn($response); + ->with( + new SearchData( + $parameters + ) + ) + ->willReturn( + new SearchDataResponse( + [ + new SearchResponseCompanyData(), + ] + ) + ); } - protected function login(): bool + private function loginApiWithSessionId(string $sessionId): void { $this->apiClient - ->expects($this->once()) ->method('login') - ->with(new Login($this->userKey)) - ->willReturn(new LoginResponse($this->sessionId)); + ->willReturn(new LoginResponse($sessionId)); - return $this->api->login(); + $this->api->login(); } } diff --git a/tests/Integration/GusApiTest.php b/tests/Integration/GusApiTest.php index 3bc3432..9367e10 100644 --- a/tests/Integration/GusApiTest.php +++ b/tests/Integration/GusApiTest.php @@ -1,8 +1,9 @@ login(); } - public function testGetExampleCompanyByNip() + public function testGetExampleCompanyByNip(): void { $result = self::$apiClient->getByNip('7740001454'); @@ -34,14 +32,14 @@ public function testGetExampleCompanyByNip() $this->assertValidExampleCompany($result[0]); } - public function testGetExampleCompanyByNips() + public function testGetExampleCompanyByNips(): void { $result = self::$apiClient->getByNips(['7740001454']); $this->assertCount(1, $result); $this->assertValidExampleCompany($result[0], false); } - public function testGetByInvalidNipAndGetMessage() + public function testGetByInvalidNipAndGetMessage(): void { $this->expectException(NotFoundException::class); @@ -54,37 +52,36 @@ public function testGetByInvalidNipAndGetMessage() } } - public function testGetExampleCompanyByRegon() + public function testGetExampleCompanyByRegon(): void { $result = self::$apiClient->getByRegon('610188201'); $this->assertCount(1, $result); $this->assertValidExampleCompany($result[0]); } - public function testGetExampleCompanyByRegons() + public function testGetExampleCompanyByRegons(): void { $result = self::$apiClient->getByRegons9(['610188201']); $this->assertCount(1, $result); $this->assertValidExampleCompany($result[0], false); } - public function testGetExampleCompanyByKrs() + public function testGetExampleCompanyByKrs(): void { $result = self::$apiClient->getByKrs('0000028860'); $this->assertCount(1, $result); $this->assertValidExampleCompany($result[0], false); } - public function testGetExampleCompanyByKrses() + public function testGetExampleCompanyByKrses(): void { $result = self::$apiClient->getByKrses(['0000028860']); $this->assertCount(1, $result); $this->assertValidExampleCompany($result[0], false); } - public function testGetStatus() + public function testGetStatus(): void { - $this->assertInstanceOf(DateTimeImmutable::class, self::$apiClient->dataStatus()); $this->assertSame(1, self::$apiClient->serviceStatus()); $this->assertSame('Usluga dostepna', self::$apiClient->serviceMessage()); } @@ -102,16 +99,14 @@ public function testGetFullReport(): void $this->assertEquals('', $result[0]['praw_dataZakonczeniaPostepowaniaUpadlosciowego']); } - public function testInvalidKey() + public function testInvalidKey(): void { - $apiClient = new GusApi('abcde12345abcde12345', 'dev'); - $apiClient->setUserKey('invalid-key'); - $this->assertSame('invalid-key', $apiClient->getUserKey()); + $apiClient = new GusApi('invalid-key', 'dev'); $this->expectExceptionObject(new InvalidUserKeyException('User key \'invalid-key\' is invalid')); $apiClient->login(); } - public function testLoginLogout() + public function testLoginLogout(): void { $apiClient = new GusApi('abcde12345abcde12345', 'dev'); $this->assertTrue($apiClient->login()); diff --git a/tests/SearchReportTest.php b/tests/SearchReportTest.php index 2e2c81f..38f2d35 100644 --- a/tests/SearchReportTest.php +++ b/tests/SearchReportTest.php @@ -1,5 +1,7 @@ '34B', 'activityEndDate' => '2029-02-22', 'postCity' => 'Płock', - ], \json_decode(\json_encode(new SearchReport($companyData)), true)); + ], json_decode((string) json_encode(new SearchReport($companyData)), true)); } } diff --git a/tests/UslugaBIRzewnPubl.xsd b/tests/UslugaBIRzewnPubl.xsd index b015028..1e6ae41 100644 --- a/tests/UslugaBIRzewnPubl.xsd +++ b/tests/UslugaBIRzewnPubl.xsd @@ -1,135 +1,303 @@ - - + + - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - - - - - - - https://Wyszukiwarkaregontest.stat.gov.pl/wsBIR/UslugaBIRzewnPubl.svc - - - - + + + + https://wyszukiwarkaregontest.stat.gov.pl/wsBIR/UslugaBIRzewnPubl.svc + + - \ No newline at end of file + diff --git a/tests/Util/BulkReportResponseDecoderTest.php b/tests/Util/BulkReportResponseDecoderTest.php index 2b736f6..6e08296 100644 --- a/tests/Util/BulkReportResponseDecoderTest.php +++ b/tests/Util/BulkReportResponseDecoderTest.php @@ -1,17 +1,22 @@ NrNieruchomosci = '208'; $companyData->NrLokalu = ''; $companyData->Typ = 'P'; - $companyData->SilosID = 6; + $companyData->SilosID = '6'; $companyData->DataZakonczeniaDzialalnosci = ''; $expected = new SearchDataResponse([ diff --git a/tests/Util/FullReportResponseDecoderTest.php b/tests/Util/FullReportResponseDecoderTest.php index 4110005..0258277 100644 --- a/tests/Util/FullReportResponseDecoderTest.php +++ b/tests/Util/FullReportResponseDecoderTest.php @@ -1,32 +1,35 @@ assertInstanceOf(GetFullReportResponse::class, $reportDecoded); - $this->assertEquals([], $reportDecoded->getReport()); + self::assertSame([], $reportDecoded->getReport()); } - public function testDecodeWithValidXMLObject() + public function testDecodeWithValidXMLObject(): void { - $content = \file_get_contents(__DIR__.'/../resources/response/fullSearchResponse.xsd'); + $content = self::getContent(__DIR__ . '/../resources/response/fullSearchResponse.xsd'); $rawReport = new GetFullReportResponseRaw($content); $reportDecoded = FullReportResponseDecoder::decode($rawReport); - $this->assertInstanceOf(GetFullReportResponse::class, $reportDecoded); - $this->assertEquals([ + self::assertSame([ [ 'fiz_regon9' => '666666666', 'fiz_nazwa' => 'NIEPUBLICZNY ZAKŁAD OPIEKI ZDROWOTNEJ xxxxxxxxxxxxx', @@ -73,7 +76,7 @@ public function testDecodeWithValidXMLObject() ], $reportDecoded->getReport()); } - public function testInvalidServerResponse() + public function testInvalidServerResponse(): void { $rawReport = new GetFullReportResponseRaw('Invalid XML structure'); $this->expectException(InvalidServerResponseException::class);