当前位置: 首页>>代码示例>>PHP>>正文


PHP Bookstore\Author类代码示例

本文整理汇总了PHP中Propel\Tests\Bookstore\Author的典型用法代码示例。如果您正苦于以下问题:PHP Author类的具体用法?PHP Author怎么用?PHP Author使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了Author类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: testToStringUsesDefaultStringFormat

    public function testToStringUsesDefaultStringFormat()
    {
        $author = new Author();
        $author->setFirstName('John');
        $author->setLastName('Doe');
        $expected = <<<EOF
Id: null
FirstName: John
LastName: Doe
Email: null
Age: null

EOF;
        $this->assertEquals($expected, (string) $author, 'generated __toString() uses default string format and exportTo()');
        $publisher = new Publisher();
        $publisher->setId(345345);
        $publisher->setName('Peguinoo');
        $expected = <<<EOF
<?xml version="1.0" encoding="UTF-8"?>
<data>
  <Id>345345</Id>
  <Name><![CDATA[Peguinoo]]></Name>
</data>

EOF;
        $this->assertEquals($expected, (string) $publisher, 'generated __toString() uses default string format and exportTo()');
    }
开发者ID:rouffj,项目名称:Propel2,代码行数:27,代码来源:AbstractOMBuilderTest.php

示例2: testSerializeObjectWithCollections

 public function testSerializeObjectWithCollections()
 {
     $book1 = new Book();
     $book1->setTitle('Foo5');
     $book1->setISBN('1234');
     $book2 = new Book();
     $book2->setTitle('Foo6');
     $book2->setISBN('1234');
     $author = new Author();
     $author->setFirstName('JAne');
     $author->addBook($book1);
     $author->addBook($book2);
     $author->save();
     $a = clone $author;
     $sa = serialize($a);
     $author->clearAllReferences();
     $this->assertEquals($author, unserialize($sa));
 }
开发者ID:norfil,项目名称:Propel2,代码行数:18,代码来源:BaseObjectSerializeTest.php

示例3: testAddingABook

 public function testAddingABook()
 {
     $author = AuthorQuery::create()->findPk($this->author->getId());
     $c1 = new Book();
     $c1->setTitle("ORM 101");
     $author->addBook($c1);
     $this->assertEquals(3, count($author->getBooks()));
     $this->assertEquals(3, $author->countBooks());
 }
开发者ID:robin850,项目名称:Propel2,代码行数:9,代码来源:PoisonedCacheBugTest.php

示例4: setUp

 protected function setUp()
 {
     parent::setUp();
     $publisher = new Publisher();
     $publisher->setId(1234);
     $publisher->setName('Penguin');
     $author = new Author();
     $author->setId(5678);
     $author->setFirstName('George');
     $author->setLastName('Byron');
     $book = new Book();
     $book->setId(9012);
     $book->setTitle('Don Juan');
     $book->setISBN('0140422161');
     $book->setPrice(12.99);
     $book->setAuthor($author);
     $book->setPublisher($publisher);
     $this->book = $book;
 }
开发者ID:disider,项目名称:Propel2,代码行数:19,代码来源:ActiveRecordConvertTest.php

示例5: testInvalidCharset

 public function testInvalidCharset()
 {
     $this->markTestSkipped('Skipped because of weird behavior on some platforms');
     $db = Propel::getServiceContainer()->getAdapter(BookPeer::DATABASE_NAME);
     if ($db instanceof SqliteAdapter) {
         $this->markTestSkipped();
     }
     $a = new Author();
     $a->setFirstName("Б.");
     $a->setLastName("АКУНИН");
     $a->save();
     $authorNameWindows1251 = iconv("utf-8", "windows-1251", $a->getLastName());
     $a->setLastName($authorNameWindows1251);
     // Different databases seem to handle invalid data differently (no surprise, I guess...)
     if ($db instanceof PgsqlAdapter) {
         try {
             $a->save();
             $this->fail("Expected an exception when saving non-UTF8 data to database.");
         } catch (Exception $x) {
             print $x;
         }
     } else {
         // No exception is thrown by MySQL ... (others need to be tested still)
         $a->save();
         $a->reload();
         $this->assertEquals("", $a->getLastName(), "Expected last_name to be empty (after inserting invalid charset data)");
     }
 }
