simpletest_test.php 1.7KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. <?php
  2. // $Id: simpletest_test.php 1748 2008-04-14 01:50:41Z lastcraft $
  3. require_once(dirname(__FILE__) . '/../autorun.php');
  4. require_once(dirname(__FILE__) . '/../simpletest.php');
  5. SimpleTest::ignore('ShouldNeverBeRunEither');
  6. class ShouldNeverBeRun extends UnitTestCase {
  7. function testWithNoChanceOfSuccess() {
  8. $this->fail('Should be ignored');
  9. }
  10. }
  11. class ShouldNeverBeRunEither extends ShouldNeverBeRun { }
  12. class TestOfStackTrace extends UnitTestCase {
  13. function testCanFindAssertInTrace() {
  14. $trace = new SimpleStackTrace(array('assert'));
  15. $this->assertEqual(
  16. $trace->traceMethod(array(array(
  17. 'file' => '/my_test.php',
  18. 'line' => 24,
  19. 'function' => 'assertSomething'))),
  20. ' at [/my_test.php line 24]');
  21. }
  22. }
  23. class DummyResource { }
  24. class TestOfContext extends UnitTestCase {
  25. function testCurrentContextIsUnique() {
  26. $this->assertSame(
  27. SimpleTest::getContext(),
  28. SimpleTest::getContext());
  29. }
  30. function testContextHoldsCurrentTestCase() {
  31. $context = SimpleTest::getContext();
  32. $this->assertSame($this, $context->getTest());
  33. }
  34. function testResourceIsSingleInstanceWithContext() {
  35. $context = new SimpleTestContext();
  36. $this->assertSame(
  37. $context->get('DummyResource'),
  38. $context->get('DummyResource'));
  39. }
  40. function testClearingContextResetsResources() {
  41. $context = new SimpleTestContext();
  42. $resource = $context->get('DummyResource');
  43. $context->clear();
  44. $this->assertClone($resource, $context->get('DummyResource'));
  45. }
  46. }
  47. ?>