-
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
142 additions
and
1 deletion.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
<?php | ||
declare(strict_types=1); | ||
|
||
namespace Soap\WsdlReader\Metadata\Predicate; | ||
|
||
use Soap\Engine\Metadata\Model\TypeMeta; | ||
|
||
final class IsConsideredNullableType | ||
{ | ||
public function __invoke(TypeMeta $meta): bool | ||
{ | ||
if ($meta->isNullable()->unwrapOr(false)) { | ||
return true; | ||
} | ||
|
||
if ($meta->isNil()->unwrapOr(false)) { | ||
return true; | ||
} | ||
|
||
if ($meta->isAttribute()->unwrapOr(false)) { | ||
// If no 'use' is defined, XSD attributes get an implicit default "optional" value | ||
if ($meta->use()->unwrapOr('optional') === 'optional') { | ||
return true; | ||
} | ||
} | ||
|
||
return false; | ||
} | ||
} |
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,15 @@ | ||
<?php | ||
declare(strict_types=1); | ||
|
||
namespace Soap\WsdlReader\Metadata\Predicate; | ||
|
||
use Soap\Engine\Metadata\Model\TypeMeta; | ||
|
||
final class IsConsideredScalarType | ||
{ | ||
public function __invoke(TypeMeta $meta): bool | ||
{ | ||
return $meta->isSimple()->unwrapOr(false) | ||
|| $meta->isAttribute()->unwrapOr(false); | ||
} | ||
} |
60 changes: 60 additions & 0 deletions
60
tests/Unit/Metadata/Predicate/IsConsideredNullableTypeTest.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,60 @@ | ||
<?php | ||
declare(strict_types=1); | ||
|
||
namespace Soap\WsdlReader\Test\Unit\Metadata\Predicate; | ||
|
||
use PHPUnit\Framework\TestCase; | ||
use Soap\Engine\Metadata\Model\TypeMeta; | ||
use Soap\WsdlReader\Metadata\Predicate\IsConsideredNullableType; | ||
|
||
final class IsConsideredNullableTypeTest extends TestCase | ||
{ | ||
/** | ||
* @dataProvider provideTests | ||
* | ||
*/ | ||
public function test_it_knows_if_a_type_is_considered_nullable(TypeMeta $meta, bool $expected): void | ||
{ | ||
static::assertSame($expected, (new IsConsideredNullableType())($meta)); | ||
} | ||
|
||
public static function provideTests() | ||
{ | ||
yield 'empty' => [ | ||
(new TypeMeta()), | ||
false, | ||
]; | ||
yield 'nullable' => [ | ||
(new TypeMeta())->withIsNullable(true), | ||
true, | ||
]; | ||
yield 'not-nullable' => [ | ||
(new TypeMeta())->withIsNullable(false), | ||
false, | ||
]; | ||
yield 'nillable' => [ | ||
(new TypeMeta())->withIsNil(true), | ||
true, | ||
]; | ||
yield 'not-nillable' => [ | ||
(new TypeMeta())->withIsNil(false), | ||
false, | ||
]; | ||
yield 'default-attribute' => [ | ||
(new TypeMeta())->withIsAttribute(true), | ||
true, | ||
]; | ||
yield 'optional-attribute' => [ | ||
(new TypeMeta())->withIsAttribute(true)->withUse('optional'), | ||
true, | ||
]; | ||
yield 'required-attribute' => [ | ||
(new TypeMeta())->withIsAttribute(true)->withUse('required'), | ||
false, | ||
]; | ||
yield 'prohibit-attribute' => [ | ||
(new TypeMeta())->withIsAttribute(true)->withUse('prohibit'), | ||
false, | ||
]; | ||
} | ||
} |
36 changes: 36 additions & 0 deletions
36
tests/Unit/Metadata/Predicate/IsConsideredScalarTypeTest.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,36 @@ | ||
<?php | ||
declare(strict_types=1); | ||
|
||
namespace Soap\WsdlReader\Test\Unit\Metadata\Predicate; | ||
|
||
use PHPUnit\Framework\TestCase; | ||
use Soap\Engine\Metadata\Model\TypeMeta; | ||
use Soap\WsdlReader\Metadata\Predicate\IsConsideredScalarType; | ||
|
||
final class IsConsideredScalarTypeTest extends TestCase | ||
{ | ||
/** | ||
* @dataProvider provideTests | ||
* | ||
*/ | ||
public function test_it_knows_if_a_type_is_considered_scalar(TypeMeta $meta, bool $expected): void | ||
{ | ||
static::assertSame($expected, (new IsConsideredScalarType())($meta)); | ||
} | ||
|
||
public static function provideTests() | ||
{ | ||
yield 'not' => [ | ||
(new TypeMeta()), | ||
false, | ||
]; | ||
yield 'simple' => [ | ||
(new TypeMeta())->withIsSimple(true), | ||
true, | ||
]; | ||
yield 'attribute' => [ | ||
(new TypeMeta())->withIsSimple(true), | ||
true, | ||
]; | ||
} | ||
} |