Ignoring the PHP warnings in PHPUnit

后端 未结 3 1777
刺人心
刺人心 2020-12-18 18:30

Am using PHPUnit for unit testing my functions when ever any warning comes in code the test script will not be executed for that functions, can anyone tell me how to ignore

3条回答
  •  隐瞒了意图╮
    2020-12-18 19:20

    The documentented strategy to do this at a per-test level is to use the @ error suppression operator when your test calls the function that would trigger a warning or notice.

    The following code is the example from the PHPUnit documentation:

    assertFalse(@$writer->write('/is-not-writeable/file', 'stuff'));
        }
    }
    class FileWriter
    {
        public function write($file, $content) {
            $file = fopen($file, 'w');
            if($file == false) {
                return false;
            }
            // ...
        }
    }
    

提交回复
热议问题