Skip to content

Commit

Permalink
more work toward 3.0.1
Browse files Browse the repository at this point in the history
  • Loading branch information
ericsizemore committed Mar 12, 2024
1 parent 129279c commit a1bd08b
Show file tree
Hide file tree
Showing 21 changed files with 202 additions and 251 deletions.
8 changes: 7 additions & 1 deletion .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -49,4 +49,10 @@ jobs:

- uses: sudo-bot/action-scrutinizer@latest
with:
cli-args: "--format=php-clover build/logs/clover.xml"
cli-args: "--format=php-clover build/logs/clover.xml"

- name: Upload coverage reports to Codecov
uses: codecov/codecov-action@v4.0.1
with:
token: ${{ secrets.CODECOV_TOKEN }}
slug: ericsizemore/numverify-api-client-php
2 changes: 1 addition & 1 deletion .php-cs-fixer.dist.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@
],
],
'heredoc_to_nowdoc' => true,
'ordered_imports' => false,
'ordered_imports' => ['imports_order' => ['class', 'function', 'const',]],
'declare_equal_normalize' => ['space' => 'none'],
'declare_parentheses' => true,
'declare_strict_types' => true,
Expand Down
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,12 @@ Simply replace the version numbers depending on which set of changes you wish to
#### Added

* `vimeo/psalm` added into dev-dependencies and workflow
* `TestDox` attribute used for all unit tests instead of '@testCase' (work in progress)

#### Removed

* Removed unnecessary constructor and properties from `Numverify\Exception\NumverifyApiResponseException`
* Removed '@testCase' annotation from all unit tests.

### 3.0.0 (2024-03-10)

Expand Down
6 changes: 3 additions & 3 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -46,11 +46,11 @@
"phpstan/phpstan-phpunit": "^1.4",
"phpstan/phpstan-strict-rules": "^1.6",
"phpunit/phpunit": "^11.0",
"vimeo/psalm": "dev-master",
"psalm/plugin-phpunit": "^0.18.4"
"psalm/plugin-phpunit": "^0.18.4",
"vimeo/psalm": "dev-master"
},
"replace": {
"markrogoyski/numverify-api-client-php": "~2.1"
"markrogoyski/numverify-api-client-php": "^2.1"
},
"minimum-stability": "dev",
"prefer-stable": true,
Expand Down
26 changes: 13 additions & 13 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions phpunit.xml
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,7 @@
<html outputDirectory="build/logs/coverage" />
</report>
</coverage>
<logging>
<testdoxHtml outputFile="build/logs/testdox.html"/>
</logging>
</phpunit>
7 changes: 6 additions & 1 deletion psalm.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@
xmlns="https://getpsalm.org/schema/config"
xsi:schemaLocation="https://getpsalm.org/schema/config vendor/vimeo/psalm/config.xsd"
findUnusedBaselineEntry="true"
findUnusedPsalmSuppress="true"
findUnusedCode="true"
limitMethodComplexity="true"
>
<projectFiles>
<directory name="src"/>
Expand All @@ -15,4 +17,7 @@
<directory name="vendor"/>
</ignoreFiles>
</projectFiles>
<plugins><pluginClass class="Psalm\PhpUnitPlugin\Plugin"/></plugins></psalm>
<plugins>
<pluginClass class="Psalm\PhpUnitPlugin\Plugin"/>
</plugins>
</psalm>
9 changes: 4 additions & 5 deletions src/Api.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@
use GuzzleHttp\{
Client,
ClientInterface,
Exception\ServerException,
Exception\GuzzleException,
Exception\ServerException,
HandlerStack
};
use Kevinrob\GuzzleCache\{
Expand All @@ -29,16 +29,16 @@
Strategy\PrivateCacheStrategy
};
use Numverify\{
Country\Country,
Country\Collection,
Country\Country,
Exception\NumverifyApiFailureException,
PhoneNumber\Factory,
PhoneNumber\PhoneNumberInterface
};
use Psr\Http\Message\ResponseInterface;
use SensitiveParameter;
use Symfony\Component\Cache\Adapter\FilesystemAdapter;
use stdClass;
use Symfony\Component\Cache\Adapter\FilesystemAdapter;

