RestorerTest.php 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. <?php declare(strict_types=1);
  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. namespace SebastianBergmann\GlobalState;
  11. use PHPUnit\Framework\TestCase;
  12. /**
  13. * @covers \SebastianBergmann\GlobalState\Restorer
  14. *
  15. * @uses \SebastianBergmann\GlobalState\Blacklist
  16. * @uses \SebastianBergmann\GlobalState\Snapshot
  17. */
  18. final class RestorerTest extends TestCase
  19. {
  20. public static function setUpBeforeClass(): void
  21. {
  22. $GLOBALS['varBool'] = false;
  23. $GLOBALS['varNull'] = null;
  24. $_GET['varGet'] = 0;
  25. }
  26. public function testRestorerGlobalVariable(): void
  27. {
  28. $snapshot = new Snapshot(null, true, false, false, false, false, false, false, false, false);
  29. $restorer = new Restorer;
  30. $restorer->restoreGlobalVariables($snapshot);
  31. $this->assertArrayHasKey('varBool', $GLOBALS);
  32. $this->assertEquals(false, $GLOBALS['varBool']);
  33. $this->assertArrayHasKey('varNull', $GLOBALS);
  34. $this->assertEquals(null, $GLOBALS['varNull']);
  35. $this->assertArrayHasKey('varGet', $_GET);
  36. $this->assertEquals(0, $_GET['varGet']);
  37. }
  38. /**
  39. * @backupGlobals enabled
  40. */
  41. public function testIntegrationRestorerGlobalVariables(): void
  42. {
  43. $this->assertArrayHasKey('varBool', $GLOBALS);
  44. $this->assertEquals(false, $GLOBALS['varBool']);
  45. $this->assertArrayHasKey('varNull', $GLOBALS);
  46. $this->assertEquals(null, $GLOBALS['varNull']);
  47. $this->assertArrayHasKey('varGet', $_GET);
  48. $this->assertEquals(0, $_GET['varGet']);
  49. }
  50. /**
  51. * @depends testIntegrationRestorerGlobalVariables
  52. */
  53. public function testIntegrationRestorerGlobalVariables2(): void
  54. {
  55. $this->assertArrayHasKey('varBool', $GLOBALS);
  56. $this->assertEquals(false, $GLOBALS['varBool']);
  57. $this->assertArrayHasKey('varNull', $GLOBALS);
  58. $this->assertEquals(null, $GLOBALS['varNull']);
  59. $this->assertArrayHasKey('varGet', $_GET);
  60. $this->assertEquals(0, $_GET['varGet']);
  61. }
  62. }