setAppNamespace(); $connection = ConnectionManager::get('test'); $this->getTableLocator()->get('Users', [ 'table' => 'counter_cache_users', 'connection' => $connection, ]); $comments = $this->getTableLocator()->get('Comments', [ 'table' => 'counter_cache_comments', 'connection' => $connection, ]); $comments->belongsTo('Users', [ 'foreignKey' => 'user_id', ]); $comments->addBehavior('CounterCache', [ 'Users' => ['comment_count'], ]); } public function testExecute(): void { $this->exec('counter_cache Comments'); $this->assertExitSuccess(); $this->assertOutputContains('Counter cache updated successfully.'); } public function testExecuteWithOptions(): void { $this->exec('counter_cache Comments --assoc Users --limit 1 --page 1'); $this->assertExitSuccess(); } public function testExecuteFailure(): void { $this->exec('counter_cache Users'); $this->assertExitError(); $this->assertErrorContains('The specified model does not have the CounterCache behavior attached.'); } }