Пример #1
0
 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);
 }
Пример #2
0
 public function getCollectionByTypeAndName(ConfigTypeInterface $type, string $name) : ConfigCollection
 {
     $query = $this->executeSql('
             SELECT config_collection_uuid, type, name, created, updated
               FROM config_collections
         INNER JOIN objects ON (page_uuid = uuid AND type = "configCollections")
              WHERE type = :type
                AND name = :name
     ', ['type' => $type->getTypeName(), 'name' => $name]);
     $collection = $this->getCollectionFromRow($query->fetch(\PDO::FETCH_ASSOC));
     $this->getItemsForCollections([$collection]);
     return $collection;
 }