René's URL Explorer Experiment


Title: Fully automate the module without requiring changes to tests · Issue #23 · Codeception/MockeryModule · GitHub

Open Graph Title: Fully automate the module without requiring changes to tests · Issue #23 · Codeception/MockeryModule

X Title: Fully automate the module without requiring changes to tests · Issue #23 · Codeception/MockeryModule

Description: Currently using this module requires changes in each test. I have found an ugly way to alleviate that problem. The code below was tested for Cest type tests only. It should not break for any other test type but might simply not work. use...

Open Graph Description: Currently using this module requires changes in each test. I have found an ugly way to alleviate that problem. The code below was tested for Cest type tests only. It should not break for any other ...

X Description: Currently using this module requires changes in each test. I have found an ugly way to alleviate that problem. The code below was tested for Cest type tests only. It should not break for any other ...

Opengraph URL: https://github.com/Codeception/MockeryModule/issues/23

X: @github

direct link

Domain: patch-diff.githubusercontent.com


Hey, it has json ld scripts:
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Fully automate the module without requiring changes to tests","articleBody":"Currently using this module requires changes in each test.\r\nI have found an ugly way to alleviate that problem.\r\n\r\nThe code below was tested for `Cest` type tests only. It should not break for any other test type but might simply not work.\r\n\r\n```php\r\n\r\nuse Codeception\\Lib\\Di;\r\nuse Codeception\\Module;\r\nuse Codeception\\TestInterface;\r\n\r\nclass Mockery extends Module\r\n{\r\n\r\n\r\n    public function _before(TestInterface $test)\r\n    {\r\n        $meta = $test-\u003egetMetadata();\r\n        $rc = new \\ReflectionClass($meta);\r\n        $prop = $rc-\u003egetProperty('services');\r\n        $prop-\u003esetAccessible(true);\r\n        $services = $prop-\u003egetValue($meta);\r\n        /** @var Di $di */\r\n        $di = $services['di'];\r\n\r\n        $services['di'] = new class($di, $test) extends Di {\r\n            public function __construct(Di $fallback, private readonly TestInterface $test)\r\n            {\r\n                parent::__construct($fallback);\r\n\r\n            }\r\n\r\n\r\n            public function injectDependencies(object $object, string $injectMethodName = self::DEFAULT_INJECT_METHOD_NAME, array $defaults = []): void\r\n            {\r\n                if ($object === $this-\u003etest) {\r\n                    parent::injectDependencies(...func_get_args());\r\n                    return;\r\n                }\r\n                // We check if the object is our test, if so we close mockery after.\r\n\r\n                codecept_debug(['CALLING',\r\n                    get_class($object),\r\n                    $injectMethodName\r\n                ]);\r\n                try {\r\n                    parent::injectDependencies(...func_get_args());\r\n                    \\Mockery::close();\r\n                } catch (\\Throwable $t) {\r\n                    \\Mockery::resetContainer();\r\n                    throw $t;\r\n                }\r\n                \\Mockery::close();\r\n            }\r\n        };\r\n        $prop-\u003esetValue($meta, $services);\r\n    }\r\n}\r\n```\r\n\r\nEssentially we hijack the `Di` container and replace it with a custom implementation. Based on the fact that for `Cest` files the actual test is ran like this:\r\n```php\r\n$this-\u003egetMetadata()-\u003egetService('di')-\u003einjectDependencies($this-\u003etestInstance, $methodName, $context);\r\n```\r\nWe abuse this to insert a mockery closure after calling the test method.\r\n\r\n\r\nWhile I'm happy to make a PR for this, I'm not sure it should be in an \"official\" repository. I probably don't have time to implement a proper fix where we add an event to allow modules to fail a test before it is finished.\r\n","author":{"url":"https://github.com/SamMousa","@type":"Person","name":"SamMousa"},"datePublished":"2023-11-13T16:01:02.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":0},"url":"https://github.com/23/MockeryModule/issues/23"}

route-pattern/_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format)
route-controllervoltron_issues_fragments
route-actionissue_layout
fetch-noncev2:ff4391b8-5f2e-b1e0-7c81-8a9c16f208f5
current-catalog-service-hash81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114
request-idDC62:16ACDA:35E301:449194:69916010
html-safe-nonce325a19903e4d1dd03e76acba43d8657fa1d0e6d8f5594f8ee6db1bd2b8700802
visitor-payloadeyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJEQzYyOjE2QUNEQTozNUUzMDE6NDQ5MTk0OjY5OTE2MDEwIiwidmlzaXRvcl9pZCI6IjMwNTI0OTgzMTkyMDI5MzQ4MDAiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ==
visitor-hmac8c3adf4abf8db4f0c54e0d25b9e9a525a26f9851c4b4d9b2232e88d76dc043d1
hovercard-subject-tagissue:1990960177
github-keyboard-shortcutsrepository,issues,copilot
google-site-verificationApib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I
octolytics-urlhttps://collector.github.com/github/collect
analytics-location///voltron/issues_fragments/issue_layout
fb:app_id1401488693436528
apple-itunes-appapp-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/Codeception/MockeryModule/23/issue_layout
twitter:imagehttps://opengraph.githubassets.com/62cc78aa49db7b710b1de41cf3c615a98ca1819ed51b19ffa82eaba4a09cc747/Codeception/MockeryModule/issues/23
twitter:cardsummary_large_image
og:imagehttps://opengraph.githubassets.com/62cc78aa49db7b710b1de41cf3c615a98ca1819ed51b19ffa82eaba4a09cc747/Codeception/MockeryModule/issues/23
og:image:altCurrently using this module requires changes in each test. I have found an ugly way to alleviate that problem. The code below was tested for Cest type tests only. It should not break for any other ...
og:image:width1200
og:image:height600
og:site_nameGitHub
og:typeobject
og:author:usernameSamMousa
hostnamegithub.com
expected-hostnamegithub.com
None42c603b9d642c4a9065a51770f75e5e27132fef0e858607f5c9cb7e422831a7b
turbo-cache-controlno-preview
go-importgithub.com/Codeception/MockeryModule git https://github.com/Codeception/MockeryModule.git
octolytics-dimension-user_id1288753
octolytics-dimension-user_loginCodeception
octolytics-dimension-repository_id16224303
octolytics-dimension-repository_nwoCodeception/MockeryModule
octolytics-dimension-repository_publictrue
octolytics-dimension-repository_is_forkfalse
octolytics-dimension-repository_network_root_id16224303
octolytics-dimension-repository_network_root_nwoCodeception/MockeryModule
turbo-body-classeslogged-out env-production page-responsive
disable-turbofalse
browser-stats-urlhttps://api.github.com/_private/browser/stats
browser-errors-urlhttps://api.github.com/_private/browser/errors
release848bc6032dcc93a9a7301dcc3f379a72ba13b96e
ui-targetfull
theme-color#1e2327
color-schemelight dark

Links:

Skip to contenthttps://patch-diff.githubusercontent.com/Codeception/MockeryModule/issues/23#start-of-content
https://patch-diff.githubusercontent.com/
Sign in https://patch-diff.githubusercontent.com/login?return_to=https%3A%2F%2Fgithub.com%2FCodeception%2FMockeryModule%2Fissues%2F23
GitHub CopilotWrite better code with AIhttps://github.com/features/copilot
GitHub SparkBuild and deploy intelligent appshttps://github.com/features/spark
GitHub ModelsManage and compare promptshttps://github.com/features/models
MCP RegistryNewIntegrate external toolshttps://github.com/mcp
ActionsAutomate any workflowhttps://github.com/features/actions
CodespacesInstant dev environmentshttps://github.com/features/codespaces
IssuesPlan and track workhttps://github.com/features/issues
Code ReviewManage code changeshttps://github.com/features/code-review
GitHub Advanced SecurityFind and fix vulnerabilitieshttps://github.com/security/advanced-security
Code securitySecure your code as you buildhttps://github.com/security/advanced-security/code-security
Secret protectionStop leaks before they starthttps://github.com/security/advanced-security/secret-protection
Why GitHubhttps://github.com/why-github
Documentationhttps://docs.github.com
Bloghttps://github.blog
Changeloghttps://github.blog/changelog
Marketplacehttps://github.com/marketplace
View all featureshttps://github.com/features
Enterpriseshttps://github.com/enterprise
Small and medium teamshttps://github.com/team
Startupshttps://github.com/enterprise/startups
Nonprofitshttps://github.com/solutions/industry/nonprofits
App Modernizationhttps://github.com/solutions/use-case/app-modernization
DevSecOpshttps://github.com/solutions/use-case/devsecops
DevOpshttps://github.com/solutions/use-case/devops
CI/CDhttps://github.com/solutions/use-case/ci-cd
View all use caseshttps://github.com/solutions/use-case
Healthcarehttps://github.com/solutions/industry/healthcare
Financial serviceshttps://github.com/solutions/industry/financial-services
Manufacturinghttps://github.com/solutions/industry/manufacturing
Governmenthttps://github.com/solutions/industry/government
View all industrieshttps://github.com/solutions/industry
View all solutionshttps://github.com/solutions
AIhttps://github.com/resources/articles?topic=ai
Software Developmenthttps://github.com/resources/articles?topic=software-development
DevOpshttps://github.com/resources/articles?topic=devops
Securityhttps://github.com/resources/articles?topic=security
View all topicshttps://github.com/resources/articles
Customer storieshttps://github.com/customer-stories
Events & webinarshttps://github.com/resources/events
Ebooks & reportshttps://github.com/resources/whitepapers
Business insightshttps://github.com/solutions/executive-insights
GitHub Skillshttps://skills.github.com
Documentationhttps://docs.github.com
Customer supporthttps://support.github.com
Community forumhttps://github.com/orgs/community/discussions
Trust centerhttps://github.com/trust-center
Partnershttps://github.com/partners
GitHub SponsorsFund open source developershttps://github.com/sponsors
Security Labhttps://securitylab.github.com
Maintainer Communityhttps://maintainers.github.com
Acceleratorhttps://github.com/accelerator
Archive Programhttps://archiveprogram.github.com
Topicshttps://github.com/topics
Trendinghttps://github.com/trending
Collectionshttps://github.com/collections
Enterprise platformAI-powered developer platformhttps://github.com/enterprise
GitHub Advanced SecurityEnterprise-grade security featureshttps://github.com/security/advanced-security
Copilot for BusinessEnterprise-grade AI featureshttps://github.com/features/copilot/copilot-business
Premium SupportEnterprise-grade 24/7 supporthttps://github.com/premium-support
Pricinghttps://github.com/pricing
Search syntax tipshttps://docs.github.com/search-github/github-code-search/understanding-github-code-search-syntax
documentationhttps://docs.github.com/search-github/github-code-search/understanding-github-code-search-syntax
Sign in https://patch-diff.githubusercontent.com/login?return_to=https%3A%2F%2Fgithub.com%2FCodeception%2FMockeryModule%2Fissues%2F23
Sign up https://patch-diff.githubusercontent.com/signup?ref_cta=Sign+up&ref_loc=header+logged+out&ref_page=%2F%3Cuser-name%3E%2F%3Crepo-name%3E%2Fvoltron%2Fissues_fragments%2Fissue_layout&source=header-repo&source_repo=Codeception%2FMockeryModule
Reloadhttps://patch-diff.githubusercontent.com/Codeception/MockeryModule/issues/23
Reloadhttps://patch-diff.githubusercontent.com/Codeception/MockeryModule/issues/23
Reloadhttps://patch-diff.githubusercontent.com/Codeception/MockeryModule/issues/23
Codeception https://patch-diff.githubusercontent.com/Codeception
MockeryModulehttps://patch-diff.githubusercontent.com/Codeception/MockeryModule
Notifications https://patch-diff.githubusercontent.com/login?return_to=%2FCodeception%2FMockeryModule
Fork 12 https://patch-diff.githubusercontent.com/login?return_to=%2FCodeception%2FMockeryModule
Star 34 https://patch-diff.githubusercontent.com/login?return_to=%2FCodeception%2FMockeryModule
Code https://patch-diff.githubusercontent.com/Codeception/MockeryModule
Issues 2 https://patch-diff.githubusercontent.com/Codeception/MockeryModule/issues
Pull requests 0 https://patch-diff.githubusercontent.com/Codeception/MockeryModule/pulls
Actions https://patch-diff.githubusercontent.com/Codeception/MockeryModule/actions
Projects 0 https://patch-diff.githubusercontent.com/Codeception/MockeryModule/projects
Wiki https://patch-diff.githubusercontent.com/Codeception/MockeryModule/wiki
Security 0 https://patch-diff.githubusercontent.com/Codeception/MockeryModule/security
Insights https://patch-diff.githubusercontent.com/Codeception/MockeryModule/pulse
Code https://patch-diff.githubusercontent.com/Codeception/MockeryModule
Issues https://patch-diff.githubusercontent.com/Codeception/MockeryModule/issues
Pull requests https://patch-diff.githubusercontent.com/Codeception/MockeryModule/pulls
Actions https://patch-diff.githubusercontent.com/Codeception/MockeryModule/actions
Projects https://patch-diff.githubusercontent.com/Codeception/MockeryModule/projects
Wiki https://patch-diff.githubusercontent.com/Codeception/MockeryModule/wiki
Security https://patch-diff.githubusercontent.com/Codeception/MockeryModule/security
Insights https://patch-diff.githubusercontent.com/Codeception/MockeryModule/pulse
New issuehttps://patch-diff.githubusercontent.com/login?return_to=https://github.com/Codeception/MockeryModule/issues/23
New issuehttps://patch-diff.githubusercontent.com/login?return_to=https://github.com/Codeception/MockeryModule/issues/23
Fully automate the module without requiring changes to testshttps://patch-diff.githubusercontent.com/Codeception/MockeryModule/issues/23#top
https://github.com/SamMousa
https://github.com/SamMousa
SamMousahttps://github.com/SamMousa
on Nov 13, 2023https://github.com/Codeception/MockeryModule/issues/23#issue-1990960177
https://github.com
Termshttps://docs.github.com/site-policy/github-terms/github-terms-of-service
Privacyhttps://docs.github.com/site-policy/privacy-policies/github-privacy-statement
Securityhttps://github.com/security
Statushttps://www.githubstatus.com/
Communityhttps://github.community/
Docshttps://docs.github.com/
Contacthttps://support.github.com?tags=dotcom-footer

Viewport: width=device-width


URLs of crawlers that visited me.