Skip to content

Add Doctrine schema and voter assertions - #246

Merged
TavoNiievez merged 1 commit into
Codeception:mainfrom
TavoNiievez:new_asserts
Sep 4, 2026
Merged

Add Doctrine schema and voter assertions#246
TavoNiievez merged 1 commit into
Codeception:mainfrom
TavoNiievez:new_asserts

Conversation

@TavoNiievez

@TavoNiievez TavoNiievez commented Sep 3, 2026

Copy link
Copy Markdown
Member

What

Two assertions that have no equivalent in Symfony's own test traits, nor elsewhere in this module.

seeDoctrineSchemaIsValid()DoctrineAssertionsTrait

In-process equivalent of bin/console doctrine:schema:validate. It fails on an invalid mapping, and on a database schema that has drifted from the metadata, so a forgotten migration surfaces as one clear failure instead of unrelated errors spread over the rest of the suite.

Guarded with class_exists(SchemaValidator::class). The entity manager checked is the one from the module's existing em_service option, so no second way of naming an entity manager is introduced.

seeUserIsGranted() / dontSeeUserIsGranted()SecurityAssertionsTrait

Run the application's voters through Security::isGranted(), with an optional subject:

$I->seeUserIsGranted('POST_EDIT', $post);
$I->dontSeeUserIsGranted('POST_DELETE', $post);

seeUserHasRole() only covers attributes checked without a subject. Custom voters — the part of the authorization layer applications actually write — were reachable only through a full HTTP round trip and a 403 assertion.

Tests

tests/_app gains a UserVoter fixture. It implements VoterInterface instead of extending Voter, whose abstract voteOnAttribute() signature gained a Vote argument in Symfony 8.1 and is therefore not compatible across every supported Symfony version.

Functional coverage against a real Symfony application follows in Codeception/symfony-module-tests.

Scope

An earlier revision of this branch also proposed a new EnvironmentAssertionsTrait and a further set of Doctrine, Security and Session assertions. Those have been dropped:

  • Environment and infrastructure checksseeAppCacheIsWritable, seeAppLogIsWritable, seeProjectStructureIsSane, seeEnvFileIsSynchronized, seeAssetManifestExists, seeDoctrineProxyDirIsWritable, seeSessionSavePathIsWritable, seeDoctrineDatabaseIsUp — describe the machine the application runs on rather than the application. They belong in CI or a healthcheck. If the cache directory is not writable the kernel does not boot; if the database is down every database-touching test already fails.
  • Container-parameter wrappersseeKernelEnvironmentIs, seeDebugModeEnabled, dontSeeDebugModeEnabled, seeKernelCharsetIs, seeBundleIsEnabled, seeFirewallIsConfigured, seeRoleInHierarchy — are one grabParameter() call plus a plain assertion (kernel.environment, kernel.debug, kernel.charset, kernel.bundles, security.firewalls, security.role_hierarchy.roles).
  • seeSymfonyVersion() is a version guard rather than an assertion, and Kernel::VERSION is public.
  • seeAppEnvAndDebugMatchKernel() and seeEnvFileIsSynchronized() passed vacuously when the variables or the example file were absent.
  • seeSecretCanBeResolved() could not pass at all: ContainerBag::get('env(resolve:NAME)') resolves to Container::getParameter(), and env(...) parameter names exist only at compile time, so every call ended in the catch block and failed. resolve: is also the wrong processor for a vault secret, which is read as a plain %env(NAME)%.

Three of the dropped methods called markTestSkipped() from inside an assertion, which would have been the first occurrence in src/: a helper that skips the caller's whole test hides failures rather than reporting them.

CONTRIBUTING.md records the see* / assert* naming convention together with both scope rules, so the same ground does not have to be re-argued on the next assertions PR.

Notes

Based on main after #247.

@ThomasLandauer

Copy link
Copy Markdown
Member

This PR replaces #218

@TavoNiievez
TavoNiievez force-pushed the new_asserts branch 2 times, most recently from f7a3627 to f9c73ec Compare September 4, 2026 01:25
@TavoNiievez TavoNiievez changed the title Add module-specific assertions (Doctrine, Environment, Security, Session) Add Doctrine schema and voter assertions Sep 4, 2026
seeDoctrineSchemaIsValid() is the in-process equivalent of
`bin/console doctrine:schema:validate`. It reports invalid mappings and a
database schema that has drifted from the metadata, so a missing migration
surfaces as one clear failure instead of unrelated errors spread over the
rest of the suite.

seeUserIsGranted() and dontSeeUserIsGranted() run the application's voters
through Security::isGranted(). seeUserHasRole() only covers attributes checked
without a subject, which left custom voters -- the part of the authorization
layer applications actually write -- reachable only through full HTTP round
trips.

The test application gains a UserVoter fixture. It implements VoterInterface
rather than extending Voter, whose abstract voteOnAttribute() signature gained
a Vote argument in Symfony 8.1 and is therefore not compatible across every
supported Symfony version.

