BlacklistTest.php 3.2 KB

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