Add flash, service-mock, query-count, messenger-transport and console… - #247
Merged
Merged
Conversation
…-result assertions Close the small set of gaps that today push a Symfony developer toward a separate, non-Codeception package, in two buckets: assertions Symfony ships in its own Test\* traits that the module had not inherited yet, and capabilities absent from both Symfony core and the Codeception module ecosystem. Symfony ports: - assertSessionHasFlashMessage() (SessionAssertionsTrait), a port of Symfony 8.1's BrowserKit assertion of the same name. Given one or more messages it passes if any of them is present in the type's channel, matching Symfony's SessionHasFlashMessage constraint, and reads the flash bag with peek() so it stays non-destructive. Symfony 5.4 has no FlashBagAwareSessionInterface, so the concrete Session class is accepted as well. - runCommand() plus assertCommandIsSuccessful(), assertCommandFailed(), assertCommandIsInvalid() and assertCommandResultEquals() (ConsoleAssertionsTrait), a port of Symfony 8.1's ConsoleCommandAssertionsTrait. runCommand() returns an ExecutionResult exposing the status code together with the separate standard and error output, which runSymfonyConsoleCommand() cannot. It is guarded with class_exists(ExecutionResult::class), and runSymfonyConsoleCommand() remains the pre-8.1 path. Module-native: - mockService() / unmockService() (ServicesAssertionsTrait) swap a container service for a test double on the existing persistent-service rails, so the replacement survives kernel reboots. The double is built with Codeception Stub, PHPUnit or Mockery; the module only supplies the replacement. - seeNumQueriesIsLessThan() / dontSeeDuplicateQueries() (DoctrineAssertionsTrait) guard against N+1 queries by reading the Doctrine db profiler collector, typed through the new DataCollectorName::DB. symfony/doctrine-bridge is added as a dev dependency to type the collector; it spans Symfony 5.4 to 8.1, so every CI row stays green. - grabMessengerTransport(), seeMessengerTransportContains(), seeMessengerQueueCount() and consumeMessengerMessages() (MessengerAssertionsTrait) inspect and process the real message objects on a Symfony in-memory transport, complementing the existing profiler-based dispatch assertions. seeMessengerQueueCount() counts the pending queue (sent minus acknowledged or rejected), and consumeMessengerMessages() handles queued envelopes through the routable message bus in-process, which works with the in-memory transport where messenger:consume does not. They resolve the transport from the Transport\InMemory namespace, so on older versions they report a symfony/messenger >= 6.3 requirement. No new trait, no new config knob, and nothing added to the Symfony facade except the two new services Part entries. Also stop the functional CI job from installing a second copy of the module into the app: it removed codeception/module-symfony with --no-update and then ran `composer install`, which reinstalls from the app's lockfile, so the module source under test and a stale released copy were both autoloaded. Includes the internal-domain deduplication carried on this branch: build the domain set keyed by host regex instead of array_unique() over a growing list, so grabbing the internal domains is O(N) rather than O(N^2).
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.
Closes the small set of gaps that today push a Symfony developer toward a separate, non-Codeception package. Two buckets: assertions Symfony ships in its own
Test\*traits that the module had not inherited yet, and capabilities absent from both Symfony core and the Codeception module ecosystem.Charter inheritance (Symfony ports)
assertSessionHasFlashMessage()(SessionAssertionsTrait) — port of Symfony 8.1's BrowserKit assertion of the same name. When one or more messages are given it passes if any of them is present in the type's channel (matching Symfony'sSessionHasFlashMessageconstraint). The flash bag is read withpeek(), so it is non-destructive and needs no extra dependency or version guard.runCommand()+assertCommandIsSuccessful()/assertCommandFailed()/assertCommandIsInvalid()/assertCommandResultEquals()(ConsoleAssertionsTrait) — port of Symfony 8.1'sConsoleCommandAssertionsTrait.runCommand()returns anExecutionResultexposing the status code together with the separate standard and error output, whichrunSymfonyConsoleCommand()cannot. Guarded withclass_exists(ExecutionResult::class);runSymfonyConsoleCommand()stays the pre-8.1 path, and the unit tests skip below 8.1.Competitive gaps (module-native)
mockService()/unmockService()(ServicesAssertionsTrait) — swap a container service for a test double (mock, stub,MockHttpClient,MockClock, ...) on the existing persistent-service rails, so the replacement survives kernel reboots. The double is built with CodeceptionStub, PHPUnit or Mockery; the module only supplies the replacement.seeNumQueriesIsLessThan()/dontSeeDuplicateQueries()(DoctrineAssertionsTrait) — N+1 guard reading the Doctrinedbprofiler collector (newDataCollectorName::DB, typed throughgrabCollector()).symfony/doctrine-bridgeis added as a dev dependency to type the collector; it spans Symfony 5.4–8.1 so every CI row stays green.grabMessengerTransport()/seeMessengerTransportContains()/seeMessengerQueueCount()/consumeMessengerMessages()(MessengerAssertionsTrait) — inspect and process the real message objects on a Symfony in-memory transport, complementing the existing profiler-based dispatch assertions.seeMessengerQueueCount()counts the pending queue (sent minus acked/rejected).consumeMessengerMessages()handles queued envelopes through the routable message bus in-process (with aReceivedStamp+ConsumedByWorkerStamp), which works with the in-memory transport wheremessenger:consumedoes not. The unit tests skip below 6.3 (modern in-memory transport).Scope discipline
No new trait, no new config knob, and nothing added to the
Symfony.phpfacade except the two newservicesPart entries. Capabilities reachable by composing a sibling Codeception module (module-rest,module-webdriver,module-doctrine,module-datafactory) are deliberately left out.Validation
composer phpstan(level max),composer cs-checkandvendor/bin/phpunit testsall pass, across the Symfony 5.4 / 6.4 / 7.4 / 8.1 CI matrix.A matching functional test is opened separately in
Codeception/symfony-module-tests, perCONTRIBUTING.md.