开发者ID:norfil,项目名称:Propel2,代码行数:28,代码来源:CharacterEncodingTest.php

示例6: testGroupByArray

 public function testGroupByArray()
 {
     $stephenson = new Author();
     $stephenson->setFirstName("Neal");
     $stephenson->setLastName("Stephenson");
     $stephenson->save();
     $byron = new Author();
     $byron->setFirstName("George");
     $byron->setLastName("Byron");
     $byron->save();
     $phoenix = new Book();
     $phoenix->setTitle("Harry Potter and the Order of the Phoenix");
     $phoenix->setISBN("043935806X");
     $phoenix->setAuthor($stephenson);
     $phoenix->save();
     $qs = new Book();
     $qs->setISBN("0380977427");
     $qs->setTitle("Quicksilver");
     $qs->setAuthor($stephenson);
     $qs->save();
     $dj = new Book();
     $dj->setISBN("0140422161");
     $dj->setTitle("Don Juan");
     $dj->setAuthor($stephenson);
     $dj->save();
     $td = new Book();
     $td->setISBN("067972575X");
     $td->setTitle("The Tin Drum");
     $td->setAuthor($byron);
     $td->save();
     $authors = AuthorQuery::create()->leftJoinBook()->select(array('FirstName', 'LastName'))->withColumn('COUNT(Book.Id)', 'nbBooks')->groupBy(array('FirstName', 'LastName'))->orderByLastName()->find();
     $expectedSql = 'SELECT COUNT(book.id) AS nbBooks, author.first_name AS "FirstName", author.last_name AS "LastName" FROM author LEFT JOIN book ON (author.id=book.author_id) GROUP BY author.first_name,author.last_name ORDER BY author.last_name ASC';
     $this->assertEquals($expectedSql, $this->con->getLastExecutedQuery());
     $this->assertEquals(2, count($authors));
     $this->assertEquals('George', $authors[0]['FirstName']);
     $this->assertEquals(1, $authors[0]['nbBooks']);
     $this->assertEquals('Neal', $authors[1]['FirstName']);
     $this->assertEquals(3, $authors[1]['nbBooks']);
 }
开发者ID:SwissalpS,项目名称:Propel2,代码行数:39,代码来源:ModelCriteriaGroupByArrayTest.php

示例7: testFromArray

 public function testFromArray()
 {
     $author = new Author();
     $author->setFirstName('Jane');
     $author->setLastName('Austen');
     $author->save();
     $books = array(array('Title' => 'Mansfield Park', 'ISBN' => 'FA404', 'AuthorId' => $author->getId()), array('Title' => 'Pride And Prejudice', 'ISBN' => 'FA404', 'AuthorId' => $author->getId()));
     $col = new ObjectCollection();
     $col->setModel('Propel\\Tests\\Bookstore\\Book');
     $col->fromArray($books);
     $col->save();
     $nbBooks = PropelQuery::from('Propel\\Tests\\Bookstore\\Book')->count();
     $this->assertEquals(6, $nbBooks);
     $booksByJane = PropelQuery::from('Propel\\Tests\\Bookstore\\Book b')->join('b.Author a')->where('a.LastName = ?', 'Austen')->count();
     $this->assertEquals(2, $booksByJane);
 }
开发者ID:dracony,项目名称:forked-php-orm-benchmark,代码行数:16,代码来源:ObjectCollectionWithFixturesTest.php

示例8: testNestedTransactionForceRollBack

 public function testNestedTransactionForceRollBack()
 {
     $con = Propel::getServiceContainer()->getConnection(BookTableMap::DATABASE_NAME);
     $driver = $con->getAttribute(PDO::ATTR_DRIVER_NAME);
     // main transaction
     $con->beginTransaction();
     $a = new Author();
     $a->setFirstName('Test');
     $a->setLastName('User');
     $a->save($con);
     $authorId = $a->getId();
     // nested transaction
     $con->beginTransaction();
     $a2 = new Author();
     $a2->setFirstName('Test2');
     $a2->setLastName('User2');
     $a2->save($con);
     $authorId2 = $a2->getId();
     // force rollback
     $con->forceRollback();
     $this->assertEquals(0, $con->getNestedTransactionCount(), 'nested transaction is null after nested transaction forced rollback');
     $this->assertFalse($con->isInTransaction(), 'PropelPDO is not in transaction after nested transaction force rollback');
     AuthorTableMap::clearInstancePool();
     $at = AuthorQuery::create()->findPk($authorId);
     $this->assertNull($at, "Rolled back transaction is not persisted in database");
     $at2 = AuthorQuery::create()->findPk($authorId2);
     $this->assertNull($at2, "Forced Rolled back nested transaction is not persisted in database");
 }
开发者ID:disider,项目名称:Propel2,代码行数:28,代码来源:PropelPDOTest.php

示例9: populate

 public static function populate($con = null)
 {
     if ($con === null) {
         $con = Propel::getServiceContainer()->getConnection(BookTableMap::DATABASE_NAME);
     }
     $con->beginTransaction();
     // Add publisher records
     // ---------------------
     $scholastic = new Publisher();
     $scholastic->setName("Scholastic");
     // do not save, will do later to test cascade
     $morrow = new Publisher();
     $morrow->setName("William Morrow");
     $morrow->save($con);
     $morrow_id = $morrow->getId();
     $penguin = new Publisher();
     $penguin->setName("Penguin");
     $penguin->save();
     $penguin_id = $penguin->getId();
     $vintage = new Publisher();
     $vintage->setName("Vintage");
     $vintage->save($con);
     $vintage_id = $vintage->getId();
     $rowling = new Author();
     $rowling->setFirstName("J.K.");
     $rowling->setLastName("Rowling");
     // no save()
     $stephenson = new Author();
     $stephenson->setFirstName("Neal");
     $stephenson->setLastName("Stephenson");
     $stephenson->save($con);
     $stephenson_id = $stephenson->getId();
     $byron = new Author();
     $byron->setFirstName("George");
     $byron->setLastName("Byron");
     $byron->save($con);
     $byron_id = $byron->getId();
     $grass = new Author();
     $grass->setFirstName("Gunter");
     $grass->setLastName("Grass");
     $grass->save($con);
     $grass_id = $grass->getId();
     $phoenix = new Book();
     $phoenix->setTitle("Harry Potter and the Order of the Phoenix");
     $phoenix->setISBN("043935806X");
     $phoenix->setAuthor($rowling);
     $phoenix->setPublisher($scholastic);
     $phoenix->setPrice(10.99);
     $phoenix->save($con);
     $phoenix_id = $phoenix->getId();
     $qs = new Book();
     $qs->setISBN("0380977427");
     $qs->setTitle("Quicksilver");
     $qs->setPrice(11.99);
     $qs->setAuthor($stephenson);
     $qs->setPublisher($morrow);
     $qs->save($con);
     $qs_id = $qs->getId();
     $dj = new Book();
     $dj->setISBN("0140422161");
     $dj->setTitle("Don Juan");
     $dj->setPrice(12.99);
     $dj->setAuthor($byron);
     $dj->setPublisher($penguin);
     $dj->save($con);
     $dj_id = $dj->getId();
     $td = new Book();
     $td->setISBN("067972575X");
     $td->setTitle("The Tin Drum");
     $td->setPrice(13.99);
     $td->setAuthor($grass);
     $td->setPublisher($vintage);
     $td->save($con);
     $td_id = $td->getId();
     $r1 = new Review();
     $r1->setBook($phoenix);
     $r1->setReviewedBy("Washington Post");
     $r1->setRecommended(true);
     $r1->setReviewDate(time());
     $r1->save($con);
     $r1_id = $r1->getId();
     $r2 = new Review();
     $r2->setBook($phoenix);
     $r2->setReviewedBy("New York Times");
     $r2->setRecommended(false);
     $r2->setReviewDate(time());
     $r2->save($con);
     $r2_id = $r2->getId();
     $blob_path = _LOB_SAMPLE_FILE_PATH . '/tin_drum.gif';
     $clob_path = _LOB_SAMPLE_FILE_PATH . '/tin_drum.txt';
     $m1 = new Media();
     $m1->setBook($td);
     $m1->setCoverImage(file_get_contents($blob_path));
     // CLOB is broken in PDO OCI, see http://pecl.php.net/bugs/bug.php?id=7943
     if (get_class(Propel::getServiceContainer()->getAdapter()) != "OracleAdapter") {
         $m1->setExcerpt(file_get_contents($clob_path));
     }
     $m1->save($con);
     // Add book list records
     // ---------------------
//.........这里部分代码省略.........
开发者ID:kalaspuffar,项目名称:php-orm-benchmark,代码行数:101,代码来源:BookstoreDataPopulator.php

示例10: testToArrayDeep

 public function testToArrayDeep()
 {
     $author = new Author();
     $author->setId(5678);
     $author->setFirstName('George');
     $author->setLastName('Byron');
     $book = new Book();
     $book->setId(9012);
     $book->setTitle('Don Juan');
     $book->setISBN('0140422161');
     $book->setPrice(12.99);
     $book->setAuthor($author);
     $coll = new ArrayCollection();
     $coll->setModel('Propel\\Tests\\Bookstore\\Book');
     $coll[] = $book->toArray(TableMap::TYPE_PHPNAME, true, array(), true);
     $expected = array(array('Id' => 9012, 'Title' => 'Don Juan', 'ISBN' => '0140422161', 'Price' => 12.99, 'PublisherId' => null, 'AuthorId' => 5678, 'Author' => array('Id' => 5678, 'FirstName' => 'George', 'LastName' => 'Byron', 'Email' => null, 'Age' => null, 'Books' => array('Book_0' => '*RECURSION*'))));
     $this->assertEquals($expected, $coll->toArray());
 }
开发者ID:badelas,项目名称:thelia,代码行数:18,代码来源:ArrayCollectionTest.php

示例11: testScenarioUsingQuery

 public function testScenarioUsingQuery()
 {
     // Add publisher records
     // ---------------------
     try {
         $scholastic = new Publisher();
         $scholastic->setName("Scholastic");
         // do not save, will do later to test cascade
         $morrow = new Publisher();
         $morrow->setName("William Morrow");
         $morrow->save();
         $morrow_id = $morrow->getId();
         $penguin = new Publisher();
         $penguin->setName("Penguin");
         $penguin->save();
         $penguin_id = $penguin->getId();
         $vintage = new Publisher();
         $vintage->setName("Vintage");
         $vintage->save();
         $vintage_id = $vintage->getId();
         $this->assertTrue(true, 'Save Publisher records');
     } catch (Exception $e) {
         $this->fail('Save publisher records');
     }
     // Add author records
     // ------------------
     try {
         $rowling = new Author();
         $rowling->setFirstName("J.K.");
         $rowling->setLastName("Rowling");
         // do not save, will do later to test cascade
         $stephenson = new Author();
         $stephenson->setFirstName("Neal");
         $stephenson->setLastName("Stephenson");
         $stephenson->save();
         $stephenson_id = $stephenson->getId();
         $byron = new Author();
         $byron->setFirstName("George");
         $byron->setLastName("Byron");
         $byron->save();
         $byron_id = $byron->getId();
         $grass = new Author();
         $grass->setFirstName("Gunter");
         $grass->setLastName("Grass");
         $grass->save();
         $grass_id = $grass->getId();
         $this->assertTrue(true, 'Save Author records');
     } catch (Exception $e) {
         $this->fail('Save Author records');
     }
     // Add book records
     // ----------------
     try {
         $phoenix = new Book();
         $phoenix->setTitle("Harry Potter and the Order of the Phoenix");
         $phoenix->setISBN("043935806X");
         $phoenix->setAuthor($rowling);
         $phoenix->setPublisher($scholastic);
         $phoenix->save();
         $phoenix_id = $phoenix->getId();
         $this->assertFalse($rowling->isNew(), 'saving book also saves related author');
         $this->assertFalse($scholastic->isNew(), 'saving book also saves related publisher');
         $qs = new Book();
         $qs->setISBN("0380977427");
         $qs->setTitle("Quicksilver");
         $qs->setAuthor($stephenson);
         $qs->setPublisher($morrow);
         $qs->save();
         $qs_id = $qs->getId();
         $dj = new Book();
         $dj->setISBN("0140422161");
         $dj->setTitle("Don Juan");
         $dj->setAuthor($byron);
         $dj->setPublisher($penguin);
         $dj->save();
         $dj_id = $qs->getId();
         $td = new Book();
         $td->setISBN("067972575X");
         $td->setTitle("The Tin Drum");
         $td->setAuthor($grass);
         $td->setPublisher($vintage);
         $td->save();
         $td_id = $td->getId();
         $this->assertTrue(true, 'Save Book records');
     } catch (Exception $e) {
         $this->fail('Save Author records');
     }
     // Add review records
     // ------------------
     try {
         $r1 = new Review();
         $r1->setBook($phoenix);
         $r1->setReviewedBy("Washington Post");
         $r1->setRecommended(true);
         $r1->setReviewDate(time());
         $r1->save();
         $r1_id = $r1->getId();
         $r2 = new Review();
         $r2->setBook($phoenix);
         $r2->setReviewedBy("New York Times");
//.........这里部分代码省略.........
开发者ID:norfil,项目名称:Propel2,代码行数:101,代码来源:BookstoreTest.php

示例12: testFindWithLeftJoinWithOneToManyAndNullObject

 public function testFindWithLeftJoinWithOneToManyAndNullObject()
 {
     BookPeer::clearInstancePool();
     AuthorPeer::clearInstancePool();
     ReviewPeer::clearInstancePool();
     $freud = new Author();
     $freud->setFirstName("Sigmund");
     $freud->setLastName("Freud");
     $freud->save($this->con);
     $c = new ModelCriteria('bookstore', 'Propel\\Tests\\Bookstore\\Author');
     $c->setFormatter(ModelCriteria::FORMAT_ARRAY);
     $c->add(AuthorPeer::LAST_NAME, 'Freud');
     $c->leftJoinWith('Propel\\Tests\\Bookstore\\Author.Book');
     $c->leftJoinWith('Book.Review');
     // should not raise a notice
     $authors = $c->find($this->con);
     $this->assertTrue(true);
 }
开发者ID:rouffj,项目名称:Propel2,代码行数:18,代码来源:ArrayFormatterWithTest.php

示例13: testDoValidate_BasicValidatorObj

 public function testDoValidate_BasicValidatorObj()
 {
     $author = new Author();
     $author->setFirstName("Malcolm");
     // last name required, valid email format, age > 0
     $author->setLastName("X");
     $author->setEmail('malcolm@');
     // fail
     $res = $author->validate();
     $this->assertFalse($res, "Expected validation to fail.");
     $failures = $author->getValidationFailures();
     $this->assertEquals(1, count($failures), "Expected 1 column to fail validation.");
     $this->assertEquals(array(AuthorPeer::EMAIL), array_keys($failures), "Expected EMAIL to fail validation.");
     $validator = $failures[AuthorPeer::EMAIL]->getValidator();
     $this->assertTrue($validator instanceof MatchValidator, "Expected validator that failed to be MatchValidator");
 }
开发者ID:norfil,项目名称:Propel2,代码行数:16,代码来源:ValidatorTest.php

示例14: testQueryJoins

 /**
  *
  * @group mysql
  * @group pgsql
  */
 public function testQueryJoins()
 {
     if ($this->runningOnSQLite()) {
         $this->markTestSkipped('SQLite does not support right joins');
     }
     $author = new Author();
     $author->setFirstName('Steve');
     $author->setLastName('Bla');
     $author->save();
     $author2 = new Author();
     $author2->setFirstName('Blumen');
     $author2->setLastName('Hosen');
     $author2->save();
     $book = new Book();
     $book->setTitle('Book 1');
     $book->setISBN('12313');
     $book->save();
     $log = new PolymorphicRelationLog();
     $log->setMessage('author added');
     $log->setAuthor($author);
     $log->save();
     $log = new PolymorphicRelationLog();
     $log->setMessage('author added');
     $log->setAuthor($author2);
     $log->save();
     $log = new PolymorphicRelationLog();
     $log->setMessage('author changed');
     $log->setAuthor($author);
     $log->save();
     $log = new PolymorphicRelationLog();
     $log->setMessage('book added 1');
     $log->setBook($book);
     $log->save();
     $this->assertEquals(4, PolymorphicRelationLogQuery::create()->count());
     $logs = PolymorphicRelationLogQuery::create()->rightJoinAuthor()->with('Author')->orderById()->find();
     $this->assertCount(3, $logs);
     $this->assertEquals($author, $logs[0]->getAuthor());
     $this->assertEquals($author2, $logs[1]->getAuthor());
     $this->assertEquals($author, $logs[2]->getAuthor());
     $this->assertNull($logs[0]->getBook());
     $this->assertNull($logs[1]->getBook());
     $logs = PolymorphicRelationLogQuery::create()->rightJoinBook()->with('Book')->find();
     $this->assertCount(1, $logs);
     $this->assertEquals($book, $logs[0]->getBook());
     $this->assertNull($logs[0]->getAuthor());
     $logs = PolymorphicRelationLogQuery::create()->useAuthorQuery(null, Criteria::RIGHT_JOIN)->filterByFirstName('Steve')->endUse()->with('Author')->find();
     $this->assertCount(2, $logs);
     $logs = PolymorphicRelationLogQuery::create()->useAuthorQuery(null, Criteria::RIGHT_JOIN)->filterByFirstName('Blumen')->endUse()->with('Author')->find();
     $this->assertCount(1, $logs);
     $this->assertEquals(2, PolymorphicRelationLogQuery::create()->filterByTargetId($author->getId())->filterByTargetType('author')->count());
     $this->assertEquals(4, PolymorphicRelationLogQuery::create()->count());
     AuthorTableMap::clearInstancePool();
     $author3 = AuthorQuery::create()->leftJoinPolymorphicRelationLog()->with('PolymorphicRelationLog')->filterById($author->getId())->find()->get(0);
     $this->assertCount(2, $author3->getPolymorphicRelationLogs());
 }
开发者ID:SwissalpS,项目名称:Propel2,代码行数:60,代码来源:BookstoreLoggingTest.php

示例15: testFindOneWithDuplicateRelation

 public function testFindOneWithDuplicateRelation()
 {
     EssayTableMap::doDeleteAll();
     $auth1 = new Author();
     $auth1->setFirstName('John');
     $auth1->setLastName('Doe');
     $auth1->save();
     $auth2 = new Author();
     $auth2->setFirstName('Jack');
     $auth2->setLastName('Sparrow');
     $auth2->save();
     $essay = new Essay();
     $essay->setTitle('Foo');
     $essay->setFirstAuthor($auth1->getId());
     $essay->setSecondAuthor($auth2->getId());
     $essay->save();
     AuthorTableMap::clearInstancePool();
     EssayTableMap::clearInstancePool();
     $c = new ModelCriteria('bookstore', 'Propel\\Tests\\Bookstore\\Essay');
     $c->setFormatter(ModelCriteria::FORMAT_ON_DEMAND);
     $c->join('Propel\\Tests\\Bookstore\\Essay.AuthorRelatedByFirstAuthor');
     $c->with('AuthorRelatedByFirstAuthor');
     $c->where('Propel\\Tests\\Bookstore\\Essay.Title = ?', 'Foo');
     $c->limit(1);
     $con = Propel::getServiceContainer()->getConnection(BookTableMap::DATABASE_NAME);
     $essays = $c->find($con);
     foreach ($essays as $essay) {
         break;
     }
     $count = $con->getQueryCount();
     $this->assertEquals($essay->getTitle(), 'Foo', 'Main object is correctly hydrated');
     $firstAuthor = $essay->getAuthorRelatedByFirstAuthor();
     $this->assertEquals($count, $con->getQueryCount(), 'with() hydrates the related objects to save a query');
     $this->assertEquals($firstAuthor->getFirstName(), 'John', 'Related object is correctly hydrated');
     $secondAuthor = $essay->getAuthorRelatedBySecondAuthor();
     $this->assertEquals($count + 1, $con->getQueryCount(), 'with() does not hydrate objects not in with');
 }
开发者ID:kalaspuffar,项目名称:php-orm-benchmark,代码行数:37,代码来源:OnDemandFormatterWithTest.php


注:本文中的Propel\Tests\Bookstore\Author类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。