BitmapTest.php 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. <?php
  2. // {{{ License
  3. // This file is part of GNU social - https://www.gnu.org/software/social
  4. //
  5. // GNU social is free software: you can redistribute it and/or modify
  6. // it under the terms of the GNU Affero General Public License as published by
  7. // the Free Software Foundation, either version 3 of the License, or
  8. // (at your option) any later version.
  9. //
  10. // GNU social is distributed in the hope that it will be useful,
  11. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. // GNU Affero General Public License for more details.
  14. //
  15. // You should have received a copy of the GNU Affero General Public License
  16. // along with GNU social. If not, see <http://www.gnu.org/licenses/>.
  17. // }}}
  18. namespace App\Tests\Util;
  19. use App\Util\Exception\ServerException;
  20. use Jchook\AssertThrows\AssertThrows;
  21. use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase;
  22. class FooBitmap extends \App\Util\Bitmap
  23. {
  24. public const FOO = 1;
  25. public const BAR = 2;
  26. public const QUUX = 4;
  27. }
  28. class BarBitmap extends \App\Util\Bitmap
  29. {
  30. public const HYDROGEN = 1;
  31. public const HELIUM = 2;
  32. public const PREFIX = 'BAR_';
  33. }
  34. class QuuxBitmap extends \App\Util\Bitmap
  35. {
  36. public const HELIUM = 2;
  37. }
  38. class BitmapTest extends KernelTestCase
  39. {
  40. use AssertThrows;
  41. public function testObj()
  42. {
  43. $a = FooBitmap::create(FooBitmap::FOO | FooBitmap::BAR);
  44. static::assertTrue($a->foo);
  45. static::assertTrue($a->bar);
  46. static::assertFalse($a->quux);
  47. }
  48. public function testArray()
  49. {
  50. $b = FooBitmap::toArray(FooBitmap::FOO | FooBitmap::QUUX);
  51. static::assertSame(['FOO', 'QUUX'], $b);
  52. }
  53. public function testPrefix()
  54. {
  55. $b = BarBitmap::toArray(BarBitmap::HYDROGEN | BarBitmap::HELIUM);
  56. static::assertSame(['BAR_HYDROGEN', 'BAR_HELIUM'], $b);
  57. }
  58. public function testThrows()
  59. {
  60. static::assertThrows(ServerException::class, fn () => QuuxBitmap::create(1));
  61. }
  62. }