public function it_can_get_a_collection_by_type_and_name(ConfigTypeInterface $type, \PDOStatement $statement, \PDOStatement $itemStatement) { $collectionName = 'colName'; $collectionUuid = Uuid::uuid4(); $collectionItems = ['k1' => 'v1', 'k2' => 'v2']; $typeName = 'specType'; $type->getTypeName()->willReturn($typeName); $type->getDefaultItems()->willReturn(['k1' => null, 'k2' => null]); $this->pdo->prepare(new Argument\Token\StringContainsToken('FROM config_collections'))->willReturn($statement); $statement->execute(['type' => $typeName, 'name' => $collectionName])->shouldBeCalled(); $statement->fetch(\PDO::FETCH_ASSOC)->willReturn(['config_collection_uuid' => $collectionUuid->getBytes(), 'type' => $typeName, 'name' => $collectionName, 'created' => date('Y-m-d H:i:s'), 'updated' => date('Y-m-d H:i:s')]); $this->pdo->quote($collectionUuid->getBytes())->willReturn('"uuid1"'); $this->pdo->prepare(new Argument\Token\StringContainsToken('FROM config_items'))->willReturn($itemStatement); $itemStatement->execute([])->shouldBeCalled(); $itemStatement->fetch(\PDO::FETCH_ASSOC)->willReturn(['config_collection_uuid' => $collectionUuid->getBytes(), 'name' => 'k1', 'value' => '"v1"'], ['config_collection_uuid' => $collectionUuid->getBytes(), 'name' => 'k2', 'value' => '"v2"'], false); $this->typeContainer->getType($typeName)->willReturn($type); $collection = $this->getCollectionByTypeAndName($type, $collectionName); $collection->getUuid()->shouldBeLike($collectionUuid); $collection->getItems()->shouldReturn($collectionItems); }
private function getCollectionFromRow(array $row) : ConfigCollection { return (new ConfigCollection(Uuid::fromBytes($row['config_collection_uuid']), $this->typeContainer->getType($row['type']), $row['name']))->metaDataSetInsertTimestamp(new \DateTimeImmutable($row['created']))->metaDataSetUpdateTimestamp(new \DateTimeImmutable($row['updated'])); }