Exemple #1
0
 public function testIncrement()
 {
     $this->loadFixtures('Topics');
     $this->assertEquals(new Topic(['post_count' => 4]), Topic::select(['post_count'])->where('id', 1)->first());
     Topic::increment(1, ['post_count' => 3]);
     $this->assertEquals(new Topic(['post_count' => 7]), Topic::select(['post_count'])->where('id', 1)->first());
 }
Exemple #2
0
 public function testOnDeleteManyToOne()
 {
     $this->loadFixtures(['Topics', 'Posts']);
     $topic = Topic::find(1);
     $this->assertEquals(4, $topic->post_count);
     // Delete record with active = 0, count shouldn't change
     $post = Post::find(4);
     $post->addBehavior($this->object->track('Topic', 'post_count', function (Query $query) {
         $query->where('active', 1);
     }));
     $post->delete();
     $topic = Topic::find(1);
     $this->assertEquals(4, $topic->post_count);
     // Delete active record, could should change
     $post = Post::find(3);
     $post->addBehavior($this->object->track('Topic', 'post_count', function (Query $query) {
         $query->where('active', 1);
     }));
     $post->delete();
     $topic = Topic::find(1);
     $this->assertEquals(3, $topic->post_count);
     // Delete all records
     $post = new Post();
     $post->addBehavior($this->object->track('Topic', 'post_count', function (Query $query) {
         $query->where('active', 1);
     }));
     $post->query(Query::DELETE)->where('topic_id', 1)->save();
     $topic = Topic::find(1);
     $this->assertEquals(0, $topic->post_count);
 }