| @@ 155-193 (lines=39) @@ | ||
| 152 | /** |
|
| 153 | * Test persist. |
|
| 154 | */ |
|
| 155 | public function testPersist() |
|
| 156 | { |
|
| 157 | $this |
|
| 158 | ->given($repository = $this->randomRepository()) |
|
| 159 | ->and($unique = $this->uniqueValue()) |
|
| 160 | ->then() |
|
| 161 | ->variable($repository->get($unique->id())) |
|
| 162 | ->isNull() |
|
| 163 | ->and() |
|
| 164 | ->when($repository->persist($unique)) |
|
| 165 | ->then() |
|
| 166 | ->object($repository->get($unique->id())) |
|
| 167 | ->isEqualTo($unique) |
|
| 168 | ; |
|
| 169 | ||
| 170 | $this |
|
| 171 | ->given($repository = $this->randomRepository()) |
|
| 172 | ->given($id = UserId::next()) |
|
| 173 | ->then() |
|
| 174 | ->exception(function () use ($repository, $id) { |
|
| 175 | $repository->persist($id); |
|
| 176 | })->isInstanceOf(\InvalidArgumentException::class) |
|
| 177 | ; |
|
| 178 | ||
| 179 | $this |
|
| 180 | ->given($repository = $this->emptyRepository()) |
|
| 181 | ->and($value = $this->randomValue()) |
|
| 182 | ->and($age = $value->age()) |
|
| 183 | ->when(function () use ($repository, $value, $age) { |
|
| 184 | $repository->persist($value); |
|
| 185 | $value->setAge($age + 1); |
|
| 186 | $repository->persist($value); |
|
| 187 | }) |
|
| 188 | ->then() |
|
| 189 | ->object($other = $repository->findOne(Criteria::property('id')->eq($value->id()))) |
|
| 190 | ->integer($other->age()) |
|
| 191 | ->isEqualTo($age + 1) |
|
| 192 | ; |
|
| 193 | } |
|
| 194 | ||
| 195 | /** |
|
| 196 | * Test persistAll. |
|
| @@ 154-192 (lines=39) @@ | ||
| 151 | /** |
|
| 152 | * Test persist. |
|
| 153 | */ |
|
| 154 | public function testPersist() |
|
| 155 | { |
|
| 156 | $this |
|
| 157 | ->given($repository = $this->randomRepository()) |
|
| 158 | ->and($unique = $this->uniqueValue()) |
|
| 159 | ->then() |
|
| 160 | ->variable($repository->get($unique->id())) |
|
| 161 | ->isNull() |
|
| 162 | ->and() |
|
| 163 | ->when($repository->persist($unique)) |
|
| 164 | ->then() |
|
| 165 | ->object($repository->get($unique->id())) |
|
| 166 | ->isEqualTo($unique) |
|
| 167 | ; |
|
| 168 | ||
| 169 | $this |
|
| 170 | ->given($repository = $this->randomRepository()) |
|
| 171 | ->given($id = UserId::next()) |
|
| 172 | ->then() |
|
| 173 | ->exception(function () use ($repository, $id) { |
|
| 174 | $repository->persist($id); |
|
| 175 | })->isInstanceOf(\InvalidArgumentException::class) |
|
| 176 | ; |
|
| 177 | ||
| 178 | $this |
|
| 179 | ->given($repository = $this->emptyRepository()) |
|
| 180 | ->and($value = $this->randomValue()) |
|
| 181 | ->and($age = $value->age()) |
|
| 182 | ->when(function () use ($repository, $value, $age) { |
|
| 183 | $repository->persist($value); |
|
| 184 | $value->setAge($age + 1); |
|
| 185 | $repository->persist($value); |
|
| 186 | }) |
|
| 187 | ->then() |
|
| 188 | ->object($other = $repository->get($value->id())) |
|
| 189 | ->integer($other->age()) |
|
| 190 | ->isEqualTo($age + 1) |
|
| 191 | ; |
|
| 192 | } |
|
| 193 | ||
| 194 | /** |
|
| 195 | * Test persistAll. |
|