renommer Value en Wrapper

This commit is contained in:
Jephté Clain 2025-03-06 09:05:10 +04:00
parent 74487a0ab9
commit f8eec57055
21 changed files with 275 additions and 341 deletions

View File

@ -5,24 +5,26 @@ use nur\sery\wip\schema\input\Input;
use nur\sery\wip\schema\types\IType; use nur\sery\wip\schema\types\IType;
class AnalyzerContext { class AnalyzerContext {
function __construct(Schema $schema, Input $input, $destKey, Result $result) { function __construct(Schema $schema, Wrapper $wrapper, Input $input, $destKey, Result $result) {
$this->schema = $schema; $this->schema = $schema;
$this->wrapper = $wrapper;
$this->input = $input; $this->input = $input;
$this->destKey = $destKey;
$this->result = $result; $this->result = $result;
$this->type = null; $this->type = null;
$this->orig = null; $this->orig = null;
$this->value = null; $this->dest = null;
$this->destKey = $destKey;
} }
public Schema $schema; public Schema $schema;
public Wrapper $wrapper;
public Input $input; public Input $input;
/** @var int|string|null */
public $destKey;
public Result $result; public Result $result;
public ?IType $type; public ?IType $type;
/** @var mixed */ /** @var mixed */
public $orig; public $orig;
/** @var mixed */ /** @var mixed */
public $value; public $dest;
/** @var int|string|null */
public $destKey;
} }

View File

@ -38,17 +38,17 @@ abstract class Schema implements ArrayAccess {
} }
/** /**
* Créer une nouvelle instance de {@link Value} qui référence la * Créer une nouvelle instance de {@link Wrapper} qui référence la
* variable $dest (si $destKey===null) ou $dest[$destKey] si $destKey n'est * variable $dest (si $destKey===null) ou $dest[$destKey] si $destKey n'est
* pas null * pas null
*/ */
static function nv(?Value &$destv=null, &$dest=null, $destKey=null, &$schema=null, $definition=null): Value { static function nw(&$dest=null, $destKey=null, &$schema=null, $definition=null, ?Wrapper &$destw=null): Wrapper {
if ($definition === null) { if ($definition === null) {
# bien que techniquement, $definition peut être null (il s'agit alors du # bien que techniquement, $definition peut être null (il s'agit alors du
# schéma d'un scalaire quelconque), on ne l'autorise pas ici # schéma d'un scalaire quelconque), on ne l'autorise pas ici
throw SchemaException::invalid_schema("definition is required"); throw SchemaException::invalid_schema("definition is required");
} }
return self::ns($schema, $definition)->newValue($destv, $dest, $destKey); return self::ns($schema, $definition)->newWrapper($dest, $destKey, $destw);
} }
/** /**
@ -70,7 +70,7 @@ abstract class Schema implements ArrayAccess {
/** retourner true si le schéma est de nature scalaire */ /** retourner true si le schéma est de nature scalaire */
function isScalar(?ScalarSchema &$scalar=null): bool { return false; } function isScalar(?ScalarSchema &$scalar=null): bool { return false; }
abstract function newValue(?Value &$destv=null, &$dest=null, $destKey=null): Value; abstract function newWrapper(&$dest=null, $destKey=null, ?Wrapper &$destw=null): Wrapper;
############################################################################# #############################################################################
# key & properties # key & properties

View File

@ -1,7 +1,5 @@
# nulib\schema # nulib\schema
* implémenter support `analyzer_func`, `extractor_func`, `parser_func`,
`normalizer_func`, `formatter_func`
* dans AssocSchema, support `[key_prefix]` qui permet de spécifier un préfixe * dans AssocSchema, support `[key_prefix]` qui permet de spécifier un préfixe
commun aux champs dans le tableau destination, e.g commun aux champs dans le tableau destination, e.g
~~~php ~~~php

View File

@ -3,15 +3,15 @@ namespace nur\sery\wip\schema;
use ArrayAccess; use ArrayAccess;
use IteratorAggregate; use IteratorAggregate;
use nur\sery\wip\schema\_assoc\AssocValue; use nur\sery\wip\schema\_assoc\AssocWrapper;
use nur\sery\wip\schema\_list\ListValue; use nur\sery\wip\schema\_list\ListWrapper;
use nur\sery\wip\schema\_scalar\ScalarValue; use nur\sery\wip\schema\_scalar\ScalarWrapper;
use nur\sery\wip\schema\types\IType; use nur\sery\wip\schema\types\IType;
abstract class Value implements ArrayAccess, IteratorAggregate { abstract class Wrapper implements ArrayAccess, IteratorAggregate {
function isAssoc(?AssocValue &$assoc=null): bool { return false; } function isAssoc(?AssocWrapper &$assoc=null): bool { return false; }
function isList(?ListValue &$list=null): bool { return false; } function isList(?ListWrapper &$list=null): bool { return false; }
function isScalar(?ScalarValue &$scalar=null): bool { return false; } function isScalar(?ScalarWrapper &$scalar=null): bool { return false; }
/** spécifier la valeur destination gérée par cet objet */ /** spécifier la valeur destination gérée par cet objet */
abstract function reset(&$dest, $destKey=null, ?bool $verifix=null): self; abstract function reset(&$dest, $destKey=null, ?bool $verifix=null): self;
@ -23,11 +23,11 @@ abstract class Value implements ArrayAccess, IteratorAggregate {
abstract function getKeys(): array; abstract function getKeys(): array;
/** obtenir un objet pour gérer la valeur spécifiée */ /** obtenir un objet pour gérer la valeur spécifiée */
abstract function getValue($key=null): Value; abstract function getWrapper($key=null): Wrapper;
function getIterator() { function getIterator() {
foreach ($this->getKeys() as $key) { foreach ($this->getKeys() as $key) {
yield $key => $this->getValue($key); yield $key => $this->getWrapper($key);
} }
} }
@ -72,14 +72,14 @@ abstract class Value implements ArrayAccess, IteratorAggregate {
} }
function offsetGet($offset) { function offsetGet($offset) {
return $this->getValue($offset); return $this->getWrapper($offset);
} }
function offsetSet($offset, $value): void { function offsetSet($offset, $value): void {
$this->getValue($offset)->set($value); $this->getWrapper($offset)->set($value);
} }
function offsetUnset($offset): void { function offsetUnset($offset): void {
$this->getValue($offset)->unset(); $this->getWrapper($offset)->unset();
} }
} }

View File

@ -4,7 +4,7 @@ namespace nur\sery\wip\schema\_assoc;
use nulib\cl; use nulib\cl;
use nulib\ref\schema\ref_schema; use nulib\ref\schema\ref_schema;
use nur\sery\wip\schema\Schema; use nur\sery\wip\schema\Schema;
use nur\sery\wip\schema\Value; use nur\sery\wip\schema\Wrapper;
/** /**
* Class AssocSchema * Class AssocSchema
@ -48,8 +48,8 @@ class AssocSchema extends Schema {
return true; return true;
} }
function newValue(?Value &$destv=null, &$dest=null, $destKey=null): AssocValue { function newWrapper(&$dest=null, $destKey=null, ?Wrapper &$destw=null): AssocWrapper {
if ($destv instanceof AssocValue) return $destv->reset($dest, $destKey); if ($destw instanceof AssocWrapper) return $destw->reset($dest, $destKey);
else return ($destv = new AssocValue($this, $dest, $destKey)); else return ($destw = new AssocWrapper($this, $dest, $destKey));
} }
} }

View File

@ -2,10 +2,10 @@
namespace nur\sery\wip\schema\_assoc; namespace nur\sery\wip\schema\_assoc;
use nur\sery\wip\schema\Result; use nur\sery\wip\schema\Result;
use nur\sery\wip\schema\Value; use nur\sery\wip\schema\Wrapper;
abstract/*XXX*/ class AssocValue extends Value { abstract/*XXX*/ class AssocWrapper extends Wrapper {
function isAssoc(?AssocValue &$assoc=null): bool { $assoc = $this; return true; } function isAssoc(?AssocWrapper &$assoc=null): bool { $assoc = $this; return true; }
function ensureKeys(): bool { function ensureKeys(): bool {
} }

View File

@ -3,7 +3,7 @@ namespace nur\sery\wip\schema\_list;
use nulib\ref\schema\ref_schema; use nulib\ref\schema\ref_schema;
use nur\sery\wip\schema\Schema; use nur\sery\wip\schema\Schema;
use nur\sery\wip\schema\Value; use nur\sery\wip\schema\Wrapper;
class ListSchema extends Schema { class ListSchema extends Schema {
/** @var array meta-schema d'un schéma de nature liste */ /** @var array meta-schema d'un schéma de nature liste */
@ -46,8 +46,8 @@ class ListSchema extends Schema {
return true; return true;
} }
function newValue(?Value &$destv=null, &$dest=null, $destKey=null): ListValue { function newWrapper(&$dest=null, $destKey=null, ?Wrapper &$destw=null): ListWrapper {
if ($destv instanceof ListValue) return $destv->reset($dest, $destKey); if ($destw instanceof ListWrapper) return $destw->reset($dest, $destKey);
else return ($destv = new ListValue($this, $dest, $destKey)); else return ($destw = new ListWrapper($this, $dest, $destKey));
} }
} }

View File

@ -2,10 +2,10 @@
namespace nur\sery\wip\schema\_list; namespace nur\sery\wip\schema\_list;
use nur\sery\wip\schema\Result; use nur\sery\wip\schema\Result;
use nur\sery\wip\schema\Value; use nur\sery\wip\schema\Wrapper;
abstract/*XXX*/ class ListValue extends Value { abstract/*XXX*/ class ListWrapper extends Wrapper {
function isList(?ListValue &$list=null): bool { $list = $this; return true; } function isList(?ListWrapper &$list=null): bool { $list = $this; return true; }
function ensureKeys(): bool { function ensureKeys(): bool {
} }

View File

@ -12,7 +12,7 @@ use nur\sery\wip\schema\types\tcallable;
use nur\sery\wip\schema\types\tcontent; use nur\sery\wip\schema\types\tcontent;
use nur\sery\wip\schema\types\tpkey; use nur\sery\wip\schema\types\tpkey;
use nur\sery\wip\schema\types\trawstring; use nur\sery\wip\schema\types\trawstring;
use nur\sery\wip\schema\Value; use nur\sery\wip\schema\Wrapper;
/** /**
* Class ScalarSchema * Class ScalarSchema
@ -178,9 +178,9 @@ class ScalarSchema extends Schema {
return true; return true;
} }
function newValue(?Value &$destv=null, &$dest=null, $destKey=null): ScalarValue { function newWrapper(&$dest=null, $destKey=null, ?Wrapper &$destw=null): ScalarWrapper {
if ($destv instanceof ScalarValue) return $destv->reset($dest, $destKey); if ($destw instanceof ScalarWrapper) return $destw->reset($dest, $destKey);
else return ($destv = new ScalarValue($this, $dest, $destKey)); else return ($destw = new ScalarWrapper($this, $dest, $destKey));
} }
############################################################################# #############################################################################

View File

@ -8,54 +8,54 @@ use nur\sery\wip\schema\AnalyzerContext;
use nur\sery\wip\schema\input\Input; use nur\sery\wip\schema\input\Input;
use nur\sery\wip\schema\types; use nur\sery\wip\schema\types;
use nur\sery\wip\schema\types\IType; use nur\sery\wip\schema\types\IType;
use nur\sery\wip\schema\Value; use nur\sery\wip\schema\Wrapper;
class ScalarValue extends Value { class ScalarWrapper extends Wrapper {
function __construct(ScalarSchema $schema, &$dest=null, $destKey=null, bool $defaultVerifix=true, ?bool $defaultThrow=null) { function __construct(ScalarSchema $schema, &$dest=null, $destKey=null, ?array $params=null) {
$defaultVerifix = $params["verifix"] ?? true;
$defaultThrow = $params["throw"] ?? null;
if ($dest !== null && $defaultThrow === null) { if ($dest !== null && $defaultThrow === null) {
# Si $dest est null, ne pas lancer d'exception, parce qu'on considère que # Si $dest est null, ne pas lancer d'exception, parce qu'on considère que
# c'est une initialisation sans conséquences # c'est une initialisation sans conséquences
$defaultThrow = true; $defaultThrow = true;
} }
$this->schema = $schema; $this->schema = $schema;
$this->defaultVerifix = $defaultVerifix; $this->verifix = $defaultVerifix;
$this->defaultThrow = $defaultThrow ?? false; $this->throw = $defaultThrow ?? false;
$this->result = new ScalarResult(); $this->result = new ScalarResult();
$this->reset($dest, $destKey); $this->reset($dest, $destKey);
$this->defaultThrow = $defaultThrow ?? true; $this->throw = $defaultThrow ?? true;
} }
function isScalar(?ScalarValue &$scalar=null): bool { $scalar = $this; return true; } function isScalar(?ScalarWrapper &$scalar=null): bool { $scalar = $this; return true; }
/** @var ScalarSchema schéma de cette valeur */ /** schéma de cette valeur */
protected $schema; protected ScalarSchema $schema;
/** @var Input source et destination de la valeur */ /** source et destination de la valeur */
protected $input; protected Input $input;
/** @var string|int|null clé de la valeur dans le tableau destination */ /** @var string|int|null clé de la valeur dans le tableau destination */
protected $destKey; protected $destKey;
/** @var bool */ protected bool $verifix;
protected $defaultVerifix;
/** @var bool */ protected bool $throw;
protected $defaultThrow;
/** @var IType type de la valeur après analyse */ /** type de la valeur après analyse */
protected $type; protected ?IType $type;
/** @var ?ScalarResult résultat de l'analyse de la valeur */ /** résultat de l'analyse de la valeur */
protected $result; protected ScalarResult $result;
function reset(&$dest, $destKey=null, ?bool $verifix=null): Value { function reset(&$dest, $destKey=null, ?bool $verifix=null): Wrapper {
if ($dest instanceof Input) $input = $dest; if ($dest instanceof Input) $input = $dest;
else $input = new Input($dest); else $input = new Input($dest);
$this->input = $input; $this->input = $input;
$this->destKey = $destKey; $this->destKey = $destKey;
$this->type = null; $this->type = null;
$this->analyzeExtractParse(); $this->analyzeExtractParse();
if ($verifix ?? $this->defaultVerifix) $this->verifix(); if ($verifix ?? $this->verifix) $this->verifix();
return $this; return $this;
} }
@ -63,7 +63,7 @@ class ScalarValue extends Value {
return [null]; return [null];
} }
function getValue($key=null): ScalarValue { function getWrapper($key=null): ScalarWrapper {
if ($key === null) return $this; if ($key === null) return $this;
throw ValueException::invalid_key($key); throw ValueException::invalid_key($key);
} }
@ -124,7 +124,7 @@ class ScalarValue extends Value {
if (!$type->isAvailable($input, $destKey)) return $result->setUnavailable($schema); if (!$type->isAvailable($input, $destKey)) return $result->setUnavailable($schema);
$value = $input->get($destKey); $value = $input->get($destKey);
$context->orig = $context->value = $value; $context->orig = $context->dest = $value;
if ($type->isNull($value)) { if ($type->isNull($value)) {
return $result->setNull($schema); return $result->setNull($schema);
} elseif (is_string($value)) { } elseif (is_string($value)) {
@ -138,12 +138,12 @@ class ScalarValue extends Value {
} }
function _extract(AnalyzerContext $context): bool { function _extract(AnalyzerContext $context): bool {
return $context->type->extract($context->value); return $context->type->extract($context->dest);
} }
function _parse(AnalyzerContext $context): bool { function _parse(AnalyzerContext $context): bool {
try { try {
$context->value = $context->type->parse($context->value); $context->dest = $context->type->parse($context->dest);
return true; return true;
} catch (ValueException $e) { } catch (ValueException $e) {
return false; return false;
@ -156,7 +156,7 @@ class ScalarValue extends Value {
$destKey = $this->destKey; $destKey = $this->destKey;
$result = $this->result; $result = $this->result;
$result->reset(); $result->reset();
$context = new AnalyzerContext($schema, $input, $destKey, $result); $context = new AnalyzerContext($schema, $this, $input, $destKey, $result);
/** @var func $analyzerFunc */ /** @var func $analyzerFunc */
$analyzerFunc = $schema->analyzerFunc; $analyzerFunc = $schema->analyzerFunc;
@ -169,17 +169,17 @@ class ScalarValue extends Value {
if ($extractorFunc !== null) $valid = $extractorFunc->invoke([$context]); if ($extractorFunc !== null) $valid = $extractorFunc->invoke([$context]);
else $valid = $this->_extract($context); else $valid = $this->_extract($context);
if (!$valid) return $result->setInvalid($context->orig, $schema); if (!$valid) return $result->setInvalid($context->orig, $schema);
if ($context->type->isNull($context->value)) return $result->setNull($schema); if ($context->type->isNull($context->dest)) return $result->setNull($schema);
$extracted = $context->value; $extracted = $context->dest;
/** @var func $parserFunc */ /** @var func $parserFunc */
$parserFunc = $schema->parserFunc; $parserFunc = $schema->parserFunc;
if ($parserFunc !== null) $valid = $parserFunc->invoke([$context]); if ($parserFunc !== null) $valid = $parserFunc->invoke([$context]);
else $valid = $this->_parse($context); else $valid = $this->_parse($context);
if ($valid) { if ($valid) {
$normalized = $context->value === $context->orig; $normalized = $context->dest === $context->orig;
if ($normalized) { if ($normalized) {
$input->set($context->value, $destKey); $input->set($context->dest, $destKey);
return $result->setNormalized(); return $result->setNormalized();
} else { } else {
$input->set($extracted, $destKey); $input->set($extracted, $destKey);
@ -190,10 +190,17 @@ class ScalarValue extends Value {
} }
function verifix(?bool $throw=null): bool { function verifix(?bool $throw=null): bool {
if ($throw === null) $throw = $this->defaultThrow; $schema = $this->schema;
$input = $this->input;
$destKey = $this->destKey; $destKey = $this->destKey;
$result = $this->result;
$context = new AnalyzerContext($schema, $this, $input, $destKey, $result);
/** @var func $normalizerFunc */
$normalizerFunc = $schema->normalizerFunc;
if ($normalizerFunc !== null) return $normalizerFunc->invoke([$context]);
if ($throw === null) $throw = $this->throw;
$verifix = false; $verifix = false;
$result =& $this->result;
$modified = false; $modified = false;
if ($result->resultAvailable) { if ($result->resultAvailable) {
if ($result->null) { if ($result->null) {
@ -245,19 +252,17 @@ class ScalarValue extends Value {
else return $default; else return $default;
} }
function set($value, ?bool $verifix=null): ScalarValue { function set($value, ?bool $verifix=null): ScalarWrapper {
$this->input->set($value, $this->destKey); $this->input->set($value, $this->destKey);
$this->analyzeExtractParse(); $this->analyzeExtractParse();
if ($verifix === null) $verifix = $this->defaultVerifix; if ($verifix ?? $this->verifix) $this->verifix();
if ($verifix) $this->verifix();
return $this; return $this;
} }
function unset(?bool $verifix=null): ScalarValue { function unset(?bool $verifix=null): ScalarWrapper {
$this->input->unset($this->destKey); $this->input->unset($this->destKey);
$this->analyzeExtractParse(); $this->analyzeExtractParse();
if ($verifix === null) $verifix = $this->defaultVerifix; if ($verifix ?? $this->verifix) $this->verifix();
if ($verifix) $this->verifix();
return $this; return $this;
} }

View File

@ -2,6 +2,7 @@
namespace nur\sery\wip\schema\types; namespace nur\sery\wip\schema\types;
use nulib\cl; use nulib\cl;
use nulib\ValueException;
use nur\sery\wip\schema\_scalar\ScalarResult; use nur\sery\wip\schema\_scalar\ScalarResult;
use nur\sery\wip\schema\_scalar\ScalarSchema; use nur\sery\wip\schema\_scalar\ScalarSchema;
use nur\sery\wip\schema\Result; use nur\sery\wip\schema\Result;
@ -46,14 +47,20 @@ class tarray extends _tstring {
if (is_array($value)) { if (is_array($value)) {
$result->setNormalized(); $result->setNormalized();
return false; return false;
} elseif (is_string($value)) {
try {
$value = $this->parse($value);
$result->setValid();
return true;
} catch (ValueException $e) {
}
} elseif (is_scalar($value)) { } elseif (is_scalar($value)) {
$value = cl::with($value); $value = cl::with($value);
$result->setValid(); $result->setValid();
return true; return true;
} else {
$result->setInvalid($value, $schema);
return false;
} }
$result->setInvalid($value, $schema);
return false;
} }
function format($value, $format=null): string { function format($value, $format=null): string {

View File

@ -79,14 +79,20 @@ class tbool extends _tformatable {
if (is_bool($value)) { if (is_bool($value)) {
$result->setNormalized(); $result->setNormalized();
return false; return false;
} elseif (is_string($value)) {
try {
$value = $this->parse($value);
$result->setValid();
return true;
} catch (ValueException $e) {
}
} elseif (is_scalar($value)) { } elseif (is_scalar($value)) {
$value = boolval($value); $value = boolval($value);
$result->setValid(); $result->setValid();
return true; return true;
} else {
$result->setInvalid($value, $schema);
return false;
} }
$result->setInvalid($value, $schema);
return false;
} }
const OUINON_FORMAT = ["Oui", "Non", false]; const OUINON_FORMAT = ["Oui", "Non", false];

View File

@ -43,10 +43,16 @@ class tcallable extends _tsimple {
$value = func::with($value); $value = func::with($value);
$result->setNormalized(); $result->setNormalized();
return true; return true;
} else { } elseif (is_string($value)) {
$result->setInvalid($value, $schema); try {
return false; $value = $this->parse($value);
$result->setValid();
return true;
} catch (ValueException $e) {
}
} }
$result->setInvalid($value, $schema);
return false;
} }
function format($value, $format=null): string { function format($value, $format=null): string {

View File

@ -40,13 +40,19 @@ class tfloat extends _tformatable {
if (is_float($value)) { if (is_float($value)) {
$result->setNormalized(); $result->setNormalized();
return false; return false;
} elseif (is_string($value)) {
try {
$value = $this->parse($value);
$result->setValid();
return true;
} catch (ValueException $e) {
}
} elseif (is_scalar($value)) { } elseif (is_scalar($value)) {
$value = floatval($value); $value = floatval($value);
$result->setValid(); $result->setValid();
return true; return true;
} else {
$result->setInvalid($value, $schema);
return false;
} }
$result->setInvalid($value, $schema);
return false;
} }
} }

View File

@ -42,13 +42,19 @@ class tint extends _tformatable {
if (is_int($value)) { if (is_int($value)) {
$result->setNormalized(); $result->setNormalized();
return false; return false;
} elseif (is_string($value)) {
try {
$value = $this->parse($value);
$result->setValid();
return true;
} catch (ValueException $e) {
}
} elseif (is_scalar($value)) { } elseif (is_scalar($value)) {
$value = intval($value); $value = intval($value);
$result->setValid(); $result->setValid();
return true; return true;
} else {
$result->setInvalid($value, $schema);
return false;
} }
$result->setInvalid($value, $schema);
return false;
} }
} }

View File

@ -1,12 +1,13 @@
<?php <?php
namespace nur\sery\wip\schema\_scalar; namespace nur\sery\wip\schema\_scalar;
use Exception;
use nulib\tests\TestCase; use nulib\tests\TestCase;
use nulib\ValueException; use nulib\ValueException;
use nur\sery\wip\schema\input\Input; use nur\sery\wip\schema\input\Input;
class ScalarValueTest extends TestCase { class ScalarValueTest extends TestCase {
function checkValue(ScalarValue $value, $dest, bool $present, bool $available, bool $valid, bool $normalized): void { function checkValue(ScalarWrapper $value, $dest, bool $present, bool $available, bool $valid, bool $normalized): void {
self::assertSame($dest, $value->get(), "value"); self::assertSame($dest, $value->get(), "value");
self::assertSame($present, $value->isPresent(), "present"); self::assertSame($present, $value->isPresent(), "present");
self::assertSame($available, $value->isAvailable(), "available"); self::assertSame($available, $value->isAvailable(), "available");
@ -14,278 +15,175 @@ class ScalarValueTest extends TestCase {
self::assertSame($normalized, $value->isNormalized(), "normalized"); self::assertSame($normalized, $value->isNormalized(), "normalized");
} }
function checkVerifix(ScalarSchema $schema, $src, bool $verifix, $dest, bool $present, bool $available, bool $valid, bool $normalized, ?array $inputParams=null): void {
$value = $schema->newWrapper();
if ($inputParams !== null) $input = new Input($src, $inputParams);
else $input = $src;
$value->reset($input, null, $verifix);
$this->checkValue($value, $dest, $present, $available, $valid, $normalized);
}
function checkException(ScalarSchema $schema, $src, bool $verifix, string $exceptionClass, ?array $inputParams=null) {
$value = $schema->newWrapper();
if ($inputParams !== null) $src = new Input($src, $inputParams);
self::assertException($exceptionClass, function() use ($value, &$src, $verifix) {
$value->reset($src, null, $verifix);
});
}
function testRawstring() { function testRawstring() {
$schema = new ScalarSchema("rawstring"); $schema = new ScalarSchema("rawstring");
$value = $schema->newValue();
$string = null; $value->reset($string, null, false); $this->checkVerifix($schema, null, false, null, true, true, false, false);
$this->checkValue($value, null, true, true, false, false); $this->checkException($schema, null, true, ValueException::class);
self::assertException(ValueException::class, function() use (&$value) {
$string = null; $value->reset($string);
});
$string = ""; $value->reset($string, null, false); $this->checkVerifix($schema, "", false, "", true, true, true, true);
$this->checkValue($value, "", true, true, true, true); $this->checkVerifix($schema, "", true, "", true, true, true, true);
$string = ""; $value->reset($string);
$this->checkValue($value, "", true, true, true, true);
$string = " "; $value->reset($string, null, false); $this->checkVerifix($schema, " ", false, " ", true, true, true, true);
$this->checkValue($value, " ", true, true, true, true); $this->checkVerifix($schema, " ", true, " ", true, true, true, true);
$string = " "; $value->reset($string);
$this->checkValue($value, " ", true, true, true, true);
$string = "text"; $value->reset($string, null, false); $this->checkVerifix($schema, "text", false, "text", true, true, true, true);
$this->checkValue($value, "text", true, true, true, true); $this->checkVerifix($schema, "text", true, "text", true, true, true, true);
$string = "text"; $value->reset($string);
$this->checkValue($value, "text", true, true, true, true);
$string = " text "; $value->reset($string, null, false); $this->checkVerifix($schema, " text ", false, " text ", true, true, true, true);
$this->checkValue($value, " text ", true, true, true, true); $this->checkVerifix($schema, " text ", true, " text ", true, true, true, true);
$string = " text "; $value->reset($string);
$this->checkValue($value, " text ", true, true, true, true);
$string = false; $value->reset($string, null, false); $this->checkVerifix($schema, false, false, null, true, false, true, true);
$this->checkValue($value, null, true, false, true, true); $this->checkVerifix($schema, false, true, null, true, false, true, true);
$string = false; $value->reset($string);
$this->checkValue($value, null, true, false, true, true);
$string = true; $value->reset($string, null, false); $this->checkVerifix($schema, true, false, true, true, true, true, false);
$this->checkValue($value, true, true, true, true, false); $this->checkVerifix($schema, true, true, "1", true, true, true, false);
$string = true; $value->reset($string);
$this->checkValue($value, "1", true, true, true, false);
$string = 42; $value->reset($string, null, false); $this->checkVerifix($schema, 42, false, 42, true, true, true, false);
$this->checkValue($value, 42, true, true, true, false); $this->checkVerifix($schema, 42, true, "42", true, true, true, false);
$string = 42; $value->reset($string);
$this->checkValue($value, "42", true, true, true, false);
$string = []; $value->reset($string, null, false); $this->checkVerifix($schema, [], false, [], true, true, false, false);
$this->checkValue($value, [], true, true, false, false); $this->checkException($schema, [], true, ValueException::class);
self::assertException(ValueException::class, function() use (&$value) {
$string = null;
$value->reset($string);
});
## Tester nullable ## Tester nullable
$schema = new ScalarSchema("?rawstring"); $schema = new ScalarSchema("?rawstring");
$value = $schema->newValue();
$string = null; $value->reset($string, null, false); $this->checkVerifix($schema, null, false, null, true, true, true, true);
$this->checkValue($value, null, true, true, true, true); $this->checkVerifix($schema, null, true, null, true, true, true, true);
$string = null; $value->reset($string, null);
$this->checkValue($value, null, true, true, true, true);
## Tester required ## Tester required
$schema = new ScalarSchema(["rawstring", "required" => true]); $schema = new ScalarSchema(["rawstring", "required" => true]);
$value = $schema->newValue();
$string = false; $value->reset($string, null, false); $this->checkVerifix($schema, false, false, null, true, false, false, false);
$this->checkValue($value, null, true, false, false, false); $this->checkException($schema, false, true, ValueException::class);
self::assertException(ValueException::class, function() use (&$value) {
$string = false; $value->reset($string);
});
## Tester allow_empty === false ## Tester allow_empty === false
$inputParams = ["allow_empty" => false];
$schema = new ScalarSchema("rawstring"); $schema = new ScalarSchema("rawstring");
$value = $schema->newValue();
$string = null; $input = new Input($string, ["allow_empty" => false]); $this->checkVerifix($schema, null, false, null, true, true, false, false, $inputParams);
$value->reset($input, null, false); $this->checkException($schema, null, true, ValueException::class, $inputParams);
$this->checkValue($value, null, true, true, false, false);
self::assertException(ValueException::class, function() use (&$value) {
$string = null; $input = new Input($string, ["allow_empty" => false]);
$value->reset($input);
});
$string = ""; $input = new Input($string, ["allow_empty" => false]); $this->checkVerifix($schema, "", false, null, true, false, true, true, $inputParams);
$value->reset($input, null, false); $this->checkVerifix($schema, "", true, null, true, false, true, true, $inputParams);
$this->checkValue($value, null, true, false, true, true);
$string = ""; $input = new Input($string, ["allow_empty" => false]);
$value->reset($input);
$this->checkValue($value, null, true, false, true, true);
$schema = new ScalarSchema("?rawstring"); $schema = new ScalarSchema("?rawstring");
$value = $schema->newValue();
$string = null; $input = new Input($string, ["allow_empty" => false]); $this->checkVerifix($schema, null, false, null, true, true, true, true, $inputParams);
$value->reset($input, null, false); $this->checkVerifix($schema, null, true, null, true, true, true, true, $inputParams);
$this->checkValue($value, null, true, true, true, true);
$string = null; $input = new Input($string, ["allow_empty" => false]);
$value->reset($input);
$this->checkValue($value, null, true, true, true, true);
$string = ""; $input = new Input($string, ["allow_empty" => false]); $this->checkVerifix($schema, "", false, null, true, false, true, true, $inputParams);
$value->reset($input, null, false); $this->checkVerifix($schema, "", true, null, true, false, true, true, $inputParams);
$this->checkValue($value, null, true, false, true, true);
$string = ""; $input = new Input($string, ["allow_empty" => false]);
$value->reset($input);
$this->checkValue($value, null, true, false, true, true);
} }
function testString() { function testString() {
$schema = new ScalarSchema("string"); $schema = new ScalarSchema("string");
$value = $schema->newValue();
$string = null; $value->reset($string, null, false); $this->checkVerifix($schema, null, false, null, true, true, false, false);
$this->checkValue($value, null, true, true, false, false); $this->checkException($schema, null, true, ValueException::class);
self::assertException(ValueException::class, function() use (&$value) {
$string = null;
$value->reset($string);
});
$string = ""; $value->reset($string, null, false); $this->checkVerifix($schema, "", false, "", true, true, true, true);
$this->checkValue($value, "", true, true, true, true); $this->checkVerifix($schema, "", true, "", true, true, true, true);
$string = ""; $value->reset($string);
$this->checkValue($value, "", true, true, true, true);
$string = " "; $value->reset($string, null, false); $this->checkVerifix($schema, " ", false, "", true, true, true, false);
$this->checkValue($value, "", true, true, true, false); $this->checkVerifix($schema, " ", true, "", true, true, true, true);
$string = " "; $value->reset($string);
$this->checkValue($value, "", true, true, true, true);
$string = "text"; $value->reset($string, null, false); $this->checkVerifix($schema, "text", false, "text", true, true, true, true);
$this->checkValue($value, "text", true, true, true, true); $this->checkVerifix($schema, "text", true, "text", true, true, true, true);
$string = "text"; $value->reset($string);
$this->checkValue($value, "text", true, true, true, true);
$string = " text "; $value->reset($string, null, false); $this->checkVerifix($schema, " text ", false, "text", true, true, true, false);
$this->checkValue($value, "text", true, true, true, false); $this->checkVerifix($schema, " text ", true, "text", true, true, true, true);
$string = " text "; $value->reset($string);
$this->checkValue($value, "text", true, true, true, true);
$string = false; $value->reset($string, null, false); $this->checkVerifix($schema, false, false, null, true, false, true, true);
$this->checkValue($value, null, true, false, true, true); $this->checkVerifix($schema, false, true, null, true, false, true, true);
$string = false; $value->reset($string);
$this->checkValue($value, null, true, false, true, true);
$string = true; $value->reset($string, null, false); $this->checkVerifix($schema, true, false, true, true, true, true, false);
$this->checkValue($value, true, true, true, true, false); $this->checkVerifix($schema, true, true, "1", true, true, true, false);
$string = true; $value->reset($string);
$this->checkValue($value, "1", true, true, true, false);
$string = 42; $value->reset($string, null, false); $this->checkVerifix($schema, 42, false, 42, true, true, true, false);
$this->checkValue($value, 42, true, true, true, false); $this->checkVerifix($schema, 42, true, "42", true, true, true, false);
$string = 42; $value->reset($string);
$this->checkValue($value, "42", true, true, true, false);
$string = []; $value->reset($string, null, false); $this->checkVerifix($schema, [], false, [], true, true, false, false);
$this->checkValue($value, [], true, true, false, false); $this->checkException($schema, [], true, ValueException::class);
self::assertException(ValueException::class, function() use (&$value) {
$string = null;
$value->reset($string);
});
## Tester nullable ## Tester nullable
$schema = new ScalarSchema("?string"); $schema = new ScalarSchema("?string");
$value = $schema->newValue();
$string = null; $value->reset($string, null, false); $this->checkVerifix($schema, null, false, null, true, true, true, true);
$this->checkValue($value, null, true, true, true, true); $this->checkVerifix($schema, null, true, null, true, true, true, true);
$string = null; $value->reset($string, null);
$this->checkValue($value, null, true, true, true, true);
## Tester required ## Tester required
$schema = new ScalarSchema(["string", "required" => true]); $schema = new ScalarSchema(["string", "required" => true]);
$value = $schema->newValue();
$string = false; $value->reset($string, null, false); $this->checkVerifix($schema, false, false, null, true, false, false, false);
$this->checkValue($value, null, true, false, false, false); $this->checkException($schema, false, true, ValueException::class);
self::assertException(ValueException::class, function() use (&$value) {
$string = false; $value->reset($string);
});
} }
function testInt() { function testInt() {
$schema = new ScalarSchema("int"); $schema = new ScalarSchema("int");
$value = $schema->newValue();
$int = null; $value->reset($int, null, false); $this->checkVerifix($schema, null, false, null, true, true, false, false);
$this->checkValue($value, null, true, true, false, false); $this->checkException($schema, null, true, ValueException::class);
self::assertException(ValueException::class, function() use (&$value) {
$int = null;
$value->reset($int);
});
$int = 42; $value->reset($int, null, false); $this->checkVerifix($schema, 42, false, 42, true, true, true, true);
$this->checkValue($value, 42, true, true, true, true); $this->checkVerifix($schema, 42, true, 42, true, true, true, true);
$int = 42; $value->reset($int);
$this->checkValue($value, 42, true, true, true, true);
$int = "42"; $value->reset($int, null, false); $this->checkVerifix($schema, "42", false, "42", true, true, true, false);
$this->checkValue($value, "42", true, true, true, false); $this->checkVerifix($schema, "42", true, 42, true, true, true, false);
$int = "42"; $value->reset($int);
$this->checkValue($value, 42, true, true, true, false);
$int = "42.5"; $value->reset($int, null, false); $this->checkVerifix($schema, "42.5", false, "42.5", true, true, true, false);
$this->checkValue($value, "42.5", true, true, true, false); $this->checkVerifix($schema, "42.5", true, 42, true, true, true, false);
$int = "42.5"; $value->reset($int);
$this->checkValue($value, 42, true, true, true, false);
$int = "42,5"; $value->reset($int, null, false); $this->checkVerifix($schema, "42,5", false, "42,5", true, true, true, false);
$this->checkValue($value, "42,5", true, true, true, false); $this->checkVerifix($schema, "42,5", true, 42, true, true, true, false);
$int = "42,5"; $value->reset($int);
$this->checkValue($value, 42, true, true, true, false);
$int = " 42 "; $value->reset($int, null, false); $this->checkVerifix($schema, " 42 ", false, "42", true, true, true, false);
$this->checkValue($value, "42", true, true, true, false); $this->checkVerifix($schema, " 42 ", true, 42, true, true, true, false);
$int = " 42 "; $value->reset($int);
$this->checkValue($value, 42, true, true, true, false);
$int = ""; $value->reset($int, null, false); $this->checkVerifix($schema, "", false, "", true, true, false, false);
$this->checkValue($value, "", true, true, false, false); $this->checkException($schema, "", true, ValueException::class);
self::assertException(ValueException::class, function() use (&$value) {
$int = "";
$value->reset($int);
});
$int = " "; $value->reset($int, null, false); $this->checkVerifix($schema, " ", false, " ", true, true, false, false);
$this->checkValue($value, " ", true, true, false, false); $this->checkException($schema, " ", true, ValueException::class);
self::assertException(ValueException::class, function() use (&$value) {
$int = " ";
$value->reset($int);
});
$int = "text"; $value->reset($int, null, false); $this->checkVerifix($schema, "text", false, "text", true, true, false, false);
$this->checkValue($value, "text", true, true, false, false); $this->checkException($schema, "text", true, ValueException::class);
self::assertException(ValueException::class, function() use (&$value) {
$int = "text";
$value->reset($int);
});
$int = false; $value->reset($int, null, false); $this->checkVerifix($schema, false, false, null, true, false, true, true);
$this->checkValue($value, null, true, false, true, true); $this->checkVerifix($schema, false, true, null, true, false, true, true);
$int = false; $value->reset($int);
$this->checkValue($value, null, true, false, true, true);
$int = true; $value->reset($int, null, false); $this->checkVerifix($schema, true, false, true, true, true, true, false);
$this->checkValue($value, true, true, true, true, false); $this->checkVerifix($schema, true, true, 1, true, true, true, false);
$int = true; $value->reset($int);
$this->checkValue($value, 1, true, true, true, false);
$int = []; $value->reset($int, null, false); $this->checkVerifix($schema, [], false, [], true, true, false, false);
$this->checkValue($value, [], true, true, false, false); $this->checkException($schema, [], true, ValueException::class);
self::assertException(ValueException::class, function() use (&$value) {
$string = null;
$value->reset($string);
});
## Tester nullable ## Tester nullable
$schema = new ScalarSchema("?int"); $schema = new ScalarSchema("?int");
$value = $schema->newValue();
$int = null; $value->reset($int, null, false); $this->checkVerifix($schema, null, false, null, true, true, true, true);
$this->checkValue($value, null, true, true, true, true); $this->checkVerifix($schema, null, true, null, true, true, true, true);
$int = null; $value->reset($int, null);
$this->checkValue($value, null, true, true, true, true);
## Tester required ## Tester required
$schema = new ScalarSchema(["int", "required" => true]); $schema = new ScalarSchema(["int", "required" => true]);
$value = $schema->newValue();
$int = false; $value->reset($int, null, false); $this->checkVerifix($schema, false, false, null, true, false, false, false);
$this->checkValue($value, null, true, false, false, false); $this->checkException($schema, false, true, ValueException::class);
self::assertException(ValueException::class, function() use (&$value) {
$string = false; $value->reset($string);
});
} }
} }

View File

@ -3,7 +3,7 @@ namespace nur\sery\wip\schema\types;
use Exception; use Exception;
use nulib\tests\TestCase; use nulib\tests\TestCase;
use nur\sery\wip\schema\_scalar\ScalarValue; use nur\sery\wip\schema\_scalar\ScalarWrapper;
use nur\sery\wip\schema\Schema; use nur\sery\wip\schema\Schema;
class boolTest extends TestCase { class boolTest extends TestCase {
@ -58,8 +58,8 @@ class boolTest extends TestCase {
} }
function testBool() { function testBool() {
/** @var ScalarValue $destv */ /** @var ScalarWrapper $destv */
Schema::nv($destv, $dest, null, $schema, "bool"); Schema::nw($dest, null, $schema, "bool", $destv);
$destvSetter = function($value) use($destv) { $destvSetter = function($value) use($destv) {
return function() use($destv, $value) { return function() use($destv, $value) {
$destv->set($value); $destv->set($value);
@ -74,8 +74,8 @@ class boolTest extends TestCase {
} }
function testNbool() { function testNbool() {
/** @var ScalarValue $destv */ /** @var ScalarWrapper $destv */
Schema::nv($destv, $dest, null, $schema, "?bool"); Schema::nw($dest, null, $schema, "?bool", $destv);
$destvSetter = function($value) use($destv) { $destvSetter = function($value) use($destv) {
return function() use($destv, $value) { return function() use($destv, $value) {
$destv->set($value); $destv->set($value);

View File

@ -3,7 +3,7 @@ namespace nur\sery\wip\schema\types;
use Exception; use Exception;
use nulib\tests\TestCase; use nulib\tests\TestCase;
use nur\sery\wip\schema\_scalar\ScalarValue; use nur\sery\wip\schema\_scalar\ScalarWrapper;
use nur\sery\wip\schema\Schema; use nur\sery\wip\schema\Schema;
class floatTest extends TestCase { class floatTest extends TestCase {
@ -32,8 +32,8 @@ class floatTest extends TestCase {
} }
function testFloat() { function testFloat() {
/** @var ScalarValue $destv */ /** @var ScalarWrapper $destv */
Schema::nv($destv, $dest, null, $schema, "float"); Schema::nw($dest, null, $schema, "float", $destv);
$destvSetter = function($value) use($destv) { $destvSetter = function($value) use($destv) {
return function() use($destv, $value) { return function() use($destv, $value) {
$destv->set($value); $destv->set($value);
@ -52,11 +52,11 @@ class floatTest extends TestCase {
} }
function testRequiredFloat() { function testRequiredFloat() {
/** @var ScalarValue $destv */ /** @var ScalarWrapper $destv */
Schema::nv($destv, $dest, null, $schema, [ Schema::nw($dest, null, $schema, [
"float", null, "float", null,
"required" => true, "required" => true,
]); ], $destv);
$destvSetter = function($value) use($destv) { $destvSetter = function($value) use($destv) {
return function() use($destv, $value) { return function() use($destv, $value) {
$destv->set($value); $destv->set($value);
@ -74,8 +74,8 @@ class floatTest extends TestCase {
} }
function testNfloat() { function testNfloat() {
/** @var ScalarValue $destv */ /** @var ScalarWrapper $destv */
Schema::nv($destv, $dest, null, $schema, "?float"); Schema::nw($dest, null, $schema, "?float", $destv);
$destvSetter = function($value) use($destv) { $destvSetter = function($value) use($destv) {
return function() use($destv, $value) { return function() use($destv, $value) {
$destv->set($value); $destv->set($value);
@ -105,11 +105,11 @@ class floatTest extends TestCase {
} }
function testRequiredNfloat() { function testRequiredNfloat() {
/** @var ScalarValue $destv */ /** @var ScalarWrapper $destv */
Schema::nv($destv, $dest, null, $schema, [ Schema::nw($dest, null, $schema, [
"?float", null, "?float", null,
"required" => true, "required" => true,
]); ], $destv);
$destvSetter = function($value) use($destv) { $destvSetter = function($value) use($destv) {
return function() use($destv, $value) { return function() use($destv, $value) {
$destv->set($value); $destv->set($value);

View File

@ -3,7 +3,7 @@ namespace nur\sery\wip\schema\types;
use Exception; use Exception;
use nulib\tests\TestCase; use nulib\tests\TestCase;
use nur\sery\wip\schema\_scalar\ScalarValue; use nur\sery\wip\schema\_scalar\ScalarWrapper;
use nur\sery\wip\schema\Schema; use nur\sery\wip\schema\Schema;
class intTest extends TestCase { class intTest extends TestCase {
@ -32,8 +32,8 @@ class intTest extends TestCase {
} }
function testInt() { function testInt() {
/** @var ScalarValue $destv */ /** @var ScalarWrapper $destv */
Schema::nv($destv, $dest, null, $schema, "int"); Schema::nw($dest, null, $schema, "int", $destv);
$destvSetter = function($value) use($destv) { $destvSetter = function($value) use($destv) {
return function() use($destv, $value) { return function() use($destv, $value) {
$destv->set($value); $destv->set($value);
@ -52,11 +52,11 @@ class intTest extends TestCase {
} }
function testRequiredInt() { function testRequiredInt() {
/** @var ScalarValue $destv */ /** @var ScalarWrapper $destv */
Schema::nv($destv, $dest, null, $schema, [ Schema::nw($dest, null, $schema, [
"int", null, "int", null,
"required" => true, "required" => true,
]); ], $destv);
$destvSetter = function($value) use($destv) { $destvSetter = function($value) use($destv) {
return function() use($destv, $value) { return function() use($destv, $value) {
$destv->set($value); $destv->set($value);
@ -74,8 +74,8 @@ class intTest extends TestCase {
} }
function testNint() { function testNint() {
/** @var ScalarValue $destv */ /** @var ScalarWrapper $destv */
Schema::nv($destv, $dest, null, $schema, "?int"); Schema::nw($dest, null, $schema, "?int", $destv);
$destvSetter = function($value) use($destv) { $destvSetter = function($value) use($destv) {
return function() use($destv, $value) { return function() use($destv, $value) {
$destv->set($value); $destv->set($value);
@ -105,11 +105,11 @@ class intTest extends TestCase {
} }
function testRequiredNint() { function testRequiredNint() {
/** @var ScalarValue $destv */ /** @var ScalarWrapper $destv */
Schema::nv($destv, $dest, null, $schema, [ Schema::nw($dest, null, $schema, [
"?int", null, "?int", null,
"required" => true, "required" => true,
]); ], $destv);
$destvSetter = function($value) use($destv) { $destvSetter = function($value) use($destv) {
return function() use($destv, $value) { return function() use($destv, $value) {
$destv->set($value); $destv->set($value);

View File

@ -3,7 +3,7 @@ namespace nur\sery\wip\schema\types;
use Exception; use Exception;
use nulib\tests\TestCase; use nulib\tests\TestCase;
use nur\sery\wip\schema\_scalar\ScalarValue; use nur\sery\wip\schema\_scalar\ScalarWrapper;
use nur\sery\wip\schema\Schema; use nur\sery\wip\schema\Schema;
class strTest extends TestCase { class strTest extends TestCase {
@ -13,8 +13,8 @@ class strTest extends TestCase {
self::assertSame("", $dest); self::assertSame("", $dest);
$destv->set(" "); $destv->set(" ");
self::assertSame(" ", $destv->get()); self::assertSame("", $destv->get());
self::assertSame(" ", $dest); self::assertSame("", $dest);
$destv->set("a"); $destv->set("a");
self::assertSame("a", $destv->get()); self::assertSame("a", $destv->get());
@ -24,7 +24,7 @@ class strTest extends TestCase {
self::assertSame("12", $destv->get()); self::assertSame("12", $destv->get());
$destv->set(" 12 "); $destv->set(" 12 ");
self::assertSame(" 12 ", $destv->get()); self::assertSame("12", $destv->get());
$destv->set(12); $destv->set(12);
self::assertSame("12", $destv->get()); self::assertSame("12", $destv->get());
@ -40,8 +40,8 @@ class strTest extends TestCase {
} }
function testStr() { function testStr() {
/** @var ScalarValue $destv */ /** @var ScalarWrapper $destv */
Schema::nv($destv, $dest, null, $schema, "string"); Schema::nw($dest, null, $schema, "string", $destv);
$destvSetter = function($value) use($destv) { $destvSetter = function($value) use($destv) {
return function() use($destv, $value) { return function() use($destv, $value) {
$destv->set($value); $destv->set($value);
@ -58,11 +58,11 @@ class strTest extends TestCase {
} }
function testRequiredStr() { function testRequiredStr() {
/** @var ScalarValue $destv */ /** @var ScalarWrapper $destv */
Schema::nv($destv, $dest, null, $schema, [ Schema::nw($dest, null, $schema, [
"string", null, "string", null,
"required" => true, "required" => true,
]); ], $destv);
$destvSetter = function($value) use($destv) { $destvSetter = function($value) use($destv) {
return function() use($destv, $value) { return function() use($destv, $value) {
$destv->set($value); $destv->set($value);
@ -78,8 +78,8 @@ class strTest extends TestCase {
} }
function testNstr() { function testNstr() {
/** @var ScalarValue $destv */ /** @var ScalarWrapper $destv */
Schema::nv($destv, $dest, null, $schema, "?string"); Schema::nw($dest, null, $schema, "?string", $destv);
$destvSetter = function($value) use($destv) { $destvSetter = function($value) use($destv) {
return function() use($destv, $value) { return function() use($destv, $value) {
$destv->set($value); $destv->set($value);
@ -99,11 +99,11 @@ class strTest extends TestCase {
} }
function testRequiredNstr() { function testRequiredNstr() {
/** @var ScalarValue $destv */ /** @var ScalarWrapper $destv */
Schema::nv($destv, $dest, null, $schema, [ Schema::nw($dest, null, $schema, [
"?string", null, "?string", null,
"required" => true, "required" => true,
]); ], $destv);
$destvSetter = function($value) use($destv) { $destvSetter = function($value) use($destv) {
return function() use($destv, $value) { return function() use($destv, $value) {
$destv->set($value); $destv->set($value);

View File

@ -2,7 +2,7 @@
namespace nur\sery\wip\schema\types; namespace nur\sery\wip\schema\types;
use nulib\tests\TestCase; use nulib\tests\TestCase;
use nur\sery\wip\schema\_scalar\ScalarValue; use nur\sery\wip\schema\_scalar\ScalarWrapper;
use nur\sery\wip\schema\Schema; use nur\sery\wip\schema\Schema;
class unionTest extends TestCase { class unionTest extends TestCase {
@ -10,8 +10,8 @@ class unionTest extends TestCase {
## l'ordre des types doit être respecté ## l'ordre des types doit être respecté
# string puis int # string puis int
/** @var ScalarValue $siv */ /** @var ScalarWrapper $siv */
Schema::nv($siv, $si, null, $sis, "string|int"); Schema::nw($si, null, $sis, "string|int", $siv);
$siv->set("12"); $siv->set("12");
self::assertSame("12", $si); self::assertSame("12", $si);
@ -19,7 +19,7 @@ class unionTest extends TestCase {
self::assertSame(12, $si); self::assertSame(12, $si);
# int puis string # int puis string
Schema::nv($isv, $is, null, $iss, "int|string"); Schema::nw($is, null, $iss, "int|string", $isv);
$isv->set("12"); $isv->set("12");
self::assertSame("12", $is); self::assertSame("12", $is);