No Description

SnapshotTest.php 3.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. <?php
  2. /*
  3. * This file is part of sebastian/global-state.
  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. declare(strict_types=1);
  11. namespace SebastianBergmann\GlobalState;
  12. use ArrayObject;
  13. use PHPUnit\Framework\TestCase;
  14. use SebastianBergmann\GlobalState\TestFixture\BlacklistedInterface;
  15. use SebastianBergmann\GlobalState\TestFixture\SnapshotClass;
  16. use SebastianBergmann\GlobalState\TestFixture\SnapshotTrait;
  17. /**
  18. * @covers \SebastianBergmann\GlobalState\Snapshot
  19. */
  20. class SnapshotTest extends TestCase
  21. {
  22. /**
  23. * @var Blacklist
  24. */
  25. private $blacklist;
  26. protected function setUp()
  27. {
  28. $this->blacklist = $this->createMock(Blacklist::class);
  29. }
  30. public function testStaticAttributes()
  31. {
  32. $this->blacklist->method('isStaticAttributeBlacklisted')->willReturnCallback(
  33. function ($class) {
  34. return $class !== SnapshotClass::class;
  35. }
  36. );
  37. SnapshotClass::init();
  38. $snapshot = new Snapshot($this->blacklist, false, true, false, false, false, false, false, false, false);
  39. $expected = [
  40. SnapshotClass::class => [
  41. 'string' => 'snapshot',
  42. 'arrayObject' => new ArrayObject([1, 2, 3]),
  43. 'stdClass' => new \stdClass(),
  44. ]
  45. ];
  46. $this->assertEquals($expected, $snapshot->staticAttributes());
  47. }
  48. public function testConstants()
  49. {
  50. $snapshot = new Snapshot($this->blacklist, false, false, true, false, false, false, false, false, false);
  51. $this->assertArrayHasKey('GLOBALSTATE_TESTSUITE', $snapshot->constants());
  52. }
  53. public function testFunctions()
  54. {
  55. $snapshot = new Snapshot($this->blacklist, false, false, false, true, false, false, false, false, false);
  56. $functions = $snapshot->functions();
  57. $this->assertContains('sebastianbergmann\globalstate\testfixture\snapshotfunction', $functions);
  58. $this->assertNotContains('assert', $functions);
  59. }
  60. public function testClasses()
  61. {
  62. $snapshot = new Snapshot($this->blacklist, false, false, false, false, true, false, false, false, false);
  63. $classes = $snapshot->classes();
  64. $this->assertContains(TestCase::class, $classes);
  65. $this->assertNotContains(Exception::class, $classes);
  66. }
  67. public function testInterfaces()
  68. {
  69. $snapshot = new Snapshot($this->blacklist, false, false, false, false, false, true, false, false, false);
  70. $interfaces = $snapshot->interfaces();
  71. $this->assertContains(BlacklistedInterface::class, $interfaces);
  72. $this->assertNotContains(\Countable::class, $interfaces);
  73. }
  74. public function testTraits()
  75. {
  76. \spl_autoload_call('SebastianBergmann\GlobalState\TestFixture\SnapshotTrait');
  77. $snapshot = new Snapshot($this->blacklist, false, false, false, false, false, false, true, false, false);
  78. $this->assertContains(SnapshotTrait::class, $snapshot->traits());
  79. }
  80. public function testIniSettings()
  81. {
  82. $snapshot = new Snapshot($this->blacklist, false, false, false, false, false, false, false, true, false);
  83. $iniSettings = $snapshot->iniSettings();
  84. $this->assertArrayHasKey('date.timezone', $iniSettings);
  85. $this->assertEquals('Etc/UTC', $iniSettings['date.timezone']);
  86. }
  87. public function testIncludedFiles()
  88. {
  89. $snapshot = new Snapshot($this->blacklist, false, false, false, false, false, false, false, false, true);
  90. $this->assertContains(__FILE__, $snapshot->includedFiles());
  91. }
  92. }