No Description

BlacklistTest.php 5.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  1. <?php
  2. /**
  3. * GlobalState
  4. *
  5. * Copyright (c) 2001-2014, Sebastian Bergmann <sebastian@phpunit.de>.
  6. * All rights reserved.
  7. *
  8. * Redistribution and use in source and binary forms, with or without
  9. * modification, are permitted provided that the following conditions
  10. * are met:
  11. *
  12. * * Redistributions of source code must retain the above copyright
  13. * notice, this list of conditions and the following disclaimer.
  14. *
  15. * * Redistributions in binary form must reproduce the above copyright
  16. * notice, this list of conditions and the following disclaimer in
  17. * the documentation and/or other materials provided with the
  18. * distribution.
  19. *
  20. * * Neither the name of Sebastian Bergmann nor the names of his
  21. * contributors may be used to endorse or promote products derived
  22. * from this software without specific prior written permission.
  23. *
  24. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  25. * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  26. * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
  27. * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
  28. * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
  29. * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
  30. * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  31. * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  32. * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  33. * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
  34. * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
  35. * POSSIBILITY OF SUCH DAMAGE.
  36. *
  37. * @author Sebastian Bergmann <sebastian@phpunit.de>
  38. * @copyright 2001-2014 Sebastian Bergmann <sebastian@phpunit.de>
  39. * @license http://www.opensource.org/licenses/BSD-3-Clause The BSD 3-Clause License
  40. * @link http://www.github.com/sebastianbergmann/global-state
  41. */
  42. namespace SebastianBergmann\GlobalState;
  43. use PHPUnit_Framework_TestCase;
  44. /**
  45. * @author Sebastian Bergmann <sebastian@phpunit.de>
  46. * @copyright 2001-2014 Sebastian Bergmann <sebastian@phpunit.de>
  47. * @license http://www.opensource.org/licenses/BSD-3-Clause The BSD 3-Clause License
  48. * @link http://www.github.com/sebastianbergmann/global-state
  49. */
  50. class BlacklistTest extends PHPUnit_Framework_TestCase
  51. {
  52. /**
  53. * @var \SebastianBergmann\GlobalState\Blacklist
  54. */
  55. private $blacklist;
  56. protected function setUp()
  57. {
  58. $this->blacklist = new Blacklist;
  59. }
  60. public function testGlobalVariableThatIsNotBlacklistedIsNotTreatedAsBlacklisted()
  61. {
  62. $this->assertFalse($this->blacklist->isGlobalVariableBlacklisted('variable'));
  63. }
  64. public function testGlobalVariableCanBeBlacklisted()
  65. {
  66. $this->blacklist->addGlobalVariable('variable');
  67. $this->assertTrue($this->blacklist->isGlobalVariableBlacklisted('variable'));
  68. }
  69. public function testStaticAttributeThatIsNotBlacklistedIsNotTreatedAsBlacklisted()
  70. {
  71. $this->assertFalse(
  72. $this->blacklist->isStaticAttributeBlacklisted(
  73. 'SebastianBergmann\GlobalState\TestFixture\BlacklistedClass',
  74. 'attribute'
  75. )
  76. );
  77. }
  78. public function testClassCanBeBlacklisted()
  79. {
  80. $this->blacklist->addClass('SebastianBergmann\GlobalState\TestFixture\BlacklistedClass');
  81. $this->assertTrue(
  82. $this->blacklist->isStaticAttributeBlacklisted(
  83. 'SebastianBergmann\GlobalState\TestFixture\BlacklistedClass',
  84. 'attribute'
  85. )
  86. );
  87. }
  88. public function testSubclassesCanBeBlacklisted()
  89. {
  90. $this->blacklist->addSubclassesOf('SebastianBergmann\GlobalState\TestFixture\BlacklistedClass');
  91. $this->assertTrue(
  92. $this->blacklist->isStaticAttributeBlacklisted(
  93. 'SebastianBergmann\GlobalState\TestFixture\BlacklistedChildClass',
  94. 'attribute'
  95. )
  96. );
  97. }
  98. public function testImplementorsCanBeBlacklisted()
  99. {
  100. $this->blacklist->addImplementorsOf('SebastianBergmann\GlobalState\TestFixture\BlacklistedInterface');
  101. $this->assertTrue(
  102. $this->blacklist->isStaticAttributeBlacklisted(
  103. 'SebastianBergmann\GlobalState\TestFixture\BlacklistedImplementor',
  104. 'attribute'
  105. )
  106. );
  107. }
  108. public function testClassNamePrefixesCanBeBlacklisted()
  109. {
  110. $this->blacklist->addClassNamePrefix('SebastianBergmann\GlobalState');
  111. $this->assertTrue(
  112. $this->blacklist->isStaticAttributeBlacklisted(
  113. 'SebastianBergmann\GlobalState\TestFixture\BlacklistedClass',
  114. 'attribute'
  115. )
  116. );
  117. }
  118. public function testStaticAttributeCanBeBlacklisted()
  119. {
  120. $this->blacklist->addStaticAttribute(
  121. 'SebastianBergmann\GlobalState\TestFixture\BlacklistedClass',
  122. 'attribute'
  123. );
  124. $this->assertTrue(
  125. $this->blacklist->isStaticAttributeBlacklisted(
  126. 'SebastianBergmann\GlobalState\TestFixture\BlacklistedClass',
  127. 'attribute'
  128. )
  129. );
  130. }
  131. }