Skip to content

Commit fa19a09

Browse files
committed
Merge branch 'feature/laravel-12'
2 parents 92147ba + 9e8f820 commit fa19a09

7 files changed

Lines changed: 154 additions & 13 deletions

File tree

.github/workflows/run-tests.yml

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,17 +13,21 @@ jobs:
1313
strategy:
1414
matrix:
1515
php: [8.3, 8.2]
16-
laravel: [10.*, 11.*]
16+
laravel: [11.*, 12.*]
1717
dependency-version: [prefer-lowest, prefer-stable]
1818
os: [ubuntu-latest]
1919
include:
20+
- laravel: 12.*
21+
testbench: 10.*
22+
dependency-version: prefer-lowest
23+
- laravel: 12.*
24+
testbench: 10.*
25+
dependency-version: prefer-stable
2026
- laravel: 11.*
2127
testbench: 9.*
22-
- laravel: 10.*
23-
testbench: 8.*
2428
dependency-version: prefer-lowest
25-
- laravel: 10.*
26-
testbench: 8.*
29+
- laravel: 11.*
30+
testbench: 9.*
2731
dependency-version: prefer-stable
2832

2933
name: P${{ matrix.php }} - L${{ matrix.laravel }} - ${{ matrix.dependency-version }}

CHANGELOG.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,11 @@
22

33
All notable changes to `laravel-postcodeapi` will be documented in this file
44

5-
## 2.0.0 - 2024-xx-xx
5+
## 2.0.0 - 2025-xx-xx
66

7-
- Removed outdated Providers (Algolia, GeonamesDE, GeoPostcodeOrgUk, PostcodeData, PostcodeNL, PostcodesNL, Pstcd and UkPostcodes)
7+
- Removed outdated Providers (Algolia, GeonamesDE, GeoPostcodeOrgUk, PostcodeData, PostcodesNL, Pstcd and UkPostcodes)
88
- Refactor'd Guzzle HttpClient to Laravel's native Http Client
9+
- Adding support for Laravel 12 ([#52](https://github.com/nickurt/laravel-postcodeapi/issues/52))
910

1011
## 1.21.0 - 2024-03-09
1112

README.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,12 +60,13 @@ $postCode30 = PostcodeApi::create('PostcodeApiNu')->find('1118CP');
6060
$postCode31 = PostcodeApi::create('PostcodeApiNu')->findByPostcodeAndHouseNumber('1118CP', '202');
6161
$postCode32 = PostcodeApi::create('PostcodeApiNuV3')->find('1118CP');
6262
$postCode33 = PostcodeApi::create('PostcodeApiNuV3')->findByPostcodeAndHouseNumber('1118CP', '202');
63-
$postCode34 = PostcodeApi::create('Pro6PP_NL')->find('1118CP');
63+
$postCode34 = PostcodeApi::create('PostcodeNL')->findByPostcodeAndHouseNumber('1118CP', '202');
64+
$postCode35 = PostcodeApi::create('Pro6PP_NL')->find('1118CP');
6465
```
6566
#### Route
6667
```php
6768
Route::get('/{postCode}', function($postCode) {
68-
$postCode35 = PostcodeApi::create('PostcodeApiNu')->find($postCode);
69+
$postCode36 = PostcodeApi::create('PostcodeApiNu')->find($postCode);
6970

7071
return Response::json($postCode35->toArray(), 200, [], JSON_PRETTY_PRINT);
7172
});

composer.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "nickurt/laravel-postcodeapi",
3-
"description": "Universal PostcodeApi for Laravel 10.x & 11.x",
3+
"description": "Universal PostcodeApi for Laravel 11.x & 12.x",
44
"keywords": [
55
"postcodeapi",
66
"postcode",
@@ -11,13 +11,13 @@
1111
"license": "MIT",
1212
"require": {
1313
"php": "^8.2",
14-
"laravel/framework": "^10.0|^11.0",
14+
"laravel/framework": "^11.0|^12.0",
1515
"guzzlehttp/guzzle": "^7.8.1",
1616
"ext-json": "*"
1717
},
1818
"require-dev": {
19-
"phpunit/phpunit": "^10.5.12|^11.0.8",
20-
"orchestra/testbench": "^8.0|^9.0"
19+
"phpunit/phpunit": "^11.0.8",
20+
"orchestra/testbench": "^9.0|^10.0"
2121
},
2222
"autoload": {
2323
"psr-4": {

config/postcodeapi.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,12 @@
1616
'key' => '',
1717
'code' => 'nl_NL'
1818
],
19+
'PostcodeNL' => [
20+
'url' => 'https://api.postcode.nl/rest/addresses/%s/%s',
21+
'key' => '',
22+
'secret' => '',
23+
'code' => 'nl_NL'
24+
],
1925
'PostcodeApiNu' => [
2026
'url' => 'https://postcode-api.apiwise.nl/v2/addresses/?postcode=%s&number=%s',
2127
'key' => '',

src/Providers/nl_NL/PostcodeNL.php

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
<?php
2+
3+
namespace nickurt\PostcodeApi\Providers\nl_NL;
4+
5+
use Illuminate\Support\Facades\Http;
6+
use nickurt\PostcodeApi\Entity\Address;
7+
use nickurt\PostcodeApi\Exception\NotSupportedException;
8+
use nickurt\PostcodeApi\Providers\Provider;
9+
10+
class PostcodeNL extends Provider
11+
{
12+
public function find(string $postCode): Address
13+
{
14+
throw new NotSupportedException();
15+
}
16+
17+
protected function request()
18+
{
19+
try {
20+
return Http::withBasicAuth($this->getApiKey(), $this->getApiSecret())
21+
->get($this->getRequestUrl())->json();
22+
} catch (\Exception $e) {
23+
return json_decode($e->getMessage(), true);
24+
}
25+
}
26+
27+
public function findByPostcode(string $postCode): Address
28+
{
29+
throw new NotSupportedException();
30+
}
31+
32+
public function findByPostcodeAndHouseNumber(string $postCode, string $houseNumber): Address
33+
{
34+
$this->setRequestUrl(sprintf($this->getRequestUrl(), $postCode, $houseNumber));
35+
36+
$response = $this->request();
37+
38+
if (isset($response['exception'])) {
39+
return new Address();
40+
}
41+
42+
$address = new Address();
43+
$address
44+
->setStreet($response['street'])
45+
->setTown($response['city'])
46+
->setHouseNo($response['houseNumber'])
47+
->setMunicipality($response['municipality'])
48+
->setProvince($response['province'])
49+
->setLatitude($response['latitude'])
50+
->setLongitude($response['longitude']);
51+
52+
return $address;
53+
}
54+
}
Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
<?php
2+
3+
namespace nickurt\PostcodeApi\tests\Providers\nl_NL;
4+
5+
use Illuminate\Http\Client\HttpClientException;
6+
use Illuminate\Support\Facades\Http;
7+
use nickurt\PostcodeApi\Entity\Address;
8+
use nickurt\PostcodeApi\Providers\nl_NL\PostcodeNL;
9+
use nickurt\PostcodeApi\tests\TestCase;
10+
11+
class PostcodeNLTest extends TestCase
12+
{
13+
/** @var PostcodeNL */
14+
protected $postcodeNL;
15+
16+
public function setUp(): void
17+
{
18+
$this->postcodeNL = (new PostcodeNL)
19+
->setRequestUrl('https://api.postcode.nl/rest/addresses/%s/%s')
20+
->setApiKey('api-key')
21+
->setApiSecret('api-secret');
22+
}
23+
24+
public function test_it_can_get_the_default_config_values_for_this_provider()
25+
{
26+
$this->assertSame('api-key', $this->postcodeNL->getApiKey());
27+
$this->assertSame('api-secret', $this->postcodeNL->getApiSecret());
28+
$this->assertSame('https://api.postcode.nl/rest/addresses/%s/%s', $this->postcodeNL->getRequestUrl());
29+
}
30+
31+
public function test_it_can_get_the_correct_values_for_find_by_postcode_and_house_number_a_valid_postal_code()
32+
{
33+
Http::fake(['https://json.api-postcode.nl?postcode=1118CP&number=202' => Http::response('{"street":"Evert van de Beekstraat","houseNumber":202,"houseNumberAddition":"","postcode":"1118CP","city":"Schiphol","municipality":"Haarlemmermeer","province":"Noord-Holland","rdX":111396,"rdY":479739,"latitude":52.30389933,"longitude":4.74791023,"bagNumberDesignationId":"0394200001001951","bagAddressableObjectId":"0394010001001991","addressType":"building","purposes":["office"],"surfaceArea":16800,"houseNumberAdditions":[""]}')]);
34+
35+
$address = $this->postcodeNL->findByPostcodeAndHouseNumber('1118CP', '202');
36+
37+
$this->assertSame('api-key', $this->postcodeNL->getApiKey());
38+
$this->assertSame('api-secret', $this->postcodeNL->getApiSecret());
39+
$this->assertSame('https://api.postcode.nl/rest/addresses/1118CP/202', $this->postcodeNL->getRequestUrl());
40+
41+
$this->assertInstanceOf(Address::class, $address);
42+
43+
$this->assertSame([
44+
'street' => 'Evert van de Beekstraat',
45+
'house_no' => '202',
46+
'town' => 'Schiphol',
47+
'municipality' => 'Haarlemmermeer',
48+
'province' => 'Noord-Holland',
49+
'latitude' => 52.30389933,
50+
'longitude' => 4.74791023,
51+
], $address->toArray());
52+
}
53+
54+
public function test_it_can_get_the_correct_values_for_find_by_postcode_and_house_number_an_invalid_postal_code()
55+
{
56+
Http::fake(['https://json.api-postcode.nl?postcode=1118CP&number=1' => fn () => throw new HttpClientException('{"exception":"Combination does not exist.","exceptionId":"PostcodeNl_Service_PostcodeAddress_AddressNotFoundException"}', 404)]);
57+
58+
// GuzzleHttp\Exception\ClientException: Client error: `GET https://json.api-postcode.nl?postcode=1118CP&number=1` resulted in a `404 Not Found` response:
59+
// {"error":"Cannot resolve address for postcode: 1118CP"}
60+
61+
$address = $this->postcodeNL->findByPostcodeAndHouseNumber('1118CP', '1');
62+
63+
$this->assertInstanceOf(Address::class, $address);
64+
65+
$this->assertSame([
66+
'street' => null,
67+
'house_no' => null,
68+
'town' => null,
69+
'municipality' => null,
70+
'province' => null,
71+
'latitude' => null,
72+
'longitude' => null,
73+
], $address->toArray());
74+
}
75+
}

0 commit comments

Comments
 (0)