SnapshotTest.php 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. <?php
  2. /*
  3. * This file is part of the GlobalState package.
  4. *
  5. * (c) Sebastian Bergmann <sebastian@phpunit.de>
  6. *
  7. * For the full copyright and license information, please view the LICENSE
  8. * file that was distributed with this source code.
  9. */
  10. namespace SebastianBergmann\GlobalState;
  11. use ArrayObject;
  12. use PHPUnit_Framework_TestCase;
  13. use SebastianBergmann\GlobalState\TestFixture\SnapshotClass;
  14. /**
  15. */
  16. class SnapshotTest extends PHPUnit_Framework_TestCase
  17. {
  18. public function testStaticAttributes()
  19. {
  20. $blacklist = $this->getBlacklist();
  21. $blacklist->method('isStaticAttributeBlacklisted')->willReturnCallback(function ($class) {
  22. return $class !== 'SebastianBergmann\GlobalState\TestFixture\SnapshotClass';
  23. });
  24. SnapshotClass::init();
  25. $snapshot = new Snapshot($blacklist, false, true, false, false, false, false, false, false, false);
  26. $expected = array('SebastianBergmann\GlobalState\TestFixture\SnapshotClass' => array(
  27. 'string' => 'snapshot',
  28. 'arrayObject' => new ArrayObject(array(1, 2, 3)),
  29. 'stdClass' => new \stdClass(),
  30. ));
  31. $this->assertEquals($expected, $snapshot->staticAttributes());
  32. }
  33. public function testConstants()
  34. {
  35. $snapshot = new Snapshot($this->getBlacklist(), false, false, true, false, false, false, false, false, false);
  36. $this->assertArrayHasKey('GLOBALSTATE_TESTSUITE', $snapshot->constants());
  37. }
  38. public function testFunctions()
  39. {
  40. require_once __DIR__.'/_fixture/SnapshotFunctions.php';
  41. $snapshot = new Snapshot($this->getBlacklist(), false, false, false, true, false, false, false, false, false);
  42. $functions = $snapshot->functions();
  43. $this->assertThat(
  44. $functions,
  45. $this->logicalOr(
  46. // Zend
  47. $this->contains('sebastianbergmann\globalstate\testfixture\snapshotfunction'),
  48. // HHVM
  49. $this->contains('SebastianBergmann\GlobalState\TestFixture\snapshotFunction')
  50. )
  51. );
  52. $this->assertNotContains('assert', $functions);
  53. }
  54. public function testClasses()
  55. {
  56. $snapshot = new Snapshot($this->getBlacklist(), false, false, false, false, true, false, false, false, false);
  57. $classes = $snapshot->classes();
  58. $this->assertContains('PHPUnit_Framework_TestCase', $classes);
  59. $this->assertNotContains('Exception', $classes);
  60. }
  61. public function testInterfaces()
  62. {
  63. $snapshot = new Snapshot($this->getBlacklist(), false, false, false, false, false, true, false, false, false);
  64. $interfaces = $snapshot->interfaces();
  65. $this->assertContains('PHPUnit_Framework_Test', $interfaces);
  66. $this->assertNotContains('Countable', $interfaces);
  67. }
  68. /**
  69. * @requires PHP 5.4
  70. */
  71. public function testTraits()
  72. {
  73. spl_autoload_call('SebastianBergmann\GlobalState\TestFixture\SnapshotTrait');
  74. $snapshot = new Snapshot($this->getBlacklist(), false, false, false, false, false, false, true, false, false);
  75. $this->assertContains('SebastianBergmann\GlobalState\TestFixture\SnapshotTrait', $snapshot->traits());
  76. }
  77. public function testIniSettings()
  78. {
  79. $snapshot = new Snapshot($this->getBlacklist(), false, false, false, false, false, false, false, true, false);
  80. $iniSettings = $snapshot->iniSettings();
  81. $this->assertArrayHasKey('date.timezone', $iniSettings);
  82. $this->assertEquals('Etc/UTC', $iniSettings['date.timezone']);
  83. }
  84. public function testIncludedFiles()
  85. {
  86. $snapshot = new Snapshot($this->getBlacklist(), false, false, false, false, false, false, false, false, true);
  87. $this->assertContains(__FILE__, $snapshot->includedFiles());
  88. }
  89. /**
  90. * @return \SebastianBergmann\GlobalState\Blacklist
  91. */
  92. private function getBlacklist()
  93. {
  94. return $this->getMockBuilder('SebastianBergmann\GlobalState\Blacklist')
  95. ->disableOriginalConstructor()
  96. ->getMock();
  97. }
  98. }