SingletonTestCase.php 960 B

12345678910111213141516171819202122232425262728293031
  1. <?php
  2. abstract class SingletonTestCase extends PHPUnit_Framework_TestCase {
  3. private $rclass;
  4. abstract function getClassName();
  5. function setUp() {
  6. $this->rclass = new ReflectionClass($this->getClassName());
  7. }
  8. function testConstructorPrivateness() {
  9. $rmethod = new ReflectionMethod($this->getClassName(), '__construct');
  10. $this->assertTrue($rmethod->isPrivate());
  11. }
  12. function testInstanceVariable() {
  13. $this->assertTrue($this->rclass->hasProperty('instance'));
  14. $rprop = new ReflectionProperty($this->getClassName(), 'instance');
  15. $this->assertTrue($rprop->isPrivate());
  16. $this->assertTrue($rprop->isStatic());
  17. }
  18. function testGetInstanceMethod() {
  19. $this->assertTrue($this->rclass->hasMethod('getInstance'));
  20. $rmethod = new ReflectionMethod($this->getClassName(), 'getInstance');
  21. $this->assertTrue($rmethod->isPublic());
  22. $this->assertTrue($rmethod->isStatic());
  23. $this->assertEquals(0, $rmethod->getNumberOfParameters());
  24. }
  25. }