PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Friday, April 22, 2022

[FIXED] How does one turn off logging during unit testing in CakePHP 2.x?

 April 22, 2022     cakephp, cakephp-2.3     No comments   

Issue

If you are unit testing a model, for instance, and in that model you use CakePHP's CakeLog convenience method (perhaps testing an expected exception, etc):

CakeLog::warning('This is a warning');

Cake will not only output this at the command line during your test, it will also add the error to logs/error.log.

I need to accomplish one of two things:

  1. Turn off logging during unit testing
  2. Mock the CakeLog class or stub Model->log() (inherited from Object->log)

How does a savvy CakePHP developer accomplish one of these two things?

Related: Using DB logging and doing said logging to your test database where such a thing wouldn't bother you...


Solution

At the top of your test, put CakeLog::drop(logger_name); to disable logging on the logger_name stream



Answered By - hd1
Answer Checked By - Clifford M. (PHPFixing Volunteer)
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing