Add Doctrine schema and voter assertions - #246
Merged
Merged
Conversation
Member
|
This PR replaces #218 |
TavoNiievez
force-pushed
the
new_asserts
branch
2 times, most recently
from
September 4, 2026 01:25
f7a3627 to
f9c73ec
Compare
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
force-pushed
the
new_asserts
branch
from
September 4, 2026 01:38
f9c73ec to
d83f581
Compare
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.
This was referenced Sep 4, 2026
Merged
Merged
Merged
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
marked this pull request as ready for review
September 4, 2026 02:06
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
Two assertions that have no equivalent in Symfony's own test traits, nor elsewhere in this module.
seeDoctrineSchemaIsValid()—DoctrineAssertionsTraitIn-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 existingem_serviceoption, so no second way of naming an entity manager is introduced.seeUserIsGranted()/dontSeeUserIsGranted()—SecurityAssertionsTraitRun the application's voters through
Security::isGranted(), with an optional subject: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/_appgains aUserVoterfixture. It implementsVoterInterfaceinstead of extendingVoter, whose abstractvoteOnAttribute()signature gained aVoteargument 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
EnvironmentAssertionsTraitand a further set of Doctrine, Security and Session assertions. Those have been dropped:seeAppCacheIsWritable,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.seeKernelEnvironmentIs,seeDebugModeEnabled,dontSeeDebugModeEnabled,seeKernelCharsetIs,seeBundleIsEnabled,seeFirewallIsConfigured,seeRoleInHierarchy— are onegrabParameter()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, andKernel::VERSIONis public.seeAppEnvAndDebugMatchKernel()andseeEnvFileIsSynchronized()passed vacuously when the variables or the example file were absent.seeSecretCanBeResolved()could not pass at all:ContainerBag::get('env(resolve:NAME)')resolves toContainer::getParameter(), andenv(...)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 insrc/: a helper that skips the caller's whole test hides failures rather than reporting them.CONTRIBUTING.mdrecords thesee*/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
mainafter #247.