NyTest class
Main testing orchestrator for Nylo testing framework.
Provides PHPUnit/Pest-like testing syntax with automatic setup, teardown, mocking, and test isolation.
Example:
void main() {
NyTest.init();
nyTest('user can login', () async {
NyTest.actingAs(User(id: 1, name: 'Test'));
expectAuthenticated<User>();
});
nyTest('can time travel', () async {
NyTest.travel(DateTime(2025, 1, 1));
expect(NyTime.now().year, 2025);
NyTest.travelBack();
});
}
Constructors
- NyTest()
Properties
- hashCode → int
-
The hash code for this object.
no setterinherited
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
Methods
-
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
toString(
) → String -
A string representation of this object.
inherited
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited
Static Properties
- cache → NyTestCache
-
Get the in-memory cache instance.
no setter
- isInitialized → bool
-
Check if test framework is initialized.
no setter
Static Methods
-
actingAs<
T> (T user, {String? key}) → void - Set an authenticated user for the current test.
-
actingUser<
T> () → T? - Get the currently acting user.
-
assertReturns<
T> (T value, dynamic matcher) → T - Assert and return the result.
-
dd(
) → Never - Dump state and throw an exception (like Laravel's dd()).
-
dump(
) → void - Dump current test state to console.
-
freezeTime(
) → void - Freeze time at the current moment.
-
get<
T> (String key) → T? - Get a value from test state.
-
init(
{bool autoReset = true, bool disableGoogleFonts = true}) → void - Initialize the Nylo testing framework.
-
logout(
) → void - Clear the authenticated user.
-
mockApi<
T> (MockApiHandler handler) → void - Mock an API service type.
-
reset(
) → void - Reset all test state.
-
seedBackpack(
Map< String, dynamic> data) → void - Seed backpack with test data.
-
set(
String key, dynamic value) → void - Store a value in test state.
-
travel(
DateTime date) → void - Travel to a specific point in time.
-
travelBack(
) → void - Reset time to use real system time.
-
travelBackward(
Duration duration) → void - Travel backward in time by a duration.
-
travelForward(
Duration duration) → void - Travel forward in time by a duration.
-
withLocale<
T> (String locale, Future< T> callback()) → Future<T> - Execute code with a temporary locale.