From fcf161c21bea311d5ab39d43024f61d68a3d447a Mon Sep 17 00:00:00 2001 From: Ion Bazan Date: Mon, 2 Dec 2019 12:39:01 +0800 Subject: [PATCH 1/2] allow PHPUnit 8 --- .gitignore | 3 +- .travis.yml | 1 + composer.json | 2 +- src/GusApi/Util/BulkReportResponseDecoder.php | 4 -- src/GusApi/Util/DataSearchDecoder.php | 35 ++++++++------ src/GusApi/Util/FullReportResponseDecoder.php | 4 -- tests/Client/BuilderTest.php | 11 ++--- tests/Client/GusApiClientTest.php | 7 ++- tests/Client/SoapActionMapperTest.php | 5 +- tests/Context/ContextTest.php | 46 +++++++++++++++++++ tests/ExampleCompanyTrait.php | 2 +- tests/GusApiTest.php | 9 ++-- tests/Integration/GusApiTest.php | 2 +- tests/Util/FullReportResponseDecoderTest.php | 5 +- 14 files changed, 88 insertions(+), 48 deletions(-) create mode 100644 tests/Context/ContextTest.php diff --git a/.gitignore b/.gitignore index a465e3b..e473d73 100644 --- a/.gitignore +++ b/.gitignore @@ -5,4 +5,5 @@ examples/captcha.jpeg phpunit.xml .php_cs.cache .php_cs -composer.lock \ No newline at end of file +.phpunit.result.cache +composer.lock diff --git a/.travis.yml b/.travis.yml index e471072..af9f86b 100644 --- a/.travis.yml +++ b/.travis.yml @@ -4,6 +4,7 @@ php: - 7.1 - 7.2 - 7.3 + - 7.4snapshot allow_failures: php: nightly diff --git a/composer.json b/composer.json index ffcaae4..42dd2e9 100644 --- a/composer.json +++ b/composer.json @@ -18,7 +18,7 @@ }, "require-dev": { "phpstan/phpstan-shim": "^0.11", - "phpunit/phpunit": "^7.0", + "phpunit/phpunit": "^7.0 | ^8.0", "squizlabs/php_codesniffer": "^3.4", "friendsofphp/php-cs-fixer": "^2.11" }, diff --git a/src/GusApi/Util/BulkReportResponseDecoder.php b/src/GusApi/Util/BulkReportResponseDecoder.php index a001727..c8e3b18 100644 --- a/src/GusApi/Util/BulkReportResponseDecoder.php +++ b/src/GusApi/Util/BulkReportResponseDecoder.php @@ -9,11 +9,7 @@ class BulkReportResponseDecoder { /** - * @param GetBulkReportResponseRaw $bulkReportResponseRaw - * * @throws InvalidServerResponseException - * - * @return array */ public static function decode(GetBulkReportResponseRaw $bulkReportResponseRaw): array { diff --git a/src/GusApi/Util/DataSearchDecoder.php b/src/GusApi/Util/DataSearchDecoder.php index ab0bec8..0951a60 100644 --- a/src/GusApi/Util/DataSearchDecoder.php +++ b/src/GusApi/Util/DataSearchDecoder.php @@ -12,17 +12,11 @@ class DataSearchDecoder { /** - * @param SearchResponseRaw $searchResponseRaw - * * @throws InvalidServerResponseException * @throws NotFoundException - * - * @return SearchDataResponse */ public static function decode(SearchResponseRaw $searchResponseRaw): SearchDataResponse { - $elements = []; - if ('' === $searchResponseRaw->getDaneSzukajPodmiotyResult()) { return new SearchDataResponse(); } @@ -33,17 +27,30 @@ public static function decode(SearchResponseRaw $searchResponseRaw): SearchDataR throw new InvalidServerResponseException('Invalid server response'); } + $elements = []; + foreach ($xmlElementsResponse->dane as $resultData) { - $element = new SearchResponseCompanyData(); - foreach ($resultData as $key => $item) { - if ($key === 'ErrorCode' && (int) $item === 4) { - throw new NotFoundException('No data found'); - } - $element->$key = (string) $item; - } - $elements[] = $element; + $elements[] = static::decodeSingleResult($resultData); } return new SearchDataResponse($elements); } + + /** + * @throws NotFoundException + */ + protected static function decodeSingleResult(SimpleXMLElement $element): SearchResponseCompanyData + { + $result = new SearchResponseCompanyData(); + + foreach ($element as $key => $item) { + if ('ErrorCode' === $key && 4 === (int) $item) { + throw new NotFoundException('No data found'); + } + + $result->$key = (string) $item; + } + + return $result; + } } diff --git a/src/GusApi/Util/FullReportResponseDecoder.php b/src/GusApi/Util/FullReportResponseDecoder.php index ed9049c..65a37e7 100644 --- a/src/GusApi/Util/FullReportResponseDecoder.php +++ b/src/GusApi/Util/FullReportResponseDecoder.php @@ -10,11 +10,7 @@ class FullReportResponseDecoder { /** - * @param GetFullReportResponseRaw $fullReportResponseRaw - * * @throws InvalidServerResponseException - * - * @return GetFullReportResponse */ public static function decode(GetFullReportResponseRaw $fullReportResponseRaw): GetFullReportResponse { diff --git a/tests/Client/BuilderTest.php b/tests/Client/BuilderTest.php index ca489cb..ccb848c 100644 --- a/tests/Client/BuilderTest.php +++ b/tests/Client/BuilderTest.php @@ -6,6 +6,7 @@ use GusApi\Client\GusApiClient; use GusApi\Client\SoapClient; use GusApi\Context\Context; +use GusApi\Exception\InvalidEnvironmentNameException; use PHPUnit\Framework\TestCase; class BuilderTest extends TestCase @@ -21,17 +22,15 @@ public function testBuildWithValidEnvironmentName(string $env, string $location) $this->assertInstanceOf(GusApiClient::class, $client); $this->assertSame($location, $client->getLocation()); - $this->assertAttributeSame(2, '_soap_version', $soapClient); - $this->assertAttributeInternalType('resource', '_stream_context', $soapClient); - $this->assertAttributeSame($client->getStreamContext()->getContext(), '_stream_context', $soapClient); + $this->assertSame(2, $soapClient->_soap_version); + $this->assertIsResource($soapClient->_stream_context); + $this->assertSame($client->getStreamContext()->getContext(), $soapClient->_stream_context); } - /** - * @expectedException \GusApi\Exception\InvalidEnvironmentNameException - */ public function testBuildWithInvalidEnvironmentName() { $builder = new Builder('random'); + $this->expectException(InvalidEnvironmentNameException::class); $builder->build(); } diff --git a/tests/Client/GusApiClientTest.php b/tests/Client/GusApiClientTest.php index c02e30d..0a5bc53 100644 --- a/tests/Client/GusApiClientTest.php +++ b/tests/Client/GusApiClientTest.php @@ -4,6 +4,7 @@ use GusApi\Client\GusApiClient; use GusApi\Context\Context; +use GusApi\Exception\NotFoundException; use GusApi\ParamName; use GusApi\Type\Request\GetBulkReport; use GusApi\Type\Request\GetFullReport; @@ -36,7 +37,7 @@ class GusApiClientTest extends TestCase */ protected $soap; - public function setUp() + public function setUp(): void { $this->soap = $this->getMockFromWsdl(__DIR__.'/../UslugaBIRzewnPubl.xsd'); @@ -163,14 +164,12 @@ public function testSearchDataWithMultipleResponse(): void $this->assertEquals($expected, $this->gusApiClient->searchData($searchData, '1234567890')); } - /** - * @expectedException \GusApi\Exception\NotFoundException - */ public function testSearchDataNotFound(): void { $searchData = new SearchData((new SearchParameters())->setNip('0011223344')); $this->expectSoapCall('DaneSzukajPodmioty', [$searchData], new SearchResponseRaw('')); + $this->expectException(NotFoundException::class); $this->gusApiClient->searchData($searchData, '1234567890'); } diff --git a/tests/Client/SoapActionMapperTest.php b/tests/Client/SoapActionMapperTest.php index 0897f0f..86d51bd 100644 --- a/tests/Client/SoapActionMapperTest.php +++ b/tests/Client/SoapActionMapperTest.php @@ -3,6 +3,7 @@ namespace GusApi\Tests\Client; use GusApi\Client\SoapActionMapper; +use GusApi\Exception\InvalidActionNameException; use PHPUnit\Framework\TestCase; final class SoapActionMapperTest extends TestCase @@ -19,11 +20,9 @@ public function testGetActionWithValidName($expected, $functionName): void $this->assertSame($expected, $action); } - /** - * @expectedException \GusApi\Exception\InvalidActionNameException - */ public function testGetActionWithInvalidName() { + $this->expectException(InvalidActionNameException::class); SoapActionMapper::getAction('BadFunctionName'); } diff --git a/tests/Context/ContextTest.php b/tests/Context/ContextTest.php new file mode 100644 index 0000000..d4dbc28 --- /dev/null +++ b/tests/Context/ContextTest.php @@ -0,0 +1,46 @@ +context = new Context(); + } + + public function testSetOptions() + { + $options = [ + 'http' => [ + 'follow_location' => false, + ], + ]; + + $this->context->setOptions($options); + $this->assertSame($options, $this->context->getOptions()); + $this->assertSame($options, stream_context_get_options($this->context->getContext())); + } + + public function testSetParameters() + { + $params = [ + 'notification' => function () { + return true; + }, + 'options' => [], + ]; + + $this->context->setParameters($params); + $this->assertSame($params, $this->context->getParameters()); + $this->assertSame($params, stream_context_get_params($this->context->getContext())); + } +} diff --git a/tests/ExampleCompanyTrait.php b/tests/ExampleCompanyTrait.php index 931c669..8503d58 100644 --- a/tests/ExampleCompanyTrait.php +++ b/tests/ExampleCompanyTrait.php @@ -43,7 +43,7 @@ protected function getExampleResponseData(): SearchResponseCompanyData $responseData->method('getNrNieruchomosci')->willReturn('7'); $responseData->method('getNrLokalu')->willReturn(''); $responseData->method('getTyp')->willReturn('p'); - $responseData->method('getSilosID')->willReturn('6'); + $responseData->method('getSilosID')->willReturn(6); $responseData->method('getDataZakonczeniaDzialalnosci')->willReturn(''); return $responseData; diff --git a/tests/GusApiTest.php b/tests/GusApiTest.php index 25ffc9c..9929b36 100644 --- a/tests/GusApiTest.php +++ b/tests/GusApiTest.php @@ -43,7 +43,7 @@ class GusApiTest extends TestCase */ protected $api; - public function setUp() + public function setUp(): void { $this->apiClient = $this->createMock(GusApiClient::class); $this->api = GusApi::createWithApiClient($this->userKey, $this->apiClient); @@ -218,7 +218,7 @@ public function testGetFullReport(): void $this->login(); $fullReport = $this->api->getFullReport($searchReport, ReportTypes::REPORT_PUBLIC_LAW); - $this->assertInternalType('array', $fullReport); + $this->assertIsArray($fullReport); } public function testTooManyNipsRaisesAnException() @@ -314,10 +314,7 @@ protected function expectGetValueCall(string $parameter, string $value) } /** - * @param string $parameter - * @param mixed $value - * - * @return SearchParameters + * @param mixed $value */ protected function getSearchParameters(string $parameter, $value): SearchParameters { diff --git a/tests/Integration/GusApiTest.php b/tests/Integration/GusApiTest.php index f9eeba2..3ab8713 100644 --- a/tests/Integration/GusApiTest.php +++ b/tests/Integration/GusApiTest.php @@ -20,7 +20,7 @@ class GusApiTest extends TestCase */ protected static $apiClient; - public static function setUpBeforeClass() + public static function setUpBeforeClass(): void { self::$apiClient = new GusApi('abcde12345abcde12345', 'dev'); self::$apiClient->login(); diff --git a/tests/Util/FullReportResponseDecoderTest.php b/tests/Util/FullReportResponseDecoderTest.php index 9e7fc42..9aed28b 100644 --- a/tests/Util/FullReportResponseDecoderTest.php +++ b/tests/Util/FullReportResponseDecoderTest.php @@ -2,6 +2,7 @@ namespace GusApi\Tests\Util; +use GusApi\Exception\InvalidServerResponseException; use GusApi\Type\Response\GetFullReportResponse; use GusApi\Type\Response\GetFullReportResponseRaw; use GusApi\Util\FullReportResponseDecoder; @@ -72,12 +73,10 @@ public function testDecodeWithValidXMLObject() ], $reportDecoded->getReport()); } - /** - * @expectedException \GusApi\Exception\InvalidServerResponseException - */ public function testInvalidServerResponse() { $rawReport = new GetFullReportResponseRaw('Invalid XML structure'); + $this->expectException(InvalidServerResponseException::class); FullReportResponseDecoder::decode($rawReport); } } From e9013509f34d743a3bdaefa025e3ea565be34e55 Mon Sep 17 00:00:00 2001 From: Ion Bazan Date: Tue, 3 Dec 2019 17:34:03 +0800 Subject: [PATCH 2/2] use root namespace, PHP 7.4 tests --- .php_cs.dist | 1 + .travis.yml | 2 +- README.md | 12 ++++----- phpstan.neon | 4 --- .../Client/MultipartResponseDecoder.php | 2 +- src/GusApi/Client/SoapActionMapper.php | 2 +- src/GusApi/Context/Context.php | 10 +++---- src/GusApi/Environment/EnvironmentFactory.php | 2 +- src/GusApi/GusApi.php | 26 +++++++++---------- src/GusApi/ReportRegonNumberMapper.php | 8 +++--- src/GusApi/SearchReport.php | 6 ++--- tests/Client/GusApiClientTest.php | 12 ++++----- tests/Client/RequestDecoderTest.php | 10 +++---- tests/Context/ContextTest.php | 4 +-- tests/GusApiTest.php | 6 ++--- tests/SearchReportTest.php | 2 +- tests/Util/BulkReportResponseDecoderTest.php | 2 +- tests/Util/DataSearchDecoderTest.php | 2 +- tests/Util/FullReportResponseDecoderTest.php | 2 +- 19 files changed, 56 insertions(+), 59 deletions(-) diff --git a/.php_cs.dist b/.php_cs.dist index aeebee1..e73c39a 100644 --- a/.php_cs.dist +++ b/.php_cs.dist @@ -14,5 +14,6 @@ return PhpCsFixer\Config::create() 'phpdoc_order' => true, 'phpdoc_align' => true, 'ordered_imports' => true, + 'native_function_invocation' => true, ]) ->setFinder($finder); diff --git a/.travis.yml b/.travis.yml index af9f86b..4105be1 100644 --- a/.travis.yml +++ b/.travis.yml @@ -4,7 +4,7 @@ php: - 7.1 - 7.2 - 7.3 - - 7.4snapshot + - 7.4 allow_failures: php: nightly diff --git a/README.md b/README.md index c0cb966..4797f6f 100644 --- a/README.md +++ b/README.md @@ -46,12 +46,12 @@ New in 5.x (this version support BIR1.1) 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'; + 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` diff --git a/phpstan.neon b/phpstan.neon index fe6936b..f3ba514 100644 --- a/phpstan.neon +++ b/phpstan.neon @@ -1,6 +1,2 @@ parameters: reportUnmatchedIgnoredErrors: false - ignoreErrors: - - '#stream_context_set_option invoked with 2 parameters, 4#' - - '#GusApi\\Client\\SoapClient does not have a constructor#' - - '#Parameter \#1 $haystack of function stristr expects string, string|false given.#' \ No newline at end of file diff --git a/src/GusApi/Client/MultipartResponseDecoder.php b/src/GusApi/Client/MultipartResponseDecoder.php index fb361d8..7003702 100644 --- a/src/GusApi/Client/MultipartResponseDecoder.php +++ b/src/GusApi/Client/MultipartResponseDecoder.php @@ -11,6 +11,6 @@ class MultipartResponseDecoder */ public static function decode(string $response): string { - return stristr(stristr($response, '', true).''; + return \stristr((string) \stristr($response, '', true).''; } } diff --git a/src/GusApi/Client/SoapActionMapper.php b/src/GusApi/Client/SoapActionMapper.php index e0dacb1..5766b71 100644 --- a/src/GusApi/Client/SoapActionMapper.php +++ b/src/GusApi/Client/SoapActionMapper.php @@ -28,7 +28,7 @@ class SoapActionMapper public static function getAction(string $functionName): string { if (!isset(self::ACTIONS[$functionName])) { - throw new InvalidActionNameException(sprintf('Invalid action %s', $functionName)); + throw new InvalidActionNameException(\sprintf('Invalid action %s', $functionName)); } return self::ACTIONS[$functionName].$functionName; diff --git a/src/GusApi/Context/Context.php b/src/GusApi/Context/Context.php index 16bfea8..9b07c4c 100644 --- a/src/GusApi/Context/Context.php +++ b/src/GusApi/Context/Context.php @@ -14,27 +14,27 @@ class Context implements ContextInterface */ public function __construct() { - $this->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/Environment/EnvironmentFactory.php b/src/GusApi/Environment/EnvironmentFactory.php index ca72bf1..99eb611 100644 --- a/src/GusApi/Environment/EnvironmentFactory.php +++ b/src/GusApi/Environment/EnvironmentFactory.php @@ -20,6 +20,6 @@ public static function create(string $environment): EnvironmentInterface return new DevEnvironment(); } - throw new InvalidEnvironmentNameException(sprintf('Invalid environment %s', $environment)); + throw new InvalidEnvironmentNameException(\sprintf('Invalid environment %s', $environment)); } } diff --git a/src/GusApi/GusApi.php b/src/GusApi/GusApi.php index 99f6644..6dd7ebb 100644 --- a/src/GusApi/GusApi.php +++ b/src/GusApi/GusApi.php @@ -114,7 +114,7 @@ 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(); @@ -160,7 +160,7 @@ public function dataStatus(): DateTimeImmutable if (false === $dataStatus) { throw new InvalidServerResponseException( - sprintf( + \sprintf( 'Invalid response, expected date in format "%s" given %s', self::SERVICE_STATUS_DATE_FORMAT, $result->getGetValueResult() @@ -245,7 +245,7 @@ public function getByNips(array $nips): array { $this->checkIdentifiersCount($nips); - return $this->search(SearchType::NIPS, implode(',', $nips)); + return $this->search(SearchType::NIPS, \implode(',', $nips)); } /** @@ -259,7 +259,7 @@ public function getByKrses(array $krses): array { $this->checkIdentifiersCount($krses); - return $this->search(SearchType::KRSES, implode(',', $krses)); + return $this->search(SearchType::KRSES, \implode(',', $krses)); } /** @@ -273,7 +273,7 @@ public function getByRegons9(array $regons): array { $this->checkIdentifiersCount($regons); - return $this->search(SearchType::REGONS_9, implode(',', $regons)); + return $this->search(SearchType::REGONS_9, \implode(',', $regons)); } /** @@ -287,7 +287,7 @@ public function getByregons14(array $regons): array { $this->checkIdentifiersCount($regons); - return $this->search(SearchType::REGONS_14, implode(',', $regons)); + return $this->search(SearchType::REGONS_14, \implode(',', $regons)); } /** @@ -321,12 +321,12 @@ public function getFullReport(SearchReport $searchReport, string $reportName): a */ public function getBulkReport(DateTimeImmutable $date, string $reportName): array { - if (!in_array($reportName, BulkReportTypes::REPORTS, true)) { + if (!\in_array($reportName, BulkReportTypes::REPORTS, true)) { throw new InvalidReportTypeException( - sprintf( + \sprintf( 'Invalid report type: "%s", use one of allowed type: (%s)', $reportName, - implode(', ', BulkReportTypes::REPORTS) + \implode(', ', BulkReportTypes::REPORTS) ) ); } @@ -344,7 +344,7 @@ public function getBulkReport(DateTimeImmutable $date, string $reportName): arra */ public function getResultSearchMessage(): string { - return sprintf( + return \sprintf( "StatusSesji:%s\nKomunikatKod:%s\nKomunikatTresc:%s\n", $this->getSessionStatus(), $this->getMessageCode(), @@ -399,8 +399,8 @@ public function getSessionStatus(): int */ protected function checkIdentifiersCount(array $identifiers) { - if (count($identifiers) > self::MAX_IDENTIFIERS) { - throw new \InvalidArgumentException(sprintf( + if (\count($identifiers) > self::MAX_IDENTIFIERS) { + throw new \InvalidArgumentException(\sprintf( 'Too many identifiers. Maximum allowed is %d.', self::MAX_IDENTIFIERS )); @@ -423,7 +423,7 @@ private function search(string $searchType, string $parameters): array $result = $this->apiClient->searchData(new SearchData($searchParameters), $this->sessionId); - return array_map(function (SearchResponseCompanyData $company) { + return \array_map(function (SearchResponseCompanyData $company) { return new SearchReport($company); }, $result->getDaneSzukajResult()); } diff --git a/src/GusApi/ReportRegonNumberMapper.php b/src/GusApi/ReportRegonNumberMapper.php index 777945e..4030fbc 100644 --- a/src/GusApi/ReportRegonNumberMapper.php +++ b/src/GusApi/ReportRegonNumberMapper.php @@ -16,17 +16,17 @@ class ReportRegonNumberMapper */ public static function getRegonNumberByReportName(SearchReport $report, string $reportName): string { - if (!in_array($reportName, ReportTypes::REPORTS, true)) { + if (!\in_array($reportName, ReportTypes::REPORTS, true)) { throw new InvalidReportTypeException( - sprintf( + \sprintf( 'Invalid report type: "%s", use one of allowed type: (%s)', $reportName, - implode(', ', ReportTypes::REPORTS) + \implode(', ', ReportTypes::REPORTS) ) ); } - if (in_array($reportName, ReportTypes::REGON_9_REPORTS, true)) { + if (\in_array($reportName, ReportTypes::REGON_9_REPORTS, true)) { return $report->getRegon(); } diff --git a/src/GusApi/SearchReport.php b/src/GusApi/SearchReport.php index 87653c6..8f5d685 100644 --- a/src/GusApi/SearchReport.php +++ b/src/GusApi/SearchReport.php @@ -273,7 +273,7 @@ public function getActivityEndDate(): string */ private function makeRegon14(string $regon): string { - return str_pad($regon, 14, '0'); + return \str_pad($regon, 14, '0'); } /** @@ -283,7 +283,7 @@ private function makeRegon14(string $regon): string */ private function makeType($type): string { - return trim(strtolower($type)); + return \trim(\strtolower($type)); } /** @@ -291,6 +291,6 @@ private function makeType($type): string */ public function jsonSerialize(): array { - return get_object_vars($this); + return \get_object_vars($this); } } diff --git a/tests/Client/GusApiClientTest.php b/tests/Client/GusApiClientTest.php index 0a5bc53..58cf287 100644 --- a/tests/Client/GusApiClientTest.php +++ b/tests/Client/GusApiClientTest.php @@ -88,7 +88,7 @@ public function testGetValue(): void public function testSearchDataWithSingleResponse(): void { - $searchRawResponse = file_get_contents(__DIR__.'/../resources/response/searchDataResponseResultSingle.xsd'); + $searchRawResponse = \file_get_contents(__DIR__.'/../resources/response/searchDataResponseResultSingle.xsd'); $searchData = new SearchData((new SearchParameters())->setNip('0099112233')); $this->expectSoapCall('DaneSzukajPodmioty', [$searchData], new SearchResponseRaw($searchRawResponse)); @@ -118,7 +118,7 @@ public function testSearchDataWithSingleResponse(): void public function testSearchDataWithMultipleResponse(): void { - $searchRawResponse = file_get_contents(__DIR__.'/../resources/response/searchDataReponseResultMulti.xsd'); + $searchRawResponse = \file_get_contents(__DIR__.'/../resources/response/searchDataReponseResultMulti.xsd'); $searchData = new SearchData((new SearchParameters())->setNip('0099112233')); $this->expectSoapCall('DaneSzukajPodmioty', [$searchData], new SearchResponseRaw($searchRawResponse)); @@ -175,7 +175,7 @@ public function testSearchDataNotFound(): void public function testGetBulkReport(): void { - $searchRawResponse = file_get_contents(__DIR__.'/../resources/response/bulkReportResponse.xsd'); + $searchRawResponse = \file_get_contents(__DIR__.'/../resources/response/bulkReportResponse.xsd'); $searchData = new GetBulkReport('2019-01-01', 'BIR11NowePodmiotyPrawneOrazDzialalnosciOsFizycznych'); $this->expectSoapCall( @@ -194,7 +194,7 @@ public function testGetBulkReport(): void public function testGetFullReport(): void { - $searchRawResponse = file_get_contents(__DIR__.'/../resources/response/fullSearchResponse.xsd'); + $searchRawResponse = \file_get_contents(__DIR__.'/../resources/response/fullSearchResponse.xsd'); $searchData = new GetFullReport('00112233445566', 'PublDaneRaportTypJednostki'); $this->expectSoapCall( 'DanePobierzPelnyRaport', @@ -254,7 +254,7 @@ public function testGetFullReport(): void public function testGetFullReportMultiple() { - $searchRawResponse = file_get_contents(__DIR__.'/../resources/response/fullSearchMultipleResponse.xsd'); + $searchRawResponse = \file_get_contents(__DIR__.'/../resources/response/fullSearchMultipleResponse.xsd'); $searchData = new GetFullReport('00112233445566', 'PublDaneRaportDzialalnosciPrawnej'); $this->expectSoapCall( 'DanePobierzPelnyRaport', @@ -295,7 +295,7 @@ protected function getHeaders($action, $to) protected function expectSoapCall(string $action, array $arguments, $result, bool $public = true) { $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()) ->method('__soapCall') diff --git a/tests/Client/RequestDecoderTest.php b/tests/Client/RequestDecoderTest.php index b1346ea..c331a04 100644 --- a/tests/Client/RequestDecoderTest.php +++ b/tests/Client/RequestDecoderTest.php @@ -15,19 +15,19 @@ public function testDecodeRawRandomString() public function testDecodeValidSOAPResponse() { - $content = file_get_contents(__DIR__.'/../resources/validSOAPResponse.xsd'); + $content = \file_get_contents(__DIR__.'/../resources/validSOAPResponse.xsd'); $result = MultipartResponseDecoder::decode($content); - $this->assertEquals(trim($content), $result); + $this->assertEquals(\trim($content), $result); } public function testDecodeRawSOAPResponse() { - $content = file_get_contents(__DIR__.'/../resources/rawSOAPResponse.xsd'); - $valid = file_get_contents(__DIR__.'/../resources/validSOAPResponse.xsd'); + $content = \file_get_contents(__DIR__.'/../resources/rawSOAPResponse.xsd'); + $valid = \file_get_contents(__DIR__.'/../resources/validSOAPResponse.xsd'); $result = MultipartResponseDecoder::decode($content); - $this->assertEquals(trim($valid), $result); + $this->assertEquals(\trim($valid), $result); } public function testDecodeRawEnvelopeString() diff --git a/tests/Context/ContextTest.php b/tests/Context/ContextTest.php index d4dbc28..62cb938 100644 --- a/tests/Context/ContextTest.php +++ b/tests/Context/ContextTest.php @@ -27,7 +27,7 @@ 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() @@ -41,6 +41,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/GusApiTest.php b/tests/GusApiTest.php index 9929b36..fa5de43 100644 --- a/tests/GusApiTest.php +++ b/tests/GusApiTest.php @@ -224,7 +224,7 @@ public function testGetFullReport(): void public function testTooManyNipsRaisesAnException() { $this->expectException(\InvalidArgumentException::class); - $this->api->getByNips(array_fill(0, 21, '7740001454')); + $this->api->getByNips(\array_fill(0, 21, '7740001454')); } public function testGetResultSearchMessage(): void @@ -318,8 +318,8 @@ protected function expectGetValueCall(string $parameter, string $value) */ protected function getSearchParameters(string $parameter, $value): SearchParameters { - $setter = 'set'.ucfirst($parameter); - $value = is_array($value) ? implode(',', $value) : $value; + $setter = 'set'.\ucfirst($parameter); + $value = \is_array($value) ? \implode(',', $value) : $value; return (new SearchParameters())->$setter($value); } diff --git a/tests/SearchReportTest.php b/tests/SearchReportTest.php index 759f7d8..103ae8f 100644 --- a/tests/SearchReportTest.php +++ b/tests/SearchReportTest.php @@ -44,6 +44,6 @@ public function testIsJsonSerializable(): void 'propertyNumber' => '33', 'apartmentNumber' => '34B', 'activityEndDate' => '2029-02-22', - ], json_decode(json_encode(new SearchReport($companyData)), true)); + ], \json_decode(\json_encode(new SearchReport($companyData)), true)); } } diff --git a/tests/Util/BulkReportResponseDecoderTest.php b/tests/Util/BulkReportResponseDecoderTest.php index 2c1d725..2b736f6 100644 --- a/tests/Util/BulkReportResponseDecoderTest.php +++ b/tests/Util/BulkReportResponseDecoderTest.php @@ -11,7 +11,7 @@ class BulkReportResponseDecoderTest extends TestCase { public function testDecode(): void { - $content = file_get_contents(__DIR__.'/../resources/response/bulkReportResponse.xsd'); + $content = \file_get_contents(__DIR__.'/../resources/response/bulkReportResponse.xsd'); $rawResponse = new GetBulkReportResponseRaw($content); $decodedResponse = BulkReportResponseDecoder::decode($rawResponse); diff --git a/tests/Util/DataSearchDecoderTest.php b/tests/Util/DataSearchDecoderTest.php index 73594ee..8fdfb17 100644 --- a/tests/Util/DataSearchDecoderTest.php +++ b/tests/Util/DataSearchDecoderTest.php @@ -13,7 +13,7 @@ class DataSearchDecoderTest extends TestCase { public function testDecode(): void { - $content = file_get_contents(__DIR__.'/../resources/response/searchDataResponseResultSingle.xsd'); + $content = \file_get_contents(__DIR__.'/../resources/response/searchDataResponseResultSingle.xsd'); $rawResponse = new SearchResponseRaw($content); $decodedResponse = DataSearchDecoder::decode($rawResponse); diff --git a/tests/Util/FullReportResponseDecoderTest.php b/tests/Util/FullReportResponseDecoderTest.php index 9aed28b..4110005 100644 --- a/tests/Util/FullReportResponseDecoderTest.php +++ b/tests/Util/FullReportResponseDecoderTest.php @@ -21,7 +21,7 @@ public function testDecodeWithEmptyString() public function testDecodeWithValidXMLObject() { - $content = file_get_contents(__DIR__.'/../resources/response/fullSearchResponse.xsd'); + $content = \file_get_contents(__DIR__.'/../resources/response/fullSearchResponse.xsd'); $rawReport = new GetFullReportResponseRaw($content); $reportDecoded = FullReportResponseDecoder::decode($rawReport);