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 PHPUnit_Framework_TestCase; 14 15/** 16 */ 17class BlacklistTest extends PHPUnit_Framework_TestCase 18{ 19 /** 20 * @var \SebastianBergmann\GlobalState\Blacklist 21 */ 22 private $blacklist; 23 24 protected function setUp() 25 { 26 $this->blacklist = new Blacklist; 27 } 28 29 public function testGlobalVariableThatIsNotBlacklistedIsNotTreatedAsBlacklisted() 30 { 31 $this->assertFalse($this->blacklist->isGlobalVariableBlacklisted('variable')); 32 } 33 34 public function testGlobalVariableCanBeBlacklisted() 35 { 36 $this->blacklist->addGlobalVariable('variable'); 37 38 $this->assertTrue($this->blacklist->isGlobalVariableBlacklisted('variable')); 39 } 40 41 public function testStaticAttributeThatIsNotBlacklistedIsNotTreatedAsBlacklisted() 42 { 43 $this->assertFalse( 44 $this->blacklist->isStaticAttributeBlacklisted( 45 'SebastianBergmann\GlobalState\TestFixture\BlacklistedClass', 46 'attribute' 47 ) 48 ); 49 } 50 51 public function testClassCanBeBlacklisted() 52 { 53 $this->blacklist->addClass('SebastianBergmann\GlobalState\TestFixture\BlacklistedClass'); 54 55 $this->assertTrue( 56 $this->blacklist->isStaticAttributeBlacklisted( 57 'SebastianBergmann\GlobalState\TestFixture\BlacklistedClass', 58 'attribute' 59 ) 60 ); 61 } 62 63 public function testSubclassesCanBeBlacklisted() 64 { 65 $this->blacklist->addSubclassesOf('SebastianBergmann\GlobalState\TestFixture\BlacklistedClass'); 66 67 $this->assertTrue( 68 $this->blacklist->isStaticAttributeBlacklisted( 69 'SebastianBergmann\GlobalState\TestFixture\BlacklistedChildClass', 70 'attribute' 71 ) 72 ); 73 } 74 75 public function testImplementorsCanBeBlacklisted() 76 { 77 $this->blacklist->addImplementorsOf('SebastianBergmann\GlobalState\TestFixture\BlacklistedInterface'); 78 79 $this->assertTrue( 80 $this->blacklist->isStaticAttributeBlacklisted( 81 'SebastianBergmann\GlobalState\TestFixture\BlacklistedImplementor', 82 'attribute' 83 ) 84 ); 85 } 86 87 public function testClassNamePrefixesCanBeBlacklisted() 88 { 89 $this->blacklist->addClassNamePrefix('SebastianBergmann\GlobalState'); 90 91 $this->assertTrue( 92 $this->blacklist->isStaticAttributeBlacklisted( 93 'SebastianBergmann\GlobalState\TestFixture\BlacklistedClass', 94 'attribute' 95 ) 96 ); 97 } 98 99 public function testStaticAttributeCanBeBlacklisted() 100 { 101 $this->blacklist->addStaticAttribute( 102 'SebastianBergmann\GlobalState\TestFixture\BlacklistedClass', 103 'attribute' 104 ); 105 106 $this->assertTrue( 107 $this->blacklist->isStaticAttributeBlacklisted( 108 'SebastianBergmann\GlobalState\TestFixture\BlacklistedClass', 109 'attribute' 110 ) 111 ); 112 } 113} 114