use function array_keys;
use function array_map;
Expand Down Expand Up @@ -207,8 +207,7 @@ private static function getUrl(bool $useHttps): string
*
* If everything looks good, it returns the decoded jSON data based on $asArray.
*
* @param ResponseInterface $response
* @param bool $asArray If true, returns the decoded jSON as an assoc. array, stdClass otherwise.
* @param bool $asArray If true, returns the decoded jSON as an assoc. array, stdClass otherwise.
*
* @return stdClass | ApiJsonArray | ApiCountryJsonArray
*
Expand Down
4 changes: 2 additions & 2 deletions src/Country/Collection.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@
* Role: Collection of callable countries.
*
* @implements Iterator<Country>
*
* @see \Numverify\Tests\Country\CollectionTest
*/
class Collection implements Iterator, Countable, JsonSerializable
{
Expand Down Expand Up @@ -70,8 +72,6 @@ public function findByCountryName(string $countryName): ?Country

/**
* @inheritDoc
*
* @psalm-suppress PossiblyUnusedMethod
*/
public function count(): int
{
Expand Down
2 changes: 2 additions & 0 deletions src/Country/Country.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@
/**
* Country
* Role: Value object that represents a callable country.
*
* @see \Numverify\Tests\Country\CountryTest
*/
readonly class Country implements Stringable, JsonSerializable
{
Expand Down
8 changes: 5 additions & 3 deletions src/Exception/NumverifyApiFailureException.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,18 @@

namespace Numverify\Exception;

use RuntimeException;
use Psr\Http\Message\ResponseInterface;
use RuntimeException;

use stdClass;

use function json_decode;
use function sprintf;

use stdClass;

/**
* Thrown when the Numverify API returns a failure response.
*
* @see \Numverify\Tests\Exception\NumverifyApiFailureExceptionTest
*/
class NumverifyApiFailureException extends RuntimeException
{
Expand Down
2 changes: 2 additions & 0 deletions src/Exception/NumverifyApiResponseException.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,7 @@

/**
* Thrown when the Numverify API returns an API response that is unexpected.
*
* @see \Numverify\Tests\Exception\NumverifyApiResponseExceptionTest
*/
class NumverifyApiResponseException extends RuntimeException {}
45 changes: 17 additions & 28 deletions tests/ApiCountryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,23 +18,24 @@

use GuzzleHttp\{
ClientInterface,
Handler\MockHandler,
HandlerStack,
Handler\MockHandler,
Psr7\Response
};
use Iterator;
use PHPUnit\Framework\{
Attributes\CoversClass,
Attributes\DataProvider,
TestCase,
MockObject\MockObject
};
use Numverify\{
Api,
Country\Collection,
Country\Country,
Exception\NumverifyApiFailureException
};
use PHPUnit\Framework\{
Attributes\CoversClass,
Attributes\DataProvider,
Attributes\TestDox,
MockObject\MockObject,
TestCase
};

/**
* @internal
Expand All @@ -47,31 +48,25 @@ class ApiCountryTest extends TestCase
{
private const ACCESS_KEY = 'SomeAccessKey';

/**
* @testCase getCountries success.
*/
#[DataProvider('dataProviderForHttp')]
#[TestDox('getCountries returns the correct count, with $useHttps.')]
public function testCountriesApiReturnsNumberOfCountries(bool $useHttps): void
{
$countryCollection = $this->aClient(useHttps: $useHttps)->getCountries();
self::assertCount(3, $countryCollection);
}

/**
* @testCase getCountries success
*/
#[DataProvider('dataProviderForHttp')]
#[TestDox('getCountries returns a Collection containing Country instances, with $useHttps.')]
public function testCountriesReturnsCollectionOfCountries(bool $useHttps): void
{
$countryCollection = $this->aClient(useHttps: $useHttps)->getCountries();
self::assertInstanceOf(Collection::class, $countryCollection); // @phpstan-ignore-line
self::assertContainsOnlyInstancesOf(Country::class, $countryCollection);
}

/**
* @testCase getCountries success.
*/
#[DataProvider('dataProviderForHttp')]
#[TestDox('getCountries returns expected country information with $useHttps.')]
public function testCountriesReturnsExpectedCountries(bool $useHttps): void
{
$expectedCountries = ['JP' => false, 'GB' => false, 'US' => false];
Expand All @@ -88,10 +83,8 @@ public function testCountriesReturnsExpectedCountries(bool $useHttps): void
}
}

/**
* @testCase getCountries exception - invalid access key.
*/
#[DataProvider('dataProviderForHttp')]
#[TestDox('Given an invalid api access key, getCountries returns expected error information with $useHttps.')]
public function testCountriesInvalidAccessKey(bool $useHttps): void
{
$mockHandler = new MockHandler([
Expand All @@ -112,11 +105,9 @@ public function testCountriesInvalidAccessKey(bool $useHttps): void
$stub->getCountries();
}

/**
* @testCase getCountries exception - API server error.
*/
#[DataProvider('dataProviderForHttp')]
public function testValidatePhoneNumberServerError(bool $useHttps): void
#[TestDox('Given a 500 server error response, getCountries returns appropriate exception with $useHttps.')]
public function testCountriesServerError(bool $useHttps): void
{
$mockHandler = new MockHandler([
new Response(500),
Expand All @@ -127,11 +118,9 @@ public function testValidatePhoneNumberServerError(bool $useHttps): void
$stub->getCountries();
}

/**
* @testCase getCountries exception - API bad response
*/
#[DataProvider('dataProviderForHttp')]
public function testValidatePhoneNumberBadResponse(bool $useHttps): void
#[TestDox('Given a non-200 response, getCountries returns appropriate exception with $useHttps.')]
public function testCountriesBadResponse(bool $useHttps): void
{
$mockHandler = new MockHandler([
new Response(202),
Expand All @@ -152,7 +141,7 @@ public static function dataProviderForHttp(): Iterator
}

/**
* Given a client.
* Creates a mock client for testing.
*/
private function aClient(
string $accessKey = self::ACCESS_KEY,
Expand Down

0 comments on commit a1bd08b

Please sign in to comment.