// Set up PHPillow autoloading include dirname(__FILE__) . '/../src/bootstrap.php'; // Set up database connection with default parameters phpillowConnection::createInstance(); // Set database, which will be used and get connection handler $db = phpillowConnection::getInstance(); phpillowConnection::setDatabase('test'); // Delete maybe existing database, ignoring the error, if it does not exist // yet. try { $db->delete('/test'); } catch (Exception $e) { /* Ignore */ } // Create new database $db->put('/test'); // Create a new document of the predefined user class $doc = new phpillowUserDocument(); $doc->login = '******'; $doc->name = 'Kore Nordmann'; $docId = $doc->save(); // Fetch the document from the database $doc = new phpillowUserDocument(); $doc->fetchById($docId); // Update the document $doc->email = '*****@*****.**'; $doc->save(); // Fetch the document again and dump the revisions $doc = new phpillowUserDocument(); $doc->fetchById($docId); var_dump($doc->revisions);
public function testDocumentFetchByIdWithCorrectType() { $doc = phpillowUserDocument::createNew(); $doc->login = '******'; $doc->save(); $user = new phpillowUserDocument(); $user->fetchById($doc->_id); $this->assertSame('kore', $user->login); }
public function testLoadDocumentWithAttachment() { $tool = new phpillowTool('http://localhost:5984/test', array('verbose' => false, 'input' => dirname(__FILE__) . '/data/testDumpDocumentWithAttachment.dump')); $tool->setOutputStreams($stdout = fopen('string://', 'w'), $stderr = fopen('string://', 'w')); $this->assertEquals(0, $tool->load()); fseek($stdout, 0); fseek($stderr, 0); $this->assertEquals('', stream_get_contents($stdout)); $this->assertEquals("Loading document user-kore\n", stream_get_contents($stderr)); $user = new phpillowUserDocument(); $user->fetchById('user-kore'); $this->assertEquals('kore', $user->login); $this->assertEquals(base64_encode($user->getFile('image_png.png')->data), base64_encode(file_get_contents(dirname(__FILE__) . '/../phpillow/data/image_png.png'))); }