本文整理汇总了PHP中Author::setAge方法的典型用法代码示例。如果您正苦于以下问题:PHP Author::setAge方法的具体用法?PHP Author::setAge怎么用?PHP Author::setAge使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Author
的用法示例。
在下文中一共展示了Author::setAge方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: testScenarioUsingQuery
//.........这里部分代码省略.........
$el = array_shift($failures);
$this->assertContains("must be more than", $el->getMessage(), 'Expected validation message was returned');
$bk2 = new Book();
$bk2->setTitle("Don Juan");
$ret = $bk2->validate();
$this->assertFalse($ret, 'validation failed');
$failures = $bk2->getValidationFailures();
$this->assertEquals(1, count($failures), '1 validation message was returned');
$el = array_shift($failures);
$this->assertContains("Book title already in database.", $el->getMessage(), 'Expected validation message was returned');
//Now trying some more complex validation.
$auth1 = new Author();
$auth1->setFirstName("Hans");
// last name required; will fail
$bk1->setAuthor($auth1);
$rev1 = new Review();
$rev1->setReviewDate("08/09/2001");
// will fail: reviewed_by column required
$bk1->addReview($rev1);
$ret2 = $bk1->validate();
$this->assertFalse($ret2, 'validation failed');
$failures2 = $bk1->getValidationFailures();
$this->assertEquals(3, count($failures2), '3 validation messages were returned');
$expectedKeys = array(AuthorPeer::LAST_NAME, BookPeer::TITLE, ReviewPeer::REVIEWED_BY);
$this->assertEquals($expectedKeys, array_keys($failures2), 'correct columns failed');
$bk2 = new Book();
$bk2->setTitle("12345678901");
// passes
$auth2 = new Author();
$auth2->setLastName("Blah");
//passes
$auth2->setEmail("some@body.com");
//passes
$auth2->setAge(50);
//passes
$bk2->setAuthor($auth2);
$rev2 = new Review();
$rev2->setReviewedBy("Me!");
// passes
$rev2->setStatus("new");
// passes
$bk2->addReview($rev2);
$ret3 = $bk2->validate();
$this->assertTrue($ret3, 'complex validation can pass');
// Testing doCount() functionality
// -------------------------------
// old way
$c = new Criteria();
$records = BookPeer::doSelect($c);
$count = BookPeer::doCount($c);
$this->assertEquals($count, count($records), 'correct number of results');
// new way
$count = BookQuery::create()->count();
$this->assertEquals($count, count($records), 'correct number of results');
// Test many-to-many relationships
// ---------------
// init book club list 1 with 2 books
$blc1 = new BookClubList();
$blc1->setGroupLeader("Crazyleggs");
$blc1->setTheme("Happiness");
$brel1 = new BookListRel();
$brel1->setBook($phoenix);
$brel2 = new BookListRel();
$brel2->setBook($dj);
$blc1->addBookListRel($brel1);
$blc1->addBookListRel($brel2);
示例2: testIsModifiedAndNullValues
public function testIsModifiedAndNullValues()
{
$a = new Author();
$a->setFirstName('');
$a->setLastName('Bar');
$a->setAge(0);
$a->save();
$a->setFirstName(null);
$this->assertTrue($a->isModified(), "Expected Author to be modified after changing empty string column value to NULL.");
$a->setAge(null);
$this->assertTrue($a->isModified(), "Expected Author to be modified after changing 0-value int column to NULL.");
$a->setFirstName('');
$this->assertTrue($a->isModified(), "Expected Author to be modified after changing NULL column value to empty string.");
$a->setAge(0);
$this->assertTrue($a->isModified(), "Expected Author to be modified after changing NULL column to 0-value int.");
}
示例3: boolTest
$bk1->addReview($rev1);
$ret2 = $bk1->validate();
$failures2 = $bk1->getValidationFailures();
print "Making sure 6 validation messages were returned: ";
print boolTest(count($failures2) === 3);
print "Making sure correct columns failed: ";
print boolTest(array_keys($failures2) === array(AuthorPeer::LAST_NAME, BookPeer::TITLE, ReviewPeer::REVIEWED_BY));
$bk2 = new Book();
$bk2->setTitle("12345678901");
// passes
$auth2 = new Author();
$auth2->setLastName("Blah");
//passes
$auth2->setEmail("some@body.com");
//passes
$auth2->setAge(50);
//passes
$bk2->setAuthor($auth2);
$rev2 = new Review();
$rev2->setReviewedBy("Me!");
// passes
$rev2->setStatus("new");
// passes
$bk2->addReview($rev2);
$ret3 = $bk2->validate();
print "Making sure complex validation can pass: ";
print boolTest($ret3 === true);
} catch (Exception $e) {
die("Error doing validation tests: " . $e->__toString());
}
// Test doCount()
示例4: testIsModified
/**
* Test for correct reporting of isModified().
*/
public function testIsModified()
{
// 1) Basic test
$a = new Author();
$a->setFirstName("John");
$a->setLastName("Doe");
$a->setAge(25);
$this->assertTrue($a->isModified(), "Expected Author to be modified after setting values.");
$a->save();
$this->assertFalse($a->isModified(), "Expected Author to be unmodified after saving set values.");
// 2) Test behavior with setting vars of different types
// checking setting int col to string val
$a->setAge('25');
$this->assertFalse($a->isModified(), "Expected Author to be unmodified after setting int column to string-cast of same value.");
$a->setFirstName("John2");
$this->assertTrue($a->isModified(), "Expected Author to be modified after changing string column value.");
// checking setting string col to int val
$a->setFirstName("1");
$a->save();
$this->assertFalse($a->isModified(), "Expected Author to be unmodified after saving set values.");
$a->setFirstName(1);
$this->assertFalse($a->isModified(), "Expected Author to be unmodified after setting string column to int-cast of same value.");
// 3) Test for appropriate behavior of NULL
// checking "" -> NULL
$a->setFirstName("");
$a->save();
$this->assertFalse($a->isModified(), "Expected Author to be unmodified after saving set values.");
$a->setFirstName(null);
$this->assertTrue($a->isModified(), "Expected Author to be modified after changing empty string column value to NULL.");
$a->setFirstName("John");
$a->setAge(0);
$a->save();
$this->assertFalse($a->isModified(), "Expected Author to be unmodified after saving set values.");
$a->setAge(null);
$this->assertTrue($a->isModified(), "Expected Author to be modified after changing 0-value int column to NULL.");
$a->save();
$this->assertFalse($a->isModified(), "Expected Author to be unmodified after saving set values.");
$a->setAge(0);
$this->assertTrue($a->isModified(), "Expected Author to be modified after changing NULL-value int column to 0.");
}
示例5: testDoValidate_Nulls
/**
* Test the fact that validators should not complain NULL values for non-required columns.
*/
public function testDoValidate_Nulls()
{
$author = new Author();
$author->setFirstName("Malcolm");
// last name required, valid email format, age > 0
$author->setLastName("X");
$author->setEmail(null);
// just to be explicit, of course these are the defaults anyway
$author->setAge(null);
$res = $author->validate();
$this->assertTrue($res, "Expected validation to pass with NULL columns");
$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.");
}
示例6: testSpeed
//.........这里部分代码省略.........
$r = ReviewPeer::doSelectOne(new Criteria());
$r_id = $r->getId();
$r->setReviewDate($control);
$r->save();
$r2 = ReviewPeer::retrieveByPk($r_id);
// Testing the column validators
// -----------------------------
$bk1 = new Book();
$bk1->setTitle("12345");
// min length is 10
$ret = $bk1->validate();
// Unique validator
$bk2 = new Book();
$bk2->setTitle("Don Juan");
$ret = $bk2->validate();
// Now trying some more complex validation.
$auth1 = new Author();
$auth1->setFirstName("Hans");
// last name required; will fail
$bk1->setAuthor($auth1);
$rev1 = new Review();
$rev1->setReviewDate("08/09/2001");
// will fail: reviewed_by column required
$bk1->addReview($rev1);
$ret2 = $bk1->validate();
$bk2 = new Book();
$bk2->setTitle("12345678901");
// passes
$auth2 = new Author();
$auth2->setLastName("Blah");
//passes
$auth2->setEmail("some@body.com");
//passes
$auth2->setAge(50);
//passes
$bk2->setAuthor($auth2);
$rev2 = new Review();
$rev2->setReviewedBy("Me!");
// passes
$rev2->setStatus("new");
// passes
$bk2->addReview($rev2);
$ret3 = $bk2->validate();
// Testing doCount() functionality
// -------------------------------
$c = new Criteria();
$count = BookPeer::doCount($c);
// Testing many-to-many relationships
// ----------------------------------
// init book club list 1 with 2 books
$blc1 = new BookClubList();
$blc1->setGroupLeader("Crazyleggs");
$blc1->setTheme("Happiness");
$brel1 = new BookListRel();
$brel1->setBook($phoenix);
$brel2 = new BookListRel();
$brel2->setBook($dj);
$blc1->addBookListRel($brel1);
$blc1->addBookListRel($brel2);
$blc1->save();
// init book club list 2 with 1 book
$blc2 = new BookClubList();
$blc2->setGroupLeader("John Foo");
$blc2->setTheme("Default");
$brel3 = new BookListRel();
$brel3->setBook($phoenix);