Question: I am attempting to write a test case to ensure a Singleton class cannot be instantiated. The constructor for the Singleton is defined to be private so my test is as follows:

```
$this->expectError();
$test = new TestSingletonClassA();

```

Instead of catching the error and passing the test, I get a 'PHP Fatal error: Call to private Singleton::\_\_construct()'. I've also tried passing a PatternExpectation as a parameter to expectError, but that didn't work either. Do you have any suggestions?

Some background: php5.3, simpletest1.1a

Answer: 
Unit testing frameworks cannot catch such things. But you can with [PHPT](http://qa.php.net/phpt_details.php) and similar regression test frameworks.

You might have to jump through some hoops to hook it into PHPUnit, but there's probably ways to integrate it with the remaining tests. You'll just have to separate assertions and the special case where you expect the fatal error.
i don't think it's possible to do it that way.. fatal errors are not catchable as i've understood it. you could use reflection to get the constructor method, and then make sure it has the access modifier "private".

this is hard to test in most languages. for example java, c# and c++ would not even let you compile this code. so it could never be run at all D: