[TESTS] Add tests for the bitmap utility and fix implementation
This commit is contained in:
59
tests/Util/BitmapTest.php
Normal file
59
tests/Util/BitmapTest.php
Normal file
@@ -0,0 +1,59 @@
|
||||
<?php
|
||||
|
||||
// {{{ License
|
||||
// This file is part of GNU social - https://www.gnu.org/software/social
|
||||
//
|
||||
// GNU social is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU Affero General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// GNU social is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU Affero General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU Affero General Public License
|
||||
// along with GNU social. If not, see <http://www.gnu.org/licenses/>.
|
||||
// }}}
|
||||
|
||||
namespace App\Tests\Util;
|
||||
|
||||
use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase;
|
||||
|
||||
class FooBitmap extends \App\Util\Bitmap
|
||||
{
|
||||
public const FOO = 1;
|
||||
public const BAR = 2;
|
||||
public const QUUX = 4;
|
||||
}
|
||||
|
||||
class BarBitmap extends \App\Util\Bitmap
|
||||
{
|
||||
public const HYDROGEN = 1;
|
||||
public const HELIUM = 2;
|
||||
public const PREFIX = 'BAR_';
|
||||
}
|
||||
|
||||
class BitmapTest extends KernelTestCase
|
||||
{
|
||||
public function testObj()
|
||||
{
|
||||
$a = FooBitmap::create(FooBitmap::FOO | FooBitmap::BAR);
|
||||
static::assertTrue($a->foo);
|
||||
static::assertTrue($a->bar);
|
||||
static::assertFalse($a->quux);
|
||||
}
|
||||
|
||||
public function testArray()
|
||||
{
|
||||
$b = FooBitmap::toArray(FooBitmap::FOO | FooBitmap::QUUX);
|
||||
static::assertSame(['FOO', 'QUUX'], $b);
|
||||
}
|
||||
|
||||
public function testPrefix()
|
||||
{
|
||||
$b = BarBitmap::toArray(BarBitmap::HYDROGEN | BarBitmap::HELIUM);
|
||||
static::assertSame(['BAR_HYDROGEN', 'BAR_HELIUM'], $b);
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user