コード例 #1
0
 public function create(ConfigCollection $collection)
 {
     $this->pdo->beginTransaction();
     try {
         $this->objectRepository->create(ConfigCollection::TYPE, $collection->getUuid());
         $this->executeSql('
             INSERT INTO config_collections (config_collection_uuid, type, name)
                  VALUES (:config_collection_uuid, :type, :name)
         ', ['config_collection_uuid' => $collection->getUuid()->getBytes(), 'type' => $collection->getType()->getTypeName(), 'name' => $collection->getName()]);
         $this->createItems($collection);
         $this->pdo->commit();
         $collection->metaDataSetInsertTimestamp(new \DateTimeImmutable());
     } catch (\Throwable $exception) {
         $this->pdo->rollBack();
         throw $exception;
     }
 }
コード例 #2
0
 public function it_can_create_a_collection(ConfigCollection $collection, ConfigTypeInterface $type, \PDOStatement $statement, \PDOStatement $itemStatement1, \PDOStatement $itemStatement2)
 {
     $uuid = Uuid::uuid4();
     $typeName = 'exampleType';
     $name = 'example';
     $items = ['k1' => 'v1', 'k2' => 'v2'];
     $collection->getUuid()->willReturn($uuid);
     $collection->getType()->willReturn($type);
     $collection->getName()->willReturn($name);
     $collection->getItems()->willReturn($items);
     $collection->metaDataSetInsertTimestamp(new Argument\Token\TypeToken(\DateTimeInterface::class))->shouldBeCalled();
     $type->getTypeName()->willReturn($typeName);
     $this->pdo->beginTransaction()->shouldBeCalled();
     $this->objectRepository->create(ConfigCollection::TYPE, $uuid)->shouldBeCalled();
     $this->pdo->prepare(new Argument\Token\StringContainsToken('INSERT INTO config_collections'))->willReturn($statement);
     $statement->execute(['config_collection_uuid' => $uuid->getBytes(), 'type' => $typeName, 'name' => $name])->shouldBeCalled();
     $this->pdo->prepare(new Argument\Token\StringContainsToken('INSERT INTO config_items'))->willReturn($itemStatement1, $itemStatement2, false);
     $itemStatement1->execute(['config_collection_uuid' => $uuid->getBytes(), 'name' => 'k1', 'value' => json_encode('v1')])->shouldBeCalled();
     $itemStatement2->execute(['config_collection_uuid' => $uuid->getBytes(), 'name' => 'k2', 'value' => json_encode('v2')])->shouldBeCalled();
     $this->pdo->commit()->shouldBeCalled();
     $this->create($collection);
 }