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 11namespace SebastianBergmann\GlobalState; 12 13use ArrayObject; 14use PHPUnit_Framework_TestCase; 15use SebastianBergmann\GlobalState\TestFixture\SnapshotClass; 16 17/** 18 */ 19class SnapshotTest extends PHPUnit_Framework_TestCase 20{ 21 public function testStaticAttributes() 22 { 23 $blacklist = $this->getBlacklist(); 24 $blacklist->method('isStaticAttributeBlacklisted')->willReturnCallback(function ($class) { 25 return $class !== 'SebastianBergmann\GlobalState\TestFixture\SnapshotClass'; 26 }); 27 28 SnapshotClass::init(); 29 30 $snapshot = new Snapshot($blacklist, false, true, false, false, false, false, false, false, false); 31 $expected = array('SebastianBergmann\GlobalState\TestFixture\SnapshotClass' => array( 32 'string' => 'snapshot', 33 'arrayObject' => new ArrayObject(array(1, 2, 3)), 34 'stdClass' => new \stdClass(), 35 )); 36 37 $this->assertEquals($expected, $snapshot->staticAttributes()); 38 } 39 40 public function testConstants() 41 { 42 $snapshot = new Snapshot($this->getBlacklist(), false, false, true, false, false, false, false, false, false); 43 $this->assertArrayHasKey('GLOBALSTATE_TESTSUITE', $snapshot->constants()); 44 } 45 46 public function testFunctions() 47 { 48 require_once __DIR__.'/_fixture/SnapshotFunctions.php'; 49 50 $snapshot = new Snapshot($this->getBlacklist(), false, false, false, true, false, false, false, false, false); 51 $functions = $snapshot->functions(); 52 53 $this->assertThat( 54 $functions, 55 $this->logicalOr( 56 // Zend 57 $this->contains('sebastianbergmann\globalstate\testfixture\snapshotfunction'), 58 // HHVM 59 $this->contains('SebastianBergmann\GlobalState\TestFixture\snapshotFunction') 60 ) 61 ); 62 63 $this->assertNotContains('assert', $functions); 64 } 65 66 public function testClasses() 67 { 68 $snapshot = new Snapshot($this->getBlacklist(), false, false, false, false, true, false, false, false, false); 69 $classes = $snapshot->classes(); 70 71 $this->assertContains('PHPUnit_Framework_TestCase', $classes); 72 $this->assertNotContains('Exception', $classes); 73 } 74 75 public function testInterfaces() 76 { 77 $snapshot = new Snapshot($this->getBlacklist(), false, false, false, false, false, true, false, false, false); 78 $interfaces = $snapshot->interfaces(); 79 80 $this->assertContains('PHPUnit_Framework_Test', $interfaces); 81 $this->assertNotContains('Countable', $interfaces); 82 } 83 84 /** 85 * @requires PHP 5.4 86 */ 87 public function testTraits() 88 { 89 spl_autoload_call('SebastianBergmann\GlobalState\TestFixture\SnapshotTrait'); 90 91 $snapshot = new Snapshot($this->getBlacklist(), false, false, false, false, false, false, true, false, false); 92 $this->assertContains('SebastianBergmann\GlobalState\TestFixture\SnapshotTrait', $snapshot->traits()); 93 } 94 95 public function testIniSettings() 96 { 97 $snapshot = new Snapshot($this->getBlacklist(), false, false, false, false, false, false, false, true, false); 98 $iniSettings = $snapshot->iniSettings(); 99 100 $this->assertArrayHasKey('date.timezone', $iniSettings); 101 $this->assertEquals('Etc/UTC', $iniSettings['date.timezone']); 102 } 103 104 public function testIncludedFiles() 105 { 106 $snapshot = new Snapshot($this->getBlacklist(), false, false, false, false, false, false, false, false, true); 107 $this->assertContains(__FILE__, $snapshot->includedFiles()); 108 } 109 110 /** 111 * @return \SebastianBergmann\GlobalState\Blacklist 112 */ 113 private function getBlacklist() 114 { 115 return $this->getMockBuilder('SebastianBergmann\GlobalState\Blacklist') 116 ->disableOriginalConstructor() 117 ->getMock(); 118 } 119} 120