~earboxer/bare-mess-php

01dc41b32c658f5fc362b5cd0cba56520e863664 — Zach DeCook 3 years ago f4de640
* Primitives: Make Nothing class which is a void
2 files changed, 42 insertions(+), 0 deletions(-)

A src/Nothing.php
M tests/PrimitivesTest.php
A src/Nothing.php => src/Nothing.php +28 -0
@@ 0,0 1,28 @@
<?php

namespace BareMess;

// We can't use "Void" as the name of this class as it's reserved by PHP.
class Nothing
{
    use Mutatable;
    public function __construct(& $mess = null)
    {
        return;
    }

    public function get()
    {
        return null;
    }
    public function set($value)
    {
        // TODO: Throw an error if $value is not null?
        return;
    }

    public function mess()
    {
        return '';
    }
}

M tests/PrimitivesTest.php => tests/PrimitivesTest.php +14 -0
@@ 7,6 7,7 @@ use BareMess\Example\Department;
use BareMess\Example\PublicKey;
use BareMess\{I8,I16,I32,I64};
use BareMess\Integer;
use BareMess\Nothing;
use BareMess\{U8,U16,U32,U64};
use BareMess\UInt;
use PHPUnit\Framework\TestCase;


@@ 196,4 197,17 @@ class PrimitivesTest extends TestCase
        $this->assertEquals(0x7FFFFFFFFFFFFFFF, $u64->get());
        $this->assertEquals("\xFF\xFF\xFF\xFF\xFF\xFF\xFF\x7F", $u64->mess());
    }

    public function testVoid()
    {
        $mess = "abc123";
        $void = new Nothing($mess);
        $this->assertEquals("abc123", $mess);
        $this->assertEquals(null, $void->get());
        $this->assertEquals('', $void->mess());
        $void2 = Nothing::fromValue(null);
        $this->assertEquals(null, $void2->get());
        $void2->set(null);
        $this->assertEquals(null, $void2->get());
    }
}