-
Notifications
You must be signed in to change notification settings - Fork 28
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fixed bug in detecting array value type when first element was null
- Loading branch information
1 parent
cb98b18
commit 51bd525
Showing
6 changed files
with
163 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
33 changes: 33 additions & 0 deletions
33
src/core/etl/tests/Flow/ETL/Tests/Unit/PHP/Type/TypeDetector/Fixtures/github_user_event.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
{ | ||
"id": "42298808514", | ||
"type": "CreateEvent", | ||
"actor": { | ||
"id": 1921950, | ||
"login": "norberttech", | ||
"display_login": "norberttech", | ||
"gravatar_id": "", | ||
"url": "https:\/\/api.github.com\/users\/norberttech", | ||
"avatar_url": "https:\/\/avatars.githubusercontent.com\/u\/1921950?" | ||
}, | ||
"repo": { | ||
"id": 863548915, | ||
"name": "flow-php\/symfony-http-foundation-bridge", | ||
"url": "https:\/\/api.github.com\/repos\/flow-php\/symfony-http-foundation-bridge" | ||
}, | ||
"payload": { | ||
"ref": null, | ||
"ref_type": "repository", | ||
"master_branch": "main", | ||
"description": "Flow PHP Symfony Http Foundation Bridge", | ||
"pusher_type": "user" | ||
}, | ||
"public": true, | ||
"created_at": "2024-09-26T13:39:50Z", | ||
"org": { | ||
"id": 73495297, | ||
"login": "flow-php", | ||
"gravatar_id": "", | ||
"url": "https:\/\/api.github.com\/orgs\/flow-php", | ||
"avatar_url": "https:\/\/avatars.githubusercontent.com\/u\/73495297?" | ||
} | ||
} |
54 changes: 54 additions & 0 deletions
54
src/core/etl/tests/Flow/ETL/Tests/Unit/PHP/Type/TypeDetector/StructuresTypeDetectorTest.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Flow\ETL\Tests\Unit\PHP\Type\TypeDetector; | ||
|
||
use function Flow\ETL\DSL\{structure_element, type_boolean, type_int, type_map, type_string, type_structure}; | ||
use Flow\ETL\PHP\Type\TypeDetector; | ||
use PHPUnit\Framework\TestCase; | ||
|
||
final class StructuresTypeDetectorTest extends TestCase | ||
{ | ||
public function test_detecting_structures_with_nested_arrays() : void | ||
{ | ||
$typeDetector = new TypeDetector(); | ||
|
||
$structure = \json_decode(\file_get_contents(__DIR__ . '/Fixtures/github_user_event.json'), true, 512, JSON_THROW_ON_ERROR); | ||
$type = $typeDetector->detectType($structure); | ||
|
||
self::assertEquals( | ||
type_structure([ | ||
structure_element('id', type_string()), | ||
structure_element('type', type_string()), | ||
structure_element('actor', type_structure([ | ||
structure_element('id', type_int()), | ||
structure_element('login', type_string()), | ||
structure_element('display_login', type_string()), | ||
structure_element('gravatar_id', type_string()), | ||
structure_element('url', type_string()), | ||
structure_element('avatar_url', type_string()), | ||
])), | ||
structure_element('repo', type_structure([ | ||
structure_element('id', type_int()), | ||
structure_element('name', type_string()), | ||
structure_element('url', type_string()), | ||
])), | ||
structure_element('payload', type_map( | ||
key_type: type_string(), | ||
value_type: type_string(true) | ||
)), | ||
structure_element('public', type_boolean()), | ||
structure_element('created_at', type_string()), | ||
structure_element('org', type_structure([ | ||
structure_element('id', type_int()), | ||
structure_element('login', type_string()), | ||
structure_element('gravatar_id', type_string()), | ||
structure_element('url', type_string()), | ||
structure_element('avatar_url', type_string()), | ||
])), | ||
]), | ||
$type, | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters