public function testReplaceRelation() { AggregateCommentQuery::create()->deleteAll($this->con); AggregatePostQuery::create()->deleteAll($this->con); $post1 = new AggregatePost(); $post1->save($this->con); $post2 = new AggregatePost(); $post2->save($this->con); $comment = new AggregateComment(); $comment->setAggregatePost($post1); $comment->save($this->con); $this->assertEquals(1, $post1->getNbComments()); $this->assertNull($post2->getNbComments()); $comment->setAggregatePost($post2); $comment->save($this->con); $this->assertEquals(0, $post1->getNbComments(), 'Replacing a relation changes the related object aggregate column'); $this->assertEquals(1, $post2->getNbComments(), 'Replacing a relation changes the related object aggregate column'); }
public function testQueryCountOnUpdate() { AggregateCommentQuery::create()->deleteAll($this->con); AggregatePostQuery::create()->deleteAll($this->con); $post1 = new TestablePost(); $comment = new AggregateComment(); $comment->setAggregatePost($post1); $comment2 = new AggregateComment(); $comment2->setAggregatePost($post1); $comment3 = new AggregateComment(); $comment3->setAggregatePost($post1); $post1->save($this->con); $this->assertEquals(3, $post1->getNbComments(), 'the post has 3 comments'); $this->assertEquals(2, $post1->countComputeCall, 'Only two call to count nbComment'); $post1->countComputeCall = 0; $comment4 = new AggregateComment(); $comment4->setAggregatePost($post1); $comment4->save($this->con); $this->assertEquals(4, $post1->getNbComments(), 'the post has 4 comments'); $this->assertEquals(2, $post1->countComputeCall, 'Only two call to count nbComment'); $post1->countComputeCall = 0; $comment5 = new AggregateComment(); $comment5->setAggregatePost($post1); $post1->save($this->con); $this->assertEquals(5, $post1->getNbComments(), 'the post has 5 comments'); $this->assertEquals(2, $post1->countComputeCall, 'Only two call to count nbComment'); $post1->countComputeCall = 0; $post1->save($this->con); $this->assertEquals(5, $post1->getNbComments(), 'the post has 5 comments'); $this->assertEquals(1, $post1->countComputeCall, 'Only one call to count nbComment'); }