Exemple #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');
 }
 public function testGetRelatedClass()
 {
     $q = AuthorQuery::create()->joinBook();
     $joins = $q->getJoins();
     $join = $joins['Book'];
     $with = new ModelWith($join);
     $this->assertNull($with->getRelatedClass(), 'A ModelWith initialized from a primary join has a null related class');
     $q = AuthorQuery::create('a')->joinBook();
     $joins = $q->getJoins();
     $join = $joins['Book'];
     $with = new ModelWith($join);
     $this->assertNull($with->getRelatedClass(), 'A ModelWith initialized from a primary join with alias has a null related class');
     $q = AuthorQuery::create()->joinBook('b');
     $joins = $q->getJoins();
     $join = $joins['b'];
     $with = new ModelWith($join);
     $this->assertNull($with->getRelatedClass(), 'A ModelWith initialized from a primary join with alias has a null related class');
     $q = AuthorQuery::create()->join('Author.Book')->join('Book.Publisher');
     $joins = $q->getJoins();
     $join = $joins['Publisher'];
     $with = new ModelWith($join);
     $this->assertEquals($with->getRelatedClass(), 'Book', 'A ModelWith uses the previous join relation name as related class');
     $q = ReviewQuery::create()->join('Review.Book')->join('Book.Author')->join('Book.Publisher');
     $joins = $q->getJoins();
     $join = $joins['Publisher'];
     $with = new ModelWith($join);
     $this->assertEquals($with->getRelatedClass(), 'Book', 'A ModelWith uses the previous join relation name as related class');
     $q = ReviewQuery::create()->join('Review.Book')->join('Book.BookOpinion')->join('BookOpinion.BookReader');
     $joins = $q->getJoins();
     $join = $joins['BookOpinion'];
     $with = new ModelWith($join);
     $this->assertEquals($with->getRelatedClass(), 'Book', 'A ModelWith uses the previous join relation name as related class');
     $join = $joins['BookReader'];
     $with = new ModelWith($join);
     $this->assertEquals($with->getRelatedClass(), 'BookOpinion', 'A ModelWith uses the previous join relation name as related class');
     $q = BookReaderQuery::create()->join('BookReader.BookOpinion')->join('BookOpinion.Book')->join('Book.Author');
     $joins = $q->getJoins();
     $join = $joins['Book'];
     $with = new ModelWith($join);
     $this->assertEquals($with->getRelatedClass(), 'BookOpinion', 'A ModelWith uses the previous join relation name as related class');
     $join = $joins['Author'];
     $with = new ModelWith($join);
     $this->assertEquals($with->getRelatedClass(), 'Book', 'A ModelWith uses the previous join relation name as related class');
 }