PHP Classes

File: tests/NumericBitsNamesTest.php

Recommend this page to a friend!
  Packages of Reinder Reinders   PHP Binary Flags   tests/NumericBitsNamesTest.php   Download  
File: tests/NumericBitsNamesTest.php
Role: Example script
Content type: text/plain
Description: Example script
Class: PHP Binary Flags
Manage a group of boolean flags using integers
Author: By
Last change: Binary Flags v3 (#16)

# Release Notes - v3.0.0

## Changed
- Numeric `BinaryFlags` APIs now accept `int` values only.
- Passing `float` values to numeric mask/flag methods now raises `TypeError` for `strict_types=1` callers.
- Non-strict callers should still cast or validate external values before calling the API because PHP scalar coercion can convert `float` to `int` at the call boundary.
- The numeric iterator and JSON serialization contracts are now documented as `int`-based.

## Removed
- `Bits::BIT_64`.
- The v2.x float-normalization/deprecation path in `Traits\InteractsWithNumericFlags`.

## BIT_64 Notice
`Bits::BIT_64` was removed because PHP numbers for bitwise flags are signed. The 64th bit is the sign bit, so it cannot be used reliably as a normal flag.

Using integer-compatible bits avoids these issues.
Date: 4 days ago
Size: 796 bytes
 

Contents

Class file image Download
<?php

declare(strict_types=1);

use
Reinder83\BinaryFlags\Tests\Stubs\ExampleFlags;
use
Reinder83\BinaryFlags\Tests\Stubs\ExampleFlagsWithNames;

beforeEach(function (): void {
   
$this->test = new ExampleFlags(ExampleFlags::FOO | ExampleFlags::BAR);
});

test('flag names', function (): void {
   
expect($this->test->getFlagNames())->toEqual('Foo, Bar')
        ->
and($this->test->getFlagNames(ExampleFlags::BAZ))->toEqual('Baz')
        ->
and($this->test->getFlagNames(null, true))->toEqual([
           
ExampleFlags::FOO => 'Foo',
           
ExampleFlags::BAR => 'Bar',
        ]);
});

test('named flag names', function (): void {
   
$named = new ExampleFlagsWithNames($this->test->getMask());

   
expect($named->getFlagNames())->toEqual('My foo description, My bar description');
});