/** * Convert data into jsonpatch query and save it in the data source * @return mixed */ public function persist() { $this->validate(); if (!is_array($this->data)) { $this->data = [$this->data]; } $append = $this instanceof StreamCollectorInterface; $patches = $this->jsonPatch->generateArrayAdd($this->getPath(), $this->data, $append); $this->dataSource->save($this->process, $patches); $this->data = []; }
public function testSave() { $process = Process::build(); $this->datasource->save($process, ['foo' => 'bar']); $this->assertEquals(1, $this->datasource->count()); $profile = $this->datasource->getProcess($process->getId()); $this->assertInstanceOf(\Generator::class, $profile); $profile = json_decode(current(iterator_to_array($profile))); $this->assertInstanceOf(\stdClass::class, $profile); $this->assertObjectHasAttribute('foo', $profile); $this->assertEquals('bar', $profile->foo); }
public function testSave() { $process = Process::build(); $this->datasource->save($process, ['foo' => 'bar']); $this->assertEquals(0, $this->datasource->count()); }