assert_has() public static method

assert that $haystack has a key or property named $needle. If $haystack is neither, returns false
public static assert_has ( string $needle, array | object $haystack, string $msg = null )
$needle string the key or property to look for
$haystack array | object the array or object to test
$msg string optional description of assertion
Example #1
0
    fu::strict_equal(false, $rs, "callback didn't throw correct exception type");
});
fu::test('FUnit::assert_has tests', function () {
    $arr = array("foo" => true, "bar" => null, "baz" => "bingo");
    $obj = new stdClass();
    $obj->foo = true;
    $obj->bar = null;
    $obj->baz = "bingo";
    fu::strict_equal(true, fu::assert_has('foo', $arr)['result'], "\$arr has key 'foo'");
    fu::strict_equal(true, fu::assert_has('bar', $arr)['result'], "\$arr has key 'bar'");
    fu::strict_equal(true, fu::assert_has('baz', $arr)['result'], "\$arr has key 'baz'");
    fu::strict_equal(false, fu::assert_has('bingo', $arr)['result'], "\$arr does not have key 'bingo'");
    fu::strict_equal(true, fu::assert_has('foo', $obj)['result'], "\$obj has property 'foo'");
    fu::strict_equal(true, fu::assert_has('bar', $obj)['result'], "\$obj has property 'bar'");
    fu::strict_equal(true, fu::assert_has('baz', $obj)['result'], "\$obj has property 'baz'");
    fu::strict_equal(false, fu::assert_has('bingo', $obj)['result'], "\$obj does not have property 'bingo'");
});
fu::test('FUnit::assert_not_has tests', function () {
    $arr = array("foo" => true, "bar" => null, "baz" => "bingo");
    $obj = new stdClass();
    $obj->foo = true;
    $obj->bar = null;
    $obj->baz = "bingo";
    fu::strict_equal(false, fu::assert_not_has('foo', $arr)['result'], "\$arr has key 'foo'");
    fu::strict_equal(false, fu::assert_not_has('bar', $arr)['result'], "\$arr has key 'bar'");
    fu::strict_equal(false, fu::assert_not_has('baz', $arr)['result'], "\$arr has key 'baz'");
    fu::strict_equal(true, fu::assert_not_has('bingo', $arr)['result'], "\$arr does not have key 'bingo'");
    fu::strict_equal(false, fu::assert_not_has('foo', $obj)['result'], "\$obj has property 'foo'");
    fu::strict_equal(false, fu::assert_not_has('bar', $obj)['result'], "\$obj has property 'bar'");
    fu::strict_equal(false, fu::assert_not_has('baz', $obj)['result'], "\$obj has property 'baz'");
    fu::strict_equal(true, fu::assert_not_has('bingo', $obj)['result'], "\$obj does not have property 'bingo'");