菜谱项目

BlacklistTest.php 3.2KB

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