getNewStates example

'versionId' => Uuid::fromHexToBytes($context->getVersionId()),
        ];

        $products = $this->connection->fetchAllAssociative(
            $sql,
            $params,
            ['ids' => ArrayParameterType::STRING]
        );

        $updates = [];
        foreach ($products as $product) {
            $newStates = $this->getNewStates($product);
            $oldStates = $product['states'] ? json_decode((string) $product['states'], true, 512, \JSON_THROW_ON_ERROR) : [];

            if (\count(array_diff($newStates$oldStates)) === 0) {
                continue;
            }

            $updates[] = new UpdatedStates($product['id']$oldStates$newStates);
        }

        if (empty($updates)) {
            return;
        }

class UpdatedStatesTest extends TestCase
{
    public function testUpdatedStates(): void
    {
        $updatedStates = new UpdatedStates('foobar', ['foo']['bar']);

        static::assertEquals('foobar', $updatedStates->getId());
        static::assertEquals(['foo']$updatedStates->getOldStates());
        static::assertEquals(['bar']$updatedStates->getNewStates());

        $updatedStates->setNewStates(['foo']);

        static::assertEquals(['foo']$updatedStates->getNewStates());
    }
}
Home | Imprint | This part of the site doesn't use cookies.