visit(function (Node $node) use (&$visits): void { if ($node->isRoot()) { $visits[] = '#1'; } }) ->visit(function (Node $node) use (&$visits): void { if ($node->isRoot()) { $visits[] = '#2'; } }) ->visit(function () use ($error): void { throw $error; }) ->mapper() ->map(SimpleObject::class, ['value' => 'foo']); } catch (MappingError $exception) { self::assertSame('some error message', (string)$exception->node()->messages()[0]); } self::assertSame(['#1', '#2'], $visits); } }