BitmapTest.php 2.0 KB

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