Пример #1
0
 public function testWithScope()
 {
     $topic = new Topic();
     $topic->addBehavior(new SlugBehavior(['scope' => function (Query $query) {
         $query->where('post_count', '<=', 3);
     }]));
     $topic_id = $topic->create(['title' => 'Batman vs Superman']);
     // Should not increment since other records do not meet scope
     $this->assertEquals(new Entity(['title' => 'Batman vs Superman', 'slug' => 'batman-vs-superman']), $topic->select('title', 'slug')->where('id', $topic_id)->first());
 }
Пример #2
0
 public function testIncrementCallback()
 {
     $this->loadFixtures('Topics');
     $topic = new Topic();
     $this->assertEquals(new EntityCollection([new Entity(['post_count' => 4]), new Entity(['post_count' => 1])]), $topic->select('post_count')->orderBy('id', 'asc')->all());
     $topic->increment(function (Query $query) {
         $query->where('slug', 'like', '%batman%');
     }, ['post_count' => 1]);
     $this->assertEquals(new EntityCollection([new Entity(['post_count' => 5]), new Entity(['post_count' => 1])]), $topic->select('post_count')->orderBy('id', 'asc')->all());
 }