getMock('Cake\Log\LogInterface'); $mock->expects($this->at(0)) ->method('write') ->with('error', 'Testing'); $mock->expects($this->at(1)) ->method('write') ->with('debug', print_r(array(1, 2), true)); Log::config('trait_test', ['engine' => $mock]); $subject = $this->getObjectForTrait('Cake\Log\LogTrait'); $subject->log('Testing'); $subject->log(array(1, 2), 'debug'); } }