Skip to content

Commit 468edfa

Browse files
authored
Merge pull request #15 from internalsystemerror/test-nested-assoc-value
tests: confirm that (and how) associative array values are handled in updates
2 parents 183ab6c + 354f5a8 commit 468edfa

File tree

3 files changed

+68
-2
lines changed

3 files changed

+68
-2
lines changed

docker-compose.yml

+2-1
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,12 @@ services:
99
- PROOPH_ENV=dev
1010
- PDO_DSN=pgsql:host=postgres port=5432 dbname=event_engine
1111
- PDO_USER=postgres
12-
- PDO_PWD=
12+
- PDO_PWD=test
1313

1414
postgres:
1515
image: postgres:alpine
1616
ports:
1717
- 5432:5432
1818
environment:
1919
- POSTGRES_DB=event_engine
20+
- POSTGRES_PASSWORD=test

phpunit.xml.dist

+1-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
<php>
2323
<env name="DB_HOST" value="postgres"/>
2424
<env name="DB_USERNAME" value="postgres"/>
25-
<env name="DB_PASSWORD" value=""/>
25+
<env name="DB_PASSWORD" value="test"/>
2626
<env name="DB_NAME" value="event_engine"/>
2727
<env name="DB_PORT" value="5432"/>
2828
<env name="DB_CHARSET" value="utf8"/>

tests/PostgresDocumentStoreTest.php

+65
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,71 @@ public function it_adds_collection_with_multi_field_index_unique(): void
150150
);
151151
$this->assertStringStartsWith('CREATE UNIQUE INDEX', $indexes[1]['indexdef']);
152152
}
153+
154+
/**
155+
* @test
156+
*/
157+
public function it_adds_and_updates_a_doc()
158+
{
159+
$collectionName = 'test_adds_and_updates_a_doc';
160+
$this->documentStore->addCollection($collectionName);
161+
162+
$doc = [
163+
'some' => [
164+
'prop' => 'foo',
165+
'other' => [
166+
'nested' => 42
167+
]
168+
],
169+
'baz' => 'bat',
170+
];
171+
172+
$docId = Uuid::uuid4()->toString();
173+
$this->documentStore->addDoc($collectionName, $docId, $doc);
174+
175+
$persistedDoc = $this->documentStore->getDoc($collectionName, $docId);
176+
177+
$this->assertEquals($doc, $persistedDoc);
178+
179+
$doc['baz'] = 'changed val';
180+
181+
$this->documentStore->updateDoc($collectionName, $docId, $doc);
182+
183+
$filter = new EqFilter('baz', 'changed val');
184+
185+
$filteredDocs = $this->documentStore->findDocs($collectionName, $filter);
186+
187+
$this->assertCount(1, $filteredDocs);
188+
}
189+
190+
/**
191+
* @test
192+
*/
193+
public function it_updates_a_subset_of_a_doc()
194+
{
195+
$collectionName = 'test_updates_a_subset_of_a_doc';
196+
$this->documentStore->addCollection($collectionName);
197+
198+
$doc = [
199+
'some' => [
200+
'prop' => 'foo',
201+
'other' => 'bar'
202+
],
203+
'baz' => 'bat',
204+
];
205+
206+
$docId = Uuid::uuid4()->toString();
207+
$this->documentStore->addDoc($collectionName, $docId, $doc);
208+
209+
$this->documentStore->updateDoc($collectionName, $docId, [
210+
'some' => [
211+
'prop' => 'fuzz'
212+
]
213+
]);
214+
215+
$filteredDocs = array_values(iterator_to_array($this->documentStore->findDocs($collectionName, new EqFilter('some.prop', 'fuzz'))));
216+
$this->assertArrayNotHasKey('other', $filteredDocs[0]['some']);
217+
}
153218

154219
/**
155220
* @test

0 commit comments

Comments
 (0)