Skip to content

Commit

Permalink
Merge pull request #85 from IonBazan/phpunit-8
Browse files Browse the repository at this point in the history
allow PHPUnit 8
  • Loading branch information
johnzuk authored Dec 3, 2019
2 parents 7d5a4a3 + e901350 commit bc6da0b
Show file tree
Hide file tree
Showing 28 changed files with 141 additions and 104 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,5 @@ examples/captcha.jpeg
phpunit.xml
.php_cs.cache
.php_cs
composer.lock
.phpunit.result.cache
composer.lock
1 change: 1 addition & 0 deletions .php_cs.dist
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,6 @@ return PhpCsFixer\Config::create()
'phpdoc_order' => true,
'phpdoc_align' => true,
'ordered_imports' => true,
'native_function_invocation' => true,
])
->setFinder($finder);
1 change: 1 addition & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ php:
- 7.1
- 7.2
- 7.3
- 7.4

allow_failures:
php: nightly
Expand Down
12 changes: 6 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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`
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
},
Expand Down
4 changes: 0 additions & 4 deletions phpstan.neon
Original file line number Diff line number Diff line change
@@ -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.#'
2 changes: 1 addition & 1 deletion src/GusApi/Client/MultipartResponseDecoder.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,6 @@ class MultipartResponseDecoder
*/
public static function decode(string $response): string
{
return stristr(stristr($response, '<s:'), '</s:Envelope>', true).'</s:Envelope>';
return \stristr((string) \stristr($response, '<s:'), '</s:Envelope>', true).'</s:Envelope>';
}
}
2 changes: 1 addition & 1 deletion src/GusApi/Client/SoapActionMapper.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
10 changes: 5 additions & 5 deletions src/GusApi/Context/Context.php
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
2 changes: 1 addition & 1 deletion src/GusApi/Environment/EnvironmentFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}
}
26 changes: 13 additions & 13 deletions src/GusApi/GusApi.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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));
}

/**
Expand All @@ -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));
}

/**
Expand All @@ -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));
}

/**
Expand All @@ -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));
}

/**
Expand Down Expand Up @@ -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)
)
);
}
Expand All @@ -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(),
Expand Down Expand Up @@ -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
));
Expand All @@ -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());
}
Expand Down
8 changes: 4 additions & 4 deletions src/GusApi/ReportRegonNumberMapper.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}

Expand Down
6 changes: 3 additions & 3 deletions src/GusApi/SearchReport.php
Original file line number Diff line number Diff line change
Expand Up @@ -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');
}

/**
Expand All @@ -283,14 +283,14 @@ private function makeRegon14(string $regon): string
*/
private function makeType($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);
}
}
4 changes: 0 additions & 4 deletions src/GusApi/Util/BulkReportResponseDecoder.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,7 @@
class BulkReportResponseDecoder
{
/**
* @param GetBulkReportResponseRaw $bulkReportResponseRaw
*
* @throws InvalidServerResponseException
*
* @return array
*/
public static function decode(GetBulkReportResponseRaw $bulkReportResponseRaw): array
{
Expand Down
35 changes: 21 additions & 14 deletions src/GusApi/Util/DataSearchDecoder.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
Expand All @@ -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;
}
}
4 changes: 0 additions & 4 deletions src/GusApi/Util/FullReportResponseDecoder.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,7 @@
class FullReportResponseDecoder
{
/**
* @param GetFullReportResponseRaw $fullReportResponseRaw
*
* @throws InvalidServerResponseException
*
* @return GetFullReportResponse
*/
public static function decode(GetFullReportResponseRaw $fullReportResponseRaw): GetFullReportResponse
{
Expand Down
11 changes: 5 additions & 6 deletions tests/Client/BuilderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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();
}

Expand Down
Loading

0 comments on commit bc6da0b

Please sign in to comment.