No Description

BlacklistTest.php 3.2KB

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