示例#1
0
 public function testGetRightPhpName()
 {
     $q = AuthorQuery::create()->joinBook();
     $joins = $q->getJoins();
     $join = $joins['Book'];
     $with = new ModelWith($join);
     $this->assertEquals('Book', $with->getRightPhpName(), 'A ModelWith initialized from a primary join has a right phpName');
     $q = AuthorQuery::create('a')->joinBook();
     $joins = $q->getJoins();
     $join = $joins['Book'];
     $with = new ModelWith($join);
     $this->assertEquals('Book', $with->getRightPhpName(), 'A ModelWith initialized from a primary join with alias has a right phpName');
     $q = AuthorQuery::create()->joinBook('b');
     $joins = $q->getJoins();
     $join = $joins['b'];
     $with = new ModelWith($join);
     $this->assertEquals('b', $with->getRightPhpName(), 'A ModelWith initialized from a primary join with alias uses the alias as right phpName');
     $q = AuthorQuery::create()->join('Author.Book')->join('Book.Publisher');
     $joins = $q->getJoins();
     $join = $joins['Publisher'];
     $with = new ModelWith($join);
     $this->assertEquals('Publisher', $with->getRightPhpName(), 'A ModelWith has a right phpName even when there are previous joins');
     $q = BookSummaryQuery::create()->join('BookSummary.SummarizedBook');
     $joins = $q->getJoins();
     $join = $joins['SummarizedBook'];
     $with = new ModelWith($join);
     $this->assertEquals('SummarizedBook', $with->getRightPhpName(), 'A ModelWith uses the relation name rather than the class phpName when it exists');
     $q = BookSummaryQuery::create()->join('BookSummary.SummarizedBook')->join('SummarizedBook.Author');
     $joins = $q->getJoins();
     $join = $joins['Author'];
     $with = new ModelWith($join);
     $this->assertEquals('Author', $with->getRightPhpName(), 'A ModelWith has a right phpName even when there are previous joins with custom relation names');
 }