SingletonTestCase.php 1.1 KB

1234567891011121314151617181920212223242526272829303132333435
  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 testSingletonInterface() {
  9. $this->assertTrue($this->rclass->implementsInterface('webbasics\Singleton'));
  10. }
  11. function testConstructorPrivateness() {
  12. $rmethod = new ReflectionMethod($this->getClassName(), '__construct');
  13. $this->assertTrue($rmethod->isPrivate());
  14. }
  15. function testInstanceVariable() {
  16. $this->assertTrue($this->rclass->hasProperty('instance'));
  17. $rprop = new ReflectionProperty($this->getClassName(), 'instance');
  18. $this->assertTrue($rprop->isPrivate());
  19. $this->assertTrue($rprop->isStatic());
  20. }
  21. function testGetInstanceMethod() {
  22. $this->assertTrue($this->rclass->hasMethod('getInstance'));
  23. $rmethod = new ReflectionMethod($this->getClassName(), 'getInstance');
  24. $this->assertTrue($rmethod->isPublic());
  25. $this->assertTrue($rmethod->isStatic());
  26. $this->assertEquals(0, $rmethod->getNumberOfParameters());
  27. }
  28. }