Skip to content

Commit e30a355

Browse files
committed
Fix test
1 parent 2d36d6e commit e30a355

File tree

8 files changed

+56
-9
lines changed

8 files changed

+56
-9
lines changed

packages/database/src/Hydrator/SimpleHydrator.php

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,12 @@ class SimpleHydrator implements HydratorInterface, FieldHydratorInterface
2121
*/
2222
public function extract(object $object): array
2323
{
24-
if ($object instanceof DumpableInterface) {
25-
return new AccessibleHydrator()->extract($object);
26-
}
24+
// Since dump() use get_object_dump_values(), protected fields will not return
25+
// We must use total dump by ReflectAccessor::getPropertiesValues($object);
26+
27+
// if ($object instanceof DumpableInterface) {
28+
// return new AccessibleHydrator()->extract($object);
29+
// }
2730

2831
if ($object instanceof Traversable) {
2932
return iterator_to_array($object);

packages/dom/src/HTML5Factory.php

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -161,15 +161,20 @@ public static function createFromString(
161161
*
162162
* @param string $text
163163
*
164-
* @return HTMLElement
164+
* @return HTMLElement|Node
165165
*/
166-
public static function parse(string $text): HTMLElement
166+
public static function parse(string $text): HTMLElement|Node
167167
{
168168
$doc = static::document();
169169
$root = $doc->createElement('root');
170170
$root->innerHTML = $text;
171171

172-
return $root->firstElementChild;
172+
return $root->firstChild;
173+
}
174+
175+
public static function parseAsElement(string $text): HTMLElement
176+
{
177+
return static::parse($text);
173178
}
174179

175180
/**

packages/form/test/FormTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -411,7 +411,7 @@ public function testRenderField()
411411
{
412412
$form = $this->getByDefine('windwalker');
413413

414-
$html = '<div id="input-windwalker-id-wrapper" class="control-input" data-field-wrapper><label id="input-windwalker-id-label" data-field-label for="input-windwalker-id">ID</label><div><input id="input-windwalker-id" name="windwalker[id]" data-field-input type="text" value></div></div>';
414+
$html = '<div id="input-windwalker-id-wrapper" class="control-input" data-field-wrapper><label id="input-windwalker-id-label" data-field-label for="input-windwalker-id">ID</label><div><input id="input-windwalker-id" name="windwalker[id]" data-field-input type="text" value=""></div></div>';
415415

416416
self::assertEquals($html, $form->renderField('id'));
417417

packages/orm/src/EntityMapper.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1740,7 +1740,7 @@ public function toEntity(array|object $data): object
17401740
}
17411741

17421742
if (is_object($data)) {
1743-
$data = TypeCast::toArray($data);
1743+
$data = ReflectAccessor::getPropertiesValues($data);
17441744
}
17451745

17461746
// Only ORM has Hydrator, we must call ORM to do this.

packages/orm/src/NestedSetMapper.php

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -332,6 +332,15 @@ protected function preprocessSave(BeforeSaveEvent $event, bool $new = false): vo
332332
$data = $event->data;
333333
/** @var NestedEntityInterface $entity */
334334
$entity = $this->toEntity($event->source);
335+
336+
if (is_array($event->source)) {
337+
$position = $event->source['position'];
338+
} else {
339+
$position = $event->source->getPosition();
340+
}
341+
342+
$this->hydrate(compact('position'), $entity);
343+
335344
$position = $entity->getPosition();
336345
$className = $this->getMetadata()->getClassName();
337346

@@ -353,11 +362,18 @@ protected function preprocessSave(BeforeSaveEvent $event, bool $new = false): vo
353362

354363
// We are inserting a node relative to the last root node.
355364
if (!$position->getReferenceId()) {
365+
$parentId = $entity->getParentId() ?: $this->getEmptyParentId();
356366
$reference = $this->select($k, 'parent_id', 'level', 'lft', 'rgt')
357-
->where('id', $entity->getParentId() ?: $this->getEmptyParentId())
367+
->where('id', $parentId)
358368
->order('lft', 'DESC')
359369
->limit(1)
360370
->get($className);
371+
372+
if (!$reference) {
373+
throw new NestedHandleException(
374+
sprintf('Reference of parent %s not found.', $parentId)
375+
);
376+
}
361377
} else {
362378
// We have a real node set as a location reference.
363379
// Get the reference node by primary key.

packages/orm/test/Entity/StubLocation.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
use Windwalker\ORM\Metadata\EntityMetadata;
1818
use Windwalker\ORM\Relation\Action;
1919
use Windwalker\ORM\Relation\RelationCollection;
20+
use Windwalker\Utilities\Attributes\Expose;
2021

2122
/**
2223
* The Location class.
@@ -44,8 +45,10 @@ class StubLocation implements EntityInterface
4445
OnUpdate(Action::CASCADE),
4546
OnDelete(Action::CASCADE)
4647
]
48+
#[Expose]
4749
protected ?StubLocationData $data = null;
4850

51+
#[Expose]
4952
protected RelationCollection|null $sakuras = null;
5053

5154
protected RelationCollection|null $roses = null;

packages/orm/test/Entity/StubLocationData.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
use Windwalker\ORM\Attributes\Table;
1212
use Windwalker\ORM\EntityInterface;
1313
use Windwalker\ORM\EntityTrait;
14+
use Windwalker\Utilities\Attributes\Expose;
1415

1516
/**
1617
* The LocationData class.
@@ -28,6 +29,7 @@ class StubLocationData implements EntityInterface
2829
protected string $locationNo = '';
2930

3031
#[Column('data')]
32+
#[Expose]
3133
protected string|stdClass $data = '';
3234

3335
/**

packages/utilities/src/TypeCast.php

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,24 @@ public static function extractEnum(\UnitEnum $data): string|int
6969
return $data->name;
7070
}
7171

72+
public static function dumpAll(object $object): array
73+
{
74+
static $propsCache = [];
75+
76+
$ref = new \ReflectionObject($object);
77+
$props = $propsCache[$object::class] ??= $ref->getProperties(
78+
\ReflectionProperty::IS_PUBLIC | \ReflectionProperty::IS_PROTECTED | \ReflectionProperty::IS_PRIVATE
79+
);
80+
81+
$values = [];
82+
83+
foreach ($props as $prop) {
84+
$values[$prop->getName()] = $prop->getValue($object);
85+
}
86+
87+
return $values;
88+
}
89+
7290
/**
7391
* Utility function to convert all types to an array.
7492
*

0 commit comments

Comments
 (0)