Download the PHP package marko/testing without Composer
On this page you can find all versions of the php package marko/testing. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download marko/testing
More information about marko/testing
Files in marko/testing
Package testing
Short Description Testing utilities for the Marko framework - fakes, assertions, and Pest integration
License MIT
Informations about the package testing
marko/testing
Testing utilities for Marko---reusable fakes with built-in assertions, and an in-process HTTP test client for feature tests.
Overview
marko/testing provides a set of in-memory fakes that replace real infrastructure dependencies during tests. Instead of mocking interfaces by hand or spinning up real services, you drop in a fake, run your code, and call assertion methods directly on the fake. This removes hundreds of lines of boilerplate and keeps tests focused on behavior.
Installation
Pest Base Test Case
TestCase registers PSR-4 autoloaders for app/* and modules/* before tests run, so module classes resolve without per-project Composer classmap configuration. No container or application boot is performed.
Wire it as the global base in tests/Pest.php:
After that, every Pest test in the project can reference module and app classes directly---no additional Composer path repos or classmaps required.
HTTP Tests
TestClient sends requests through your application in process (real router, middleware and controllers) and boots the application once for many requests:
Cookies persist across requests like a browser's, so session-backed flows work. Assertions on the returned TestResponse throw AssertionFailedException with the status and a body excerpt. See the HTTP tests docs.
Database Tests
With marko/database and a driver installed, TestDatabase boots and migrates your application once per process, and RefreshDatabase wraps each test in a transaction that is rolled back afterwards:
TruncateDatabase empties the entity tables instead, for code that must see committed data. Both refuse to run in production, and TruncateDatabase runs only in a testing environment (testing, test); set APP_ENV=testing. See the database tests docs.
Available Fakes
FakeEventDispatcher, FakeBroadcaster, FakeMailer, FakeQueue, FakeSession, FakeCookieJar, FakeLogger, FakeConfigRepository, FakeAuthenticatable, FakeUserProvider, FakeGuard, FakeHttpClient, FakeEncryptor, FakeClock, FakeSleeper, FakeConfirmationPrompter
Usage
FakeEventDispatcher
FakeMailer
FakeQueue
FakeSession
FakeCookieJar
FakeLogger
FakeConfigRepository
FakeAuthenticatable
FakeUserProvider
FakeGuard
FakeHttpClient
FakeEncryptor
KnownDriversValidator
API Reference
TestCase
setUp(): void— CallsregisterModuleAutoloaders()before each testregisterModuleAutoloaders(): void— Registers PSR-4 autoloaders forapp/*andmodules/*; safe to call multiple times (skips already-registered roots)projectRoot(): string— Walks up the directory tree from cwd to find the nearest ancestor containingvendor/
FakeEventDispatcher
dispatch($event): void— Record a dispatched eventdispatched(string $class): array— Return all dispatched events of a classassertDispatched(string $class): void— Assert an event was dispatchedassertNotDispatched(string $class): void— Assert an event was not dispatchedassertDispatchedCount(string $class, int $count): void— Assert exact dispatch count
FakeMailer
send($message): void— Record a sent messageassertSent(string $class): void— Assert a message was sentassertNothingSent(): void— Assert no messages were sentassertSentCount(string $class, int $count): void— Assert exact sent count
FakeQueue
push($job): void— Record a pushed jobassertPushed(string $class): void— Assert a job was pushedassertNotPushed(string $class): void— Assert a job was not pushedassertPushedCount(string $class, int $count): void— Assert exact pushed countassertNothingPushed(): void— Assert no jobs were pushed
FakeLogger
info(string $message): void,error(),warning(), etc. — Record log entriesassertLogged(string $message): void— Assert a message was loggedassertNothingLogged(): void— Assert nothing was logged
FakeGuard
new FakeGuard(string $name, bool $attemptResult)— Create guard;$attemptResultcontrols whatattempt()returnssetUser(?AuthenticatableInterface $user): void— Set the current authenticated userattempt(array $credentials): bool— Record credentials attempt and return configured resultlogin(AuthenticatableInterface $user): void— Log in a user directlylogout(): void— Clear current user and record logoutassertAuthenticated(): void— Assert a user is currently authenticatedassertGuest(): void— Assert no user is authenticatedassertAttempted(?callable $callback = null): void— Assert attempt() was called, optionally matching credentials via callbackassertNotAttempted(): void— Assert attempt() was never calledassertLoggedOut(): void— Assert logout() was called
FakeHttpClient
stub(string $urlPattern, HttpResponse|HttpException $response): self— Respond to matching URLs (*wildcard)queue(HttpResponse|HttpException ...$responses): self— Sequential responses for unmatched URLspreventStrayRequests(bool $prevent = true): self— Throw on unmatched requests (default on)assertSent(?callable $callback = null): void,assertNotSent(callable $callback): void,assertSentCount(int $expected): void,assertNothingSent(): void
TestClient
TestClient::boot(string $basePath): self,TestClient::forApplication(Application $app): self— Boot once, serve many requestsget(),post(),put(),patch(),delete(),options(),head(),getJson(),postJson(),putJson(),patchJson(),deleteJson(),call()— Send a request, return aTestResponsewithHeaders(),withServerVariables(),withCookie(),withoutCookies(),withFile(),withFiles(),actingAs($user, ?string $guard = null)— Client state for later requestscookies(),cookieJar()— The cookie jar, scoped by path, domain,Secure, expiry andSameSitelike a browserwithoutResetting(ResettableInterface ...$services): static— Services the client must not reset between requests
TestDatabase, RefreshDatabase, TruncateDatabase
TestDatabase::boot(string $basePath, bool $fresh = false): self— Boot and migrate once per process; refuses production, andfresh: trueruns only in a testing environmentapplication(),connection(),transaction(),client(),seedTable(),getTableRowCount(),appliedMigrations()new RefreshDatabase(TestDatabase $database)—begin(),rollback(),runAfterCommitCallbacks()new TruncateDatabase(TestDatabase $database)—truncate(),tables()
TestResponse
assertStatus(),assertOk(),assertCreated(),assertNoContent(),assertNotFound(),assertForbidden(),assertUnauthorized(),assertUnprocessable(),assertRedirect(?string $to = null)assertHeader(),assertHeaderMissing(),assertCookie(),assertCookieMissing(),assertSee(),assertDontSee()assertJson(),assertExactJson(),assertJsonPath(),assertJsonCount(),assertJsonMissingPath()status(),body(),header(),json(),response()
KnownDriversValidator
assertDocsUrlsResolveToValidPattern(string $knownDriversPath): void— Assert every key inknown-drivers.phpfollows themarko/*prefix patternassertSkeletonSuggestContainsAll(string $knownDriversPath, string $skeletonComposerPath): void— Assert the skeleton'ssuggestblock contains every entry fromknown-drivers.phpwith matching descriptions
Pest Expectations
marko/testing ships Pest custom expectations. They register automatically through a Pest plugin (extra.pest.plugins), so Pest.php needs no require. Pest 4 is required for the expectations; the fakes and their assert*() methods work without it.
Documentation
Full usage, API reference, and examples: marko/testing
All versions of testing with dependencies
marko/core Version self.version
marko/cache Version self.version
marko/clock Version self.version
marko/broadcasting Version self.version
marko/config Version self.version
marko/encryption Version self.version
marko/filesystem Version self.version
marko/mail Version self.version
marko/notification Version self.version
marko/queue Version self.version
marko/session Version self.version
marko/log Version self.version
marko/authentication Version self.version
marko/http Version self.version
marko/routing Version self.version
marko/validation Version self.version
psr/clock Version ^1.0
ext-fileinfo Version *