|
@@ -331,6 +331,37 @@ class CounterCacheBehaviorTest extends TestCase
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
|
|
|
+ * Testing counter cache with lambda returning false
|
|
|
|
|
+ *
|
|
|
|
|
+ * @return void
|
|
|
|
|
+ */
|
|
|
|
|
+ public function testLambdaFalse()
|
|
|
|
|
+ {
|
|
|
|
|
+ $this->post->belongsTo('Users');
|
|
|
|
|
+
|
|
|
|
|
+ $table = $this->post;
|
|
|
|
|
+ $entity = $this->_getEntity();
|
|
|
|
|
+
|
|
|
|
|
+ $this->post->addBehavior('CounterCache', [
|
|
|
|
|
+ 'Users' => [
|
|
|
|
|
+ 'posts_published' => function (Event $orgEvent, EntityInterface $orgEntity, Table $orgTable) use ($entity, $table) {
|
|
|
|
|
+ $this->assertSame($orgTable, $table);
|
|
|
|
|
+ $this->assertSame($orgEntity, $entity);
|
|
|
|
|
+
|
|
|
|
|
+ return false;
|
|
|
|
|
+ }
|
|
|
|
|
+ ]
|
|
|
|
|
+ ]);
|
|
|
|
|
+
|
|
|
|
|
+ $before = $this->_getUser();
|
|
|
|
|
+ $this->post->save($entity);
|
|
|
|
|
+ $after = $this->_getUser();
|
|
|
|
|
+
|
|
|
|
|
+ $this->assertEquals(1, $before->get('posts_published'));
|
|
|
|
|
+ $this->assertEquals(1, $after->get('posts_published'));
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
* Testing counter cache with lambda returning number and changing of related ID
|
|
* Testing counter cache with lambda returning number and changing of related ID
|
|
|
*
|
|
*
|
|
|
* @return void
|
|
* @return void
|