public function testLoadAggregateWithDocuments() { $user = phpillowUserDocument::createNew(); $user->login = '******'; $group = phpillowGroupDocument::createNew(); $group->name = 'users'; try { $group->userDocs = array($user); $groupID = $group->save(); $this->fail('Expected phpillowValidationException.'); } catch (phpillowValidationException $e) { /* Expected */ } }
$gets = 5000; $views = 2000; // Set up backend connection phpillowConnection::createInstance('10.0.118.171', 5984, 'admin', 'm4!1.d3'); phpillowConnection::setDatabase('test'); $db = phpillowConnection::getInstance(); try { $db->delete('/test'); } catch (Exception $e) { /* Ignore */ } $db->put('/test'); // /* $start = microtime(true); for ($i = 0; $i < $puts; ++$i) { $doc = new phpillowUserDocument(); $doc->login = '******' . $i; $doc->name = 'Kore Nordmann'; $doc->save(); } printf("%d PUTs in %.2fs (%d req/s)\n", $puts, $time = microtime(true) - $start, $puts / $time); // */ $start = microtime(true); for ($i = 0; $i < $gets; ++$i) { $doc = new phpillowUserDocument('user-kore_0'); } printf("%d GETs in %.2fs (%d req/s)\n", $gets, $time = microtime(true) - $start, $gets / $time); $start = microtime(true); $doc = phpillowUserView::user(array('key' => 'kore_0')); printf("First view in %.2fs (%d req/s)\n", $time = microtime(true) - $start, 1 / $time); $start = microtime(true);
public function testDocumentArrayValidatorSpecifiedInvalid() { $validator = new phpillowDocumentArrayValidator('phpillowUserDocument'); $doc1 = phpillowGroupDocument::createNew(); $doc1->name = 'Maintainer'; $doc1->save(); $doc2 = phpillowUserDocument::createNew(); $doc2->login = '******'; $doc2->save(); try { $validator->validate(array($doc1, $doc2)); $this->fail('Expected phpillowValidationException.'); } catch (phpillowValidationException $e) { $this->assertSame('Invalid document type provided.', $e->getText()); } }
public function testDocumentFetchByIdWithCorrectType() { $doc = phpillowUserDocument::createNew(); $doc->login = '******'; $doc->save(); $user = new phpillowUserDocument(); $user->fetchById($doc->_id); $this->assertSame('kore', $user->login); }
public static function createNew($docType = null) { return parent::createNew($docType === null ? __CLASS__ : $docType); }
public function testCheckRequirements() { $doc = phpillowUserDocument::createNew(); $this->assertSame(array('login'), $doc->checkRequirements()); }
public function testManuallySetContentType() { $doc = phpillowUserDocument::createNew(); $doc->login = '******'; $doc->attachFile($file = dirname(__FILE__) . '/data/image_png.png', 'image_png.png', 'image/png'); $doc->save(); $doc = phpillowManager::fetchDocument('user', 'user-kore'); $response = $doc->getFile('image_png.png'); $this->assertSame(file_get_contents($file), $response->data); $this->assertSame('image/png', $response->contentType); }
// 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 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'))); }