Attribute Assertions

BeBat/Verify has the ability to test the value of object and class properties (or “attributes”), even those that are protected or private. While writing assertions about a subject’s internal state is not generally good practice, there are times when inspecting a protected value may be the simplest way of checking your code. The attribute you wish to check can be tacked on after calling verify(), just like if you were accessing it as a public value.

For example, if you had an object called $user with a first_name property that should be equal to 'Alice', you can assert that with the following code:


A similar assertion about a class’s static properties might look like the following:


If you would rather explicitly identify your attribute/property, you can do so with the attributeNamed() method:


All of BeBat/Verify’s assertions should be compatible with reading object or class attributes. In addition, attributes fully support chaining and assertion modifiers. The only exception is that once your chain contains an attribute, you can no longer add assertions about their containing object. Put another way, always write your assertions about an object first before writing any about its attributes. For example: