From ef7d2f36769cfa3764b663978458ef50df7e8408 Mon Sep 17 00:00:00 2001 From: Norbert Orzechowicz Date: Sun, 28 Jan 2024 11:48:25 +0100 Subject: [PATCH] Remove schema definition constraint and simlify metadatA --- src/core/etl/docs/new_type.md | 1 - src/core/etl/src/Flow/ETL/DSL/functions.php | 60 ++++++------ .../src/Flow/ETL/Row/Schema/Constraint.php | 12 --- .../Flow/ETL/Row/Schema/Constraint/All.php | 32 ------ .../Flow/ETL/Row/Schema/Constraint/Any.php | 32 ------ .../Row/Schema/Constraint/IsInstanceOf.php | 23 ----- .../ETL/Row/Schema/Constraint/ListType.php | 27 ------ .../ETL/Row/Schema/Constraint/NotEmpty.php | 27 ------ .../Flow/ETL/Row/Schema/Constraint/SameAs.php | 20 ---- .../Row/Schema/Constraint/VoidConstraint.php | 16 --- .../src/Flow/ETL/Row/Schema/Definition.php | 97 ++++++------------- .../etl/src/Flow/ETL/Row/Schema/Metadata.php | 16 +-- .../Unit/Row/Schema/Constraint/AnyTest.php | 34 ------- .../Schema/Constraint/IsInstanceOfTest.php | 18 ---- .../Row/Schema/Constraint/NotEmptyTest.php | 60 ------------ .../Unit/Row/Schema/Constraint/SameAsTest.php | 18 ---- .../Tests/Unit/Row/Schema/DefinitionTest.php | 82 +--------------- .../Tests/Unit/Row/Schema/MetadataTest.php | 10 -- 18 files changed, 69 insertions(+), 516 deletions(-) delete mode 100644 src/core/etl/src/Flow/ETL/Row/Schema/Constraint.php delete mode 100644 src/core/etl/src/Flow/ETL/Row/Schema/Constraint/All.php delete mode 100644 src/core/etl/src/Flow/ETL/Row/Schema/Constraint/Any.php delete mode 100644 src/core/etl/src/Flow/ETL/Row/Schema/Constraint/IsInstanceOf.php delete mode 100644 src/core/etl/src/Flow/ETL/Row/Schema/Constraint/ListType.php delete mode 100644 src/core/etl/src/Flow/ETL/Row/Schema/Constraint/NotEmpty.php delete mode 100644 src/core/etl/src/Flow/ETL/Row/Schema/Constraint/SameAs.php delete mode 100644 src/core/etl/src/Flow/ETL/Row/Schema/Constraint/VoidConstraint.php delete mode 100644 src/core/etl/tests/Flow/ETL/Tests/Unit/Row/Schema/Constraint/AnyTest.php delete mode 100644 src/core/etl/tests/Flow/ETL/Tests/Unit/Row/Schema/Constraint/IsInstanceOfTest.php delete mode 100644 src/core/etl/tests/Flow/ETL/Tests/Unit/Row/Schema/Constraint/NotEmptyTest.php delete mode 100644 src/core/etl/tests/Flow/ETL/Tests/Unit/Row/Schema/Constraint/SameAsTest.php diff --git a/src/core/etl/docs/new_type.md b/src/core/etl/docs/new_type.md index d60a2f161..823330bce 100644 --- a/src/core/etl/docs/new_type.md +++ b/src/core/etl/docs/new_type.md @@ -5,5 +5,4 @@ interface, below you can find list of things that must be checked. * Schema * [Definition](../src/Flow/ETL/Row/Schema/Definition.php) - * [Constraint](../src/Flow/ETL/Row/Schema/Constraint.php) * [EntryFactory](../src/Flow/ETL/Row/EntryFactory.php) \ No newline at end of file diff --git a/src/core/etl/src/Flow/ETL/DSL/functions.php b/src/core/etl/src/Flow/ETL/DSL/functions.php index 9775b8f10..0f5b6bbec 100644 --- a/src/core/etl/src/Flow/ETL/DSL/functions.php +++ b/src/core/etl/src/Flow/ETL/DSL/functions.php @@ -1007,52 +1007,52 @@ function schema(Definition ...$definitions) : Schema return new Schema(...$definitions); } -function int_schema(string $name, bool $nullable = false, ?Schema\Constraint $constraint = null, ?Schema\Metadata $metadata = null) : Definition +function int_schema(string $name, bool $nullable = false, ?Schema\Metadata $metadata = null) : Definition { - return Definition::integer($name, $nullable, $constraint, $metadata); + return Definition::integer($name, $nullable, $metadata); } -function str_schema(string $name, bool $nullable = false, ?Schema\Constraint $constraint = null, ?Schema\Metadata $metadata = null) : Definition +function str_schema(string $name, bool $nullable = false, ?Schema\Metadata $metadata = null) : Definition { - return Definition::string($name, $nullable, $constraint, $metadata); + return Definition::string($name, $nullable, $metadata); } -function bool_schema(string $name, bool $nullable = false, ?Schema\Constraint $constraint = null, ?Schema\Metadata $metadata = null) : Definition +function bool_schema(string $name, bool $nullable = false, ?Schema\Metadata $metadata = null) : Definition { - return Definition::boolean($name, $nullable, $constraint, $metadata); + return Definition::boolean($name, $nullable, $metadata); } -function float_schema(string $name, bool $nullable = false, ?Schema\Constraint $constraint = null, ?Schema\Metadata $metadata = null) : Definition +function float_schema(string $name, bool $nullable = false, ?Schema\Metadata $metadata = null) : Definition { - return Definition::float($name, $nullable, $constraint, $metadata); + return Definition::float($name, $nullable, $metadata); } -function array_schema(string $name, bool $empty = false, bool $nullable = false, ?Schema\Constraint $constraint = null, ?Schema\Metadata $metadata = null) : Definition +function array_schema(string $name, bool $empty = false, bool $nullable = false, ?Schema\Metadata $metadata = null) : Definition { - return Definition::array($name, $empty, $nullable, $constraint, $metadata); + return Definition::array($name, $empty, $nullable, $metadata); } -function object_schema(string $name, ObjectType $type, ?Schema\Constraint $constraint = null, ?Schema\Metadata $metadata = null) : Definition +function object_schema(string $name, ObjectType $type, ?Schema\Metadata $metadata = null) : Definition { - return Definition::object($name, $type, $constraint, $metadata); + return Definition::object($name, $type, $metadata); } -function map_schema(string $name, MapType $type, ?Schema\Constraint $constraint = null, ?Schema\Metadata $metadata = null) : Definition +function map_schema(string $name, MapType $type, ?Schema\Metadata $metadata = null) : Definition { - return Definition::map($name, $type, $constraint, $metadata); + return Definition::map($name, $type, $metadata); } -function list_schema(string $name, ListType $type, ?Schema\Constraint $constraint = null, ?Schema\Metadata $metadata = null) : Definition +function list_schema(string $name, ListType $type, ?Schema\Metadata $metadata = null) : Definition { - return Definition::list($name, $type, $constraint, $metadata); + return Definition::list($name, $type, $metadata); } /** * @param class-string<\UnitEnum> $type */ -function enum_schema(string $name, string $type, bool $nullable = false, ?Schema\Constraint $constraint = null, ?Schema\Metadata $metadata = null) : Definition +function enum_schema(string $name, string $type, bool $nullable = false, ?Schema\Metadata $metadata = null) : Definition { - return Definition::enum($name, $type, $nullable, $constraint, $metadata); + return Definition::enum($name, $type, $nullable, $metadata); } function null_schema(string $name, ?Schema\Metadata $metadata = null) : Definition @@ -1060,34 +1060,34 @@ function null_schema(string $name, ?Schema\Metadata $metadata = null) : Definiti return Definition::null($name, $metadata); } -function datetime_schema(string $name, bool $nullable = false, ?Schema\Constraint $constraint = null, ?Schema\Metadata $metadata = null) : Definition +function datetime_schema(string $name, bool $nullable = false, ?Schema\Metadata $metadata = null) : Definition { - return Definition::datetime($name, $nullable, $constraint, $metadata); + return Definition::datetime($name, $nullable, $metadata); } -function json_schema(string $name, bool $nullable = false, ?Schema\Constraint $constraint = null, ?Schema\Metadata $metadata = null) : Definition +function json_schema(string $name, bool $nullable = false, ?Schema\Metadata $metadata = null) : Definition { - return Definition::json($name, $nullable, $constraint, $metadata); + return Definition::json($name, $nullable, $metadata); } -function xml_schema(string $name, bool $nullable = false, ?Schema\Constraint $constraint = null, ?Schema\Metadata $metadata = null) : Definition +function xml_schema(string $name, bool $nullable = false, ?Schema\Metadata $metadata = null) : Definition { - return Definition::xml($name, $nullable, $constraint, $metadata); + return Definition::xml($name, $nullable, $metadata); } -function xml_node_schema(string $name, bool $nullable = false, ?Schema\Constraint $constraint = null, ?Schema\Metadata $metadata = null) : Definition +function xml_node_schema(string $name, bool $nullable = false, ?Schema\Metadata $metadata = null) : Definition { - return Definition::xml_node($name, $nullable, $constraint, $metadata); + return Definition::xml_node($name, $nullable, $metadata); } -function struct_schema(string $name, StructureType $type, ?Schema\Constraint $constraint = null, ?Schema\Metadata $metadata = null) : Definition +function struct_schema(string $name, StructureType $type, ?Schema\Metadata $metadata = null) : Definition { - return Definition::structure($name, $type, $constraint, $metadata); + return Definition::structure($name, $type, $metadata); } -function uuid_schema(string $name, bool $nullable = false, ?Schema\Constraint $constraint = null, ?Schema\Metadata $metadata = null) : Definition +function uuid_schema(string $name, bool $nullable = false, ?Schema\Metadata $metadata = null) : Definition { - return Definition::uuid($name, \uuid_type($nullable), $constraint, $metadata); + return Definition::uuid($name, \uuid_type($nullable), $metadata); } function execution_context(?Config $config = null) : FlowContext diff --git a/src/core/etl/src/Flow/ETL/Row/Schema/Constraint.php b/src/core/etl/src/Flow/ETL/Row/Schema/Constraint.php deleted file mode 100644 index ad0167f2f..000000000 --- a/src/core/etl/src/Flow/ETL/Row/Schema/Constraint.php +++ /dev/null @@ -1,12 +0,0 @@ - - */ - private readonly array $constraints; - - public function __construct(Constraint ...$constraints) - { - $this->constraints = $constraints; - } - - public function isSatisfiedBy(Entry $entry) : bool - { - foreach ($this->constraints as $constraint) { - if (!$constraint->isSatisfiedBy($entry)) { - return false; - } - } - - return true; - } -} diff --git a/src/core/etl/src/Flow/ETL/Row/Schema/Constraint/Any.php b/src/core/etl/src/Flow/ETL/Row/Schema/Constraint/Any.php deleted file mode 100644 index 6e7ec8899..000000000 --- a/src/core/etl/src/Flow/ETL/Row/Schema/Constraint/Any.php +++ /dev/null @@ -1,32 +0,0 @@ - - */ - private readonly array $constraints; - - public function __construct(Constraint ...$constraints) - { - $this->constraints = $constraints; - } - - public function isSatisfiedBy(Entry $entry) : bool - { - foreach ($this->constraints as $constraint) { - if ($constraint->isSatisfiedBy($entry)) { - return true; - } - } - - return false; - } -} diff --git a/src/core/etl/src/Flow/ETL/Row/Schema/Constraint/IsInstanceOf.php b/src/core/etl/src/Flow/ETL/Row/Schema/Constraint/IsInstanceOf.php deleted file mode 100644 index 01aa279bf..000000000 --- a/src/core/etl/src/Flow/ETL/Row/Schema/Constraint/IsInstanceOf.php +++ /dev/null @@ -1,23 +0,0 @@ -value() instanceof $this->class; - } -} diff --git a/src/core/etl/src/Flow/ETL/Row/Schema/Constraint/ListType.php b/src/core/etl/src/Flow/ETL/Row/Schema/Constraint/ListType.php deleted file mode 100644 index 0713140e4..000000000 --- a/src/core/etl/src/Flow/ETL/Row/Schema/Constraint/ListType.php +++ /dev/null @@ -1,27 +0,0 @@ -type() instanceof PHPListType) { - return false; - } - - /** @psalm-suppress UndefinedInterfaceMethod */ - return $entry->type()->element()->isEqual($this->type); - } -} diff --git a/src/core/etl/src/Flow/ETL/Row/Schema/Constraint/NotEmpty.php b/src/core/etl/src/Flow/ETL/Row/Schema/Constraint/NotEmpty.php deleted file mode 100644 index 7aca0ac2b..000000000 --- a/src/core/etl/src/Flow/ETL/Row/Schema/Constraint/NotEmpty.php +++ /dev/null @@ -1,27 +0,0 @@ - 0 !== \count($entry->value()), - Entry\StringEntry::class => $entry->value() !== '', - Entry\JsonEntry::class => !\in_array($entry->value(), ['', '[]', '{}'], true), - default => true, // everything else can't be empty - }; - } -} diff --git a/src/core/etl/src/Flow/ETL/Row/Schema/Constraint/SameAs.php b/src/core/etl/src/Flow/ETL/Row/Schema/Constraint/SameAs.php deleted file mode 100644 index d7eb2ff38..000000000 --- a/src/core/etl/src/Flow/ETL/Row/Schema/Constraint/SameAs.php +++ /dev/null @@ -1,20 +0,0 @@ -value() === $this->value; - } -} diff --git a/src/core/etl/src/Flow/ETL/Row/Schema/Constraint/VoidConstraint.php b/src/core/etl/src/Flow/ETL/Row/Schema/Constraint/VoidConstraint.php deleted file mode 100644 index b8dd2df8d..000000000 --- a/src/core/etl/src/Flow/ETL/Row/Schema/Constraint/VoidConstraint.php +++ /dev/null @@ -1,16 +0,0 @@ -entryClass, Entry::class, true)) { @@ -69,29 +64,28 @@ public function __construct( } $this->metadata = $metadata ?? Metadata::empty(); - $this->constraint = $constraint ?? new VoidConstraint(); $this->ref = EntryReference::init($ref); } - public static function array(string|Reference $entry, bool $empty = false, bool $nullable = false, ?Constraint $constraint = null, ?Metadata $metadata = null) : self + public static function array(string|Reference $entry, bool $empty = false, bool $nullable = false, ?Metadata $metadata = null) : self { - return new self($entry, ArrayEntry::class, type_array($empty, $nullable), $constraint, $metadata); + return new self($entry, ArrayEntry::class, type_array($empty, $nullable), $metadata); } - public static function boolean(string|Reference $entry, bool $nullable = false, ?Constraint $constraint = null, ?Metadata $metadata = null) : self + public static function boolean(string|Reference $entry, bool $nullable = false, ?Metadata $metadata = null) : self { - return new self($entry, BooleanEntry::class, type_boolean($nullable), $constraint, $metadata); + return new self($entry, BooleanEntry::class, type_boolean($nullable), $metadata); } - public static function dateTime(string|Reference $entry, bool $nullable = false, ?Constraint $constraint = null, ?Metadata $metadata = null) : self + public static function dateTime(string|Reference $entry, bool $nullable = false, ?Metadata $metadata = null) : self { - return new self($entry, DateTimeEntry::class, type_datetime($nullable), $constraint, $metadata); + return new self($entry, DateTimeEntry::class, type_datetime($nullable), $metadata); } /** * @param class-string<\UnitEnum> $type */ - public static function enum(string|Reference $entry, string $type, bool $nullable = false, ?Constraint $constraint = null, ?Metadata $metadata = null) : self + public static function enum(string|Reference $entry, string $type, bool $nullable = false, ?Metadata $metadata = null) : self { if (!\enum_exists($type)) { throw new InvalidArgumentException("Enum of type \"{$type}\" not found"); @@ -101,98 +95,88 @@ public static function enum(string|Reference $entry, string $type, bool $nullabl $entry, EnumEntry::class, type_enum($type, $nullable), - $constraint, $metadata ); } - public static function float(string|Reference $entry, bool $nullable = false, ?Constraint $constraint = null, ?Metadata $metadata = null) : self + public static function float(string|Reference $entry, bool $nullable = false, ?Metadata $metadata = null) : self { - return new self($entry, FloatEntry::class, type_float($nullable), $constraint, $metadata); + return new self($entry, FloatEntry::class, type_float($nullable), $metadata); } - public static function integer(string|Reference $entry, bool $nullable = false, ?Constraint $constraint = null, ?Metadata $metadata = null) : self + public static function integer(string|Reference $entry, bool $nullable = false, ?Metadata $metadata = null) : self { - return new self($entry, IntegerEntry::class, type_int($nullable), $constraint, $metadata); + return new self($entry, IntegerEntry::class, type_int($nullable), $metadata); } - public static function json(string|Reference $entry, bool $nullable = false, ?Constraint $constraint = null, ?Metadata $metadata = null) : self + public static function json(string|Reference $entry, bool $nullable = false, ?Metadata $metadata = null) : self { - return new self($entry, JsonEntry::class, type_json($nullable), $constraint, $metadata); + return new self($entry, JsonEntry::class, type_json($nullable), $metadata); } - public static function list(string|Reference $entry, ListType $type, ?Constraint $constraint = null, ?Metadata $metadata = null) : self + public static function list(string|Reference $entry, ListType $type, ?Metadata $metadata = null) : self { return new self( $entry, ListEntry::class, $type, - $constraint, $metadata ); } - public static function map(string|Reference $entry, MapType $type, ?Constraint $constraint = null, ?Metadata $metadata = null) : self + public static function map(string|Reference $entry, MapType $type, ?Metadata $metadata = null) : self { return new self( $entry, MapEntry::class, $type, - $constraint, $metadata ); } public static function null(string|Reference $entry, ?Metadata $metadata = null) : self { - return new self($entry, NullEntry::class, type_null(), null, $metadata); + return new self($entry, NullEntry::class, type_null(), $metadata); } - public static function object(string|Reference $entry, ObjectType $type, ?Constraint $constraint = null, ?Metadata $metadata = null) : self + public static function object(string|Reference $entry, ObjectType $type, ?Metadata $metadata = null) : self { return new self( $entry, ObjectEntry::class, $type, - $constraint, $metadata ); } - public static function string(string|Reference $entry, bool $nullable = false, ?Constraint $constraint = null, ?Metadata $metadata = null) : self + public static function string(string|Reference $entry, bool $nullable = false, ?Metadata $metadata = null) : self { - return new self($entry, StringEntry::class, type_string($nullable), $constraint, $metadata); + return new self($entry, StringEntry::class, type_string($nullable), $metadata); } - public static function structure(string|Reference $entry, StructureType $type, ?Constraint $constraint = null, ?Metadata $metadata = null) : self + public static function structure(string|Reference $entry, StructureType $type, ?Metadata $metadata = null) : self { return new self( $entry, StructureEntry::class, $type, - $constraint, $metadata ); } - public static function uuid(string|Reference $entry, bool $nullable = false, ?Constraint $constraint = null, ?Metadata $metadata = null) : self - { - return new self($entry, UuidEntry::class, type_uuid($nullable), $constraint, $metadata); - } - - public static function xml(string|Reference $entry, bool $nullable = false, ?Constraint $constraint = null, ?Metadata $metadata = null) : self + public static function uuid(string|Reference $entry, bool $nullable = false, ?Metadata $metadata = null) : self { - return new self($entry, XMLEntry::class, type_xml($nullable), $constraint, $metadata); + return new self($entry, UuidEntry::class, type_uuid($nullable), $metadata); } - public static function xml_node(string|Reference $entry, bool $nullable = false, ?Constraint $constraint = null, ?Metadata $metadata = null) : self + public static function xml(string|Reference $entry, bool $nullable = false, ?Metadata $metadata = null) : self { - return new self($entry, XMLNodeEntry::class, type_xml_node($nullable), $constraint, $metadata); + return new self($entry, XMLEntry::class, type_xml($nullable), $metadata); } - public function constraint() : Constraint + public static function xml_node(string|Reference $entry, bool $nullable = false, ?Metadata $metadata = null) : self { - return $this->constraint; + return new self($entry, XMLNodeEntry::class, type_xml_node($nullable), $metadata); } public function entry() : Reference @@ -210,10 +194,6 @@ public function isEqual(self $definition) : bool return false; } - if ($this->constraint != $definition->constraint) { - return false; - } - return $this->metadata->isEqual($definition->metadata); } @@ -232,11 +212,7 @@ public function matches(Entry $entry) : bool return false; } - if ($entry::class !== $this->entryClass) { - return false; - } - - return $this->constraint->isSatisfiedBy($entry); + return $entry::class === $this->entryClass; } public function merge(self $definition) : self @@ -245,16 +221,6 @@ public function merge(self $definition) : self throw new RuntimeException(\sprintf('Cannot merge different definitions, %s and %s', $this->ref->name(), $definition->ref->name())); } - $constraint = new Any($this->constraint, $definition->constraint); - - if ($this->constraint instanceof VoidConstraint) { - $constraint = $definition->constraint; - } - - if ($definition->constraint instanceof VoidConstraint) { - $constraint = $this->constraint; - } - if ($this->type instanceof ListType && $definition->type instanceof ListType && !$this->type->isEqual($definition->type)) { $thisTypeString = $this->type->element()->toString(); $definitionTypeString = $definition->type->element()->toString(); @@ -264,7 +230,6 @@ public function merge(self $definition) : self $this->ref, $this->entryClass, type_list(type_float($this->type->element()->type()->nullable() || $definition->type->element()->type()->nullable())), - $constraint, $this->metadata->merge($definition->metadata) ); } @@ -276,7 +241,6 @@ public function merge(self $definition) : self $this->ref, ArrayEntry::class, type_array(false, $this->isNullable() || $definition->isNullable()), - $constraint, $this->metadata->merge($definition->metadata) ); } @@ -287,7 +251,6 @@ public function merge(self $definition) : self $this->ref, $this->entryClass, $this->type()->merge($definition->type()), - $constraint, $this->metadata->merge($definition->metadata) ); } @@ -303,7 +266,6 @@ public function merge(self $definition) : self $this->ref, $entryClasses[0], $type->makeNullable(true), - $constraint, $this->metadata->merge($definition->metadata) ); } @@ -313,7 +275,6 @@ public function merge(self $definition) : self $this->ref, StringEntry::class, type_string($this->isNullable() || $definition->isNullable()), - $constraint, $this->metadata->merge($definition->metadata) ); } @@ -323,7 +284,6 @@ public function merge(self $definition) : self $this->ref, FloatEntry::class, type_float($this->isNullable() || $definition->isNullable()), - $constraint, $this->metadata->merge($definition->metadata) ); } @@ -333,7 +293,6 @@ public function merge(self $definition) : self $this->ref, ArrayEntry::class, type_array(false, $this->isNullable() || $definition->isNullable()), - $constraint, $this->metadata->merge($definition->metadata) ); } @@ -348,7 +307,7 @@ public function metadata() : Metadata public function nullable() : self { - return new self($this->ref, $this->entryClass, $this->type->makeNullable(true), $this->constraint, $this->metadata); + return new self($this->ref, $this->entryClass, $this->type->makeNullable(true), $this->metadata); } public function type() : Type diff --git a/src/core/etl/src/Flow/ETL/Row/Schema/Metadata.php b/src/core/etl/src/Flow/ETL/Row/Schema/Metadata.php index 7d1f02ae1..b67f3dda9 100644 --- a/src/core/etl/src/Flow/ETL/Row/Schema/Metadata.php +++ b/src/core/etl/src/Flow/ETL/Row/Schema/Metadata.php @@ -13,12 +13,12 @@ final class Metadata { /** - * @var array|bool|float|int|object|string> + * @var array|bool|float|int|string> */ private array $map; /** - * @param array|bool|float|int|object|string> $map + * @param array|bool|float|int|string> $map */ private function __construct(array $map) { @@ -32,22 +32,22 @@ public static function empty() : self /** * @param string $key - * @param array|bool|float|int|object|string $value + * @param array|bool|float|int|object|string $value * * @return $this */ - public static function with(string $key, int|string|bool|float|object|array $value) : self + public static function with(string $key, int|string|bool|float|array $value) : self { return new self([$key => $value]); } /** * @param string $key - * @param array|bool|float|int|object|string $value + * @param array|bool|float|int|object|string $value * * @return $this */ - public function add(string $key, int|string|bool|float|object|array $value) : self + public function add(string $key, int|string|bool|float|array $value) : self { return new self(\array_merge($this->map, [$key => $value])); } @@ -57,9 +57,9 @@ public function add(string $key, int|string|bool|float|object|array $value) : se * * @throws InvalidArgumentException * - * @return array|bool|float|int|object|string + * @return array|bool|float|int|string */ - public function get(string $key) : int|string|bool|float|object|array + public function get(string $key) : int|string|bool|float|array { if (!\array_key_exists($key, $this->map)) { throw new InvalidArgumentException("There no is key: {$key}"); diff --git a/src/core/etl/tests/Flow/ETL/Tests/Unit/Row/Schema/Constraint/AnyTest.php b/src/core/etl/tests/Flow/ETL/Tests/Unit/Row/Schema/Constraint/AnyTest.php deleted file mode 100644 index 0baa0ae3c..000000000 --- a/src/core/etl/tests/Flow/ETL/Tests/Unit/Row/Schema/Constraint/AnyTest.php +++ /dev/null @@ -1,34 +0,0 @@ -assertTrue( - (new Any( - new SameAs(10), - new SameAs('test'), - new SameAs(false), - )) - ->isSatisfiedBy(new StringEntry('type', 'test')) - ); - - $this->assertFalse( - (new Any( - new SameAs(10), - new SameAs('test'), - new SameAs(false), - )) - ->isSatisfiedBy(new StringEntry('type', 'not-value')) - ); - } -} diff --git a/src/core/etl/tests/Flow/ETL/Tests/Unit/Row/Schema/Constraint/IsInstanceOfTest.php b/src/core/etl/tests/Flow/ETL/Tests/Unit/Row/Schema/Constraint/IsInstanceOfTest.php deleted file mode 100644 index fda54175b..000000000 --- a/src/core/etl/tests/Flow/ETL/Tests/Unit/Row/Schema/Constraint/IsInstanceOfTest.php +++ /dev/null @@ -1,18 +0,0 @@ -assertTrue((new IsInstanceOf(\ArrayIterator::class))->isSatisfiedBy(new ObjectEntry('array', new \ArrayIterator()))); - $this->assertFalse((new IsInstanceOf(\DateTimeImmutable::class))->isSatisfiedBy(new ObjectEntry('array', new \ArrayIterator()))); - } -} diff --git a/src/core/etl/tests/Flow/ETL/Tests/Unit/Row/Schema/Constraint/NotEmptyTest.php b/src/core/etl/tests/Flow/ETL/Tests/Unit/Row/Schema/Constraint/NotEmptyTest.php deleted file mode 100644 index c3a364f23..000000000 --- a/src/core/etl/tests/Flow/ETL/Tests/Unit/Row/Schema/Constraint/NotEmptyTest.php +++ /dev/null @@ -1,60 +0,0 @@ -assertFalse($constraint->isSatisfiedBy(array_entry('e', []))); - $this->assertFalse($constraint->isSatisfiedBy(json_entry('e', []))); - $this->assertFalse($constraint->isSatisfiedBy(json_object_entry('e', []))); - $this->assertFalse($constraint->isSatisfiedBy(list_entry('e', [], type_list(type_int())))); - } - - public function test_not_empty_is_satisfied() : void - { - $constraint = new NotEmpty(); - - $this->assertTrue($constraint->isSatisfiedBy(array_entry('e', [1]))); - $this->assertTrue($constraint->isSatisfiedBy(bool_entry('e', false))); - $this->assertTrue($constraint->isSatisfiedBy(datetime_entry('e', new \DateTimeImmutable()))); - $this->assertTrue($constraint->isSatisfiedBy(object_entry('e', type_int()))); - $this->assertTrue($constraint->isSatisfiedBy(float_entry('e', 1.1))); - $this->assertTrue($constraint->isSatisfiedBy(int_entry('e', 1))); - $this->assertTrue($constraint->isSatisfiedBy(json_entry('e', [1, 2]))); - $this->assertTrue($constraint->isSatisfiedBy(list_entry('e', [1, 2], type_list(type_int())))); - $this->assertTrue($constraint->isSatisfiedBy(null_entry('e'))); - $this->assertTrue($constraint->isSatisfiedBy(object_entry('e', new \SplFixedArray(2)))); - $this->assertTrue($constraint->isSatisfiedBy(str_entry('e', 'e'))); - $this->assertTrue($constraint->isSatisfiedBy(list_entry('list', [1, 2, 3], type_list(type_int())))); - $this->assertTrue($constraint->isSatisfiedBy(map_entry('map', ['NEW', 'PENDING'], type_map(type_int(), type_string())))); - $this->assertTrue($constraint->isSatisfiedBy(struct_entry('e', ['id' => 1], struct_type([struct_element('id', type_int())])))); - } -} diff --git a/src/core/etl/tests/Flow/ETL/Tests/Unit/Row/Schema/Constraint/SameAsTest.php b/src/core/etl/tests/Flow/ETL/Tests/Unit/Row/Schema/Constraint/SameAsTest.php deleted file mode 100644 index a2b28a0a8..000000000 --- a/src/core/etl/tests/Flow/ETL/Tests/Unit/Row/Schema/Constraint/SameAsTest.php +++ /dev/null @@ -1,18 +0,0 @@ -assertTrue((new SameAs(10))->isSatisfiedBy(new IntegerEntry('integer', 10))); - $this->assertFalse((new SameAs(20))->isSatisfiedBy(new IntegerEntry('integer', 10))); - } -} diff --git a/src/core/etl/tests/Flow/ETL/Tests/Unit/Row/Schema/DefinitionTest.php b/src/core/etl/tests/Flow/ETL/Tests/Unit/Row/Schema/DefinitionTest.php index 43ba6c415..c6dbe6f6b 100644 --- a/src/core/etl/tests/Flow/ETL/Tests/Unit/Row/Schema/DefinitionTest.php +++ b/src/core/etl/tests/Flow/ETL/Tests/Unit/Row/Schema/DefinitionTest.php @@ -21,7 +21,6 @@ use Flow\ETL\PHP\Type\Logical\List\ListElement; use Flow\ETL\PHP\Type\Logical\ListType; use Flow\ETL\PHP\Type\Logical\StructureType; -use Flow\ETL\Row\Schema\Constraint; use Flow\ETL\Row\Schema\Definition; use PHPUnit\Framework\TestCase; @@ -35,18 +34,7 @@ public function test_creating_definition_without_class() : void new Definition('name', \DateTimeInterface::class, type_datetime()); } - public function test_equals_but_different_constraints() : void - { - $def = Definition::list('list', new ListType(ListElement::integer())); - - $this->assertFalse( - $def->isEqual( - Definition::list('list', new ListType(ListElement::string())) - ) - ); - } - - public function test_equals_types_and_constraints() : void + public function test_equals_types() : void { $def = Definition::list('list', new ListType(ListElement::integer())); @@ -57,18 +45,6 @@ public function test_equals_types_and_constraints() : void ); } - public function test_matches_when_constraint_satisfied_and_everything_else_matches() : void - { - $constraint = $this->createMock(Constraint::class); - $constraint->expects($this->any()) - ->method('isSatisfiedBy') - ->willReturn(true); - - $def = Definition::integer('test', false, $constraint); - - $this->assertTrue($def->matches(int_entry('test', 1))); - } - public function test_matches_when_nullable_and_name_matches() : void { $def = Definition::integer('test', $nullable = true); @@ -83,50 +59,10 @@ public function test_matches_when_type_and_name_match() : void $this->assertTrue($def->matches(int_entry('test', 1))); } - public function test_merge_definitions_with_both_side_constraints() : void - { - $this->assertEquals( - Definition::integer( - 'id', - true, - new Constraint\Any( - new Constraint\SameAs(1), - new Constraint\SameAs('one') - ) - ), - Definition::integer('id', false, new Constraint\SameAs(1)) - ->merge(Definition::integer('id', true, new Constraint\SameAs('one'))) - ); - } - - public function test_merge_definitions_with_left_side_constraints() : void - { - $this->assertEquals( - Definition::integer( - 'id', - true, - new Constraint\SameAs(1) - ), - Definition::integer('id', false, new Constraint\SameAs(1))->merge(Definition::integer('id', true)) - ); - } - - public function test_merge_definitions_with_right_side_constraints() : void - { - $this->assertEquals( - Definition::integer( - 'id', - true, - new Constraint\SameAs(2) - )->nullable(), - Definition::integer('id')->merge(Definition::integer('id', true, new Constraint\SameAs(2))) - ); - } - - public function test_merge_definitions_without_constraints() : void + public function test_merge_definitions() : void { $this->assertEquals( - Definition::integer('id', true)->nullable(), + Definition::integer('id', true), Definition::integer('id')->merge(Definition::integer('id', true)) ); } @@ -253,18 +189,6 @@ public function test_merging_two_same_maps() : void ); } - public function test_not_matches_when_constraint_not_satisfied() : void - { - $constraint = $this->createMock(Constraint::class); - $constraint->expects($this->any()) - ->method('isSatisfiedBy') - ->willReturn(false); - - $def = Definition::integer('test', false, $constraint); - - $this->assertFalse($def->matches(int_entry('test', 1))); - } - public function test_not_matches_when_not_nullable_name_matches_but_null_given() : void { $def = Definition::integer('test', $nullable = false); diff --git a/src/core/etl/tests/Flow/ETL/Tests/Unit/Row/Schema/MetadataTest.php b/src/core/etl/tests/Flow/ETL/Tests/Unit/Row/Schema/MetadataTest.php index 4624ad005..73773d1f1 100644 --- a/src/core/etl/tests/Flow/ETL/Tests/Unit/Row/Schema/MetadataTest.php +++ b/src/core/etl/tests/Flow/ETL/Tests/Unit/Row/Schema/MetadataTest.php @@ -4,8 +4,6 @@ namespace Flow\ETL\Tests\Unit\Row\Schema; -use function Flow\ETL\DSL\type_int; -use function Flow\ETL\DSL\type_string; use Flow\ETL\Exception\InvalidArgumentException; use Flow\ETL\Row\Schema\Metadata; use PHPUnit\Framework\TestCase; @@ -42,14 +40,6 @@ public function test_merge_metadata_with_the_same_keys() : void ); } - public function test_merge_object_metadata() : void - { - $this->assertEquals( - Metadata::empty()->add('type', type_int()), - Metadata::empty()->add('type', type_string())->merge(Metadata::empty()->add('type', type_int())) - ); - } - public function test_remove_metadata_with_the_same_keys() : void { $this->assertEquals(