CONTRIBUTING.md documents the see*/assert* naming convention and records that
an assertion describes what the application does: checks about the machine it
runs on belong in CI, and container parameters are already reachable through
grabParameter().
TavoNiievez added a commit to TavoNiievez/symfony-module-tests that referenced this pull request Sep 4, 2026
Cover seeDoctrineSchemaIsValid(), seeUserIsGranted() and dontSeeUserIsGranted()
from Codeception/module-symfony#246. They pass once composer.lock points at a
module-symfony revision containing that pull request.

The application gains a UserVoter that grants USER_EDIT only on the account of
the authenticated user, so the new assertions run against a real voter instead
of a plain role check. It implements VoterInterface rather than extending
Voter, whose abstract voteOnAttribute() signature is not the same across the
Symfony versions covered by the branches of this repository.
TavoNiievez added a commit to TavoNiievez/symfony-module-tests that referenced this pull request Sep 4, 2026
Cover seeDoctrineSchemaIsValid(), seeUserIsGranted() and dontSeeUserIsGranted()
from Codeception/module-symfony#246. They pass once composer.lock points at a
module-symfony revision containing that pull request.

The application gains a UserVoter that grants USER_EDIT only on the account of
the authenticated user, so the new assertions run against a real voter instead
of a plain role check. It implements VoterInterface rather than extending
Voter, whose abstract voteOnAttribute() signature is not the same across the
Symfony versions covered by the branches of this repository.
TavoNiievez added a commit to TavoNiievez/symfony-module-tests that referenced this pull request Sep 4, 2026
Cover seeDoctrineSchemaIsValid(), seeUserIsGranted() and dontSeeUserIsGranted()
from Codeception/module-symfony#246. They pass once composer.lock points at a
module-symfony revision containing that pull request.

The application gains a UserVoter that grants USER_EDIT only on the account of
the authenticated user, so the new assertions run against a real voter instead
of a plain role check. It implements VoterInterface rather than extending
Voter, whose abstract voteOnAttribute() signature is not the same across the
Symfony versions covered by the branches of this repository.
TavoNiievez added a commit to TavoNiievez/symfony-module-tests that referenced this pull request Sep 4, 2026
Cover seeDoctrineSchemaIsValid(), seeUserIsGranted() and dontSeeUserIsGranted()
from Codeception/module-symfony#246. They pass once composer.lock points at a
module-symfony revision containing that pull request.

The application gains a UserVoter that grants USER_EDIT only on the account of
the authenticated user, so the new assertions run against a real voter instead
of a plain role check. It implements VoterInterface rather than extending
Voter, whose abstract voteOnAttribute() signature is not the same across the
Symfony versions covered by the branches of this repository.
TavoNiievez added a commit to Codeception/symfony-module-tests that referenced this pull request Sep 4, 2026
Cover seeDoctrineSchemaIsValid(), seeUserIsGranted() and dontSeeUserIsGranted()
from Codeception/module-symfony#246. They pass once composer.lock points at a
module-symfony revision containing that pull request.

The application gains a UserVoter that grants USER_EDIT only on the account of
the authenticated user, so the new assertions run against a real voter instead
of a plain role check. It implements VoterInterface rather than extending
Voter, whose abstract voteOnAttribute() signature is not the same across the
Symfony versions covered by the branches of this repository.
TavoNiievez added a commit to Codeception/symfony-module-tests that referenced this pull request Sep 4, 2026
Cover seeDoctrineSchemaIsValid(), seeUserIsGranted() and dontSeeUserIsGranted()
from Codeception/module-symfony#246. They pass once composer.lock points at a
module-symfony revision containing that pull request.

The application gains a UserVoter that grants USER_EDIT only on the account of
the authenticated user, so the new assertions run against a real voter instead
of a plain role check. It implements VoterInterface rather than extending
Voter, whose abstract voteOnAttribute() signature is not the same across the
Symfony versions covered by the branches of this repository.
TavoNiievez added a commit to Codeception/symfony-module-tests that referenced this pull request Sep 4, 2026
Cover seeDoctrineSchemaIsValid(), seeUserIsGranted() and dontSeeUserIsGranted()
from Codeception/module-symfony#246. They pass once composer.lock points at a
module-symfony revision containing that pull request.

The application gains a UserVoter that grants USER_EDIT only on the account of
the authenticated user, so the new assertions run against a real voter instead
of a plain role check. It implements VoterInterface rather than extending
Voter, whose abstract voteOnAttribute() signature is not the same across the
Symfony versions covered by the branches of this repository.
TavoNiievez added a commit to Codeception/symfony-module-tests that referenced this pull request Sep 4, 2026
Cover seeDoctrineSchemaIsValid(), seeUserIsGranted() and dontSeeUserIsGranted()
from Codeception/module-symfony#246. They pass once composer.lock points at a
module-symfony revision containing that pull request.

The application gains a UserVoter that grants USER_EDIT only on the account of
the authenticated user, so the new assertions run against a real voter instead
of a plain role check. It implements VoterInterface rather than extending
Voter, whose abstract voteOnAttribute() signature is not the same across the
Symfony versions covered by the branches of this repository.
@TavoNiievez
TavoNiievez marked this pull request as ready for review September 4, 2026 02:06
@TavoNiievez
TavoNiievez merged commit b336cca into Codeception:main Sep 4, 2026
7 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants