public function testLobSetting_WriteMode()
 {
     $blob_path = $this->getLobFile('tin_drum.gif');
     $blob2_path = $this->getLobFile('propel.gif');
     $clob_path = $this->getLobFile('tin_drum.txt');
     $book = BookPeer::doSelectOne(new Criteria());
     $m1 = new Media();
     $m1->setBook($book);
     $m1->setCoverImage(file_get_contents($blob_path));
     $m1->setExcerpt(file_get_contents($clob_path));
     $m1->save();
     MediaPeer::clearInstancePool();
     // make sure we have the latest from the db:
     $m2 = MediaPeer::retrieveByPK($m1->getId());
     // now attempt to assign a temporary stream, opened in 'w' mode, to the db
     $stream = fopen("php://memory", 'w');
     fwrite($stream, file_get_contents($blob2_path));
     $m2->setCoverImage($stream);
     $m2->save();
     fclose($stream);
     $m2->reload();
     $this->assertEquals(md5(file_get_contents($blob2_path)), md5(stream_get_contents($m2->getCoverImage())), "Expected contents to match when setting stream w/ 'w' mode");
     $stream2 = fopen("php://memory", 'w+');
     fwrite($stream2, file_get_contents($blob_path));
     rewind($stream2);
     $this->assertEquals(md5(file_get_contents($blob_path)), md5(stream_get_contents($stream2)), "Expecting setup to be correct");
     $m2->setCoverImage($stream2);
     $m2->save();
     $m2->reload();
     $this->assertEquals(md5(file_get_contents($blob_path)), md5(stream_get_contents($m2->getCoverImage())), "Expected contents to match when setting stream w/ 'w+' mode");
 }
 /**
  * Test that cascading deletes are happening correctly (whether emulated or native).
  */
 public function testDoDelete_Cascade_Simple()
 {
     // The 'media' table will cascade from book deletes
     // 1) Assert the row exists right now
     $medias = MediaPeer::doSelect(new Criteria());
     $this->assertTrue(count($medias) > 0, "Expected to find at least one row in 'media' table.");
     $media = $medias[0];
     $mediaId = $media->getId();
     // 2) Delete the owning book
     $owningBookId = $media->getBookId();
     BookPeer::doDelete($owningBookId);
     // 3) Assert that the media row is now also gone
     $obj = MediaPeer::retrieveByPK($mediaId);
     $this->assertNull($obj, "Expect NULL when retrieving on no matching Media.");
 }