-
-
Notifications
You must be signed in to change notification settings - Fork 291
Replace file based extension tests with inline ones #180
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
I feel that including code in json is not a good solution. Maybe directly reading the existing xxx.php and use |
I may agree that it looks confusing to have php-alike code in json file. I will play with other options today. In the worst case, are you open to replacing that json file with another approach? (like php files or array?) |
I have previously considered using PHP to replace the current JSON format configuration file, for example Now in the end I decided to use json and completely separate the PHP code for a simple purpose: everything seems to be low coupling, these configuration files are more like metadata that does not change, and the compiled code and parameters are like functions part. If we use PHP as a configuration file, it is inevitable that dynamically executed code will be included in the configuration file. Maybe writing all configuration items directly as classes and deleting the configuration files is a more reasonable choice (just like the solution I originally abandoned). |
Now it is indeed a troublesome question: should the test code of these extensions be part of the logic code or a static configuration? Honestly I have no idea. This is why I planned to put these test files into a separate tests directory. |
I vote for separation of test code from configuration metadata. The tests MUST be PHP (if you're using PHP to run them), the other can be anything (e.g. JSON) Why not simply include a relative path reference in the JSON metadata to any test file? e.g. "bcmath": {
"type": "builtin"
"type": "builtin",
"tests": "./tests/bcmath.php"
}, This is explicit, can easily be resolved from whichever context is executing the build process, and acts as a pointer for any developer looking to see how things are wired up without having to dive into code. |
@simonhamp This seems to be possible and a compromise. Anyway, I think we finally use |
@crazywhalecc the I guess I'm struggling to see how changing to using It feels super brittle to be interpolating PHP from a file (any file, JSON or PHP) into a shell string. |
@simonhamp This is true. But in general, these test codes are theoretically controllable, because they are only in the src directory within the project, and everyone can check their security. What may need to be done is to escape special characters. I also mentioned three options I can think of in issue #124, the first two seem riskier than this one. In addition, I also thought that on Unix platform, it can be executed through pipes:
But this solution also has problems: it is not possible to obtain its own executable path now after packaging Phar and phpmicro executable. |
@crazywhalecc I agree with you, there's minimal concern from a security perspective. I meant 'brittle' in the sense that they could be the source of various gotchas with interpolation depending on how convoluted the test needs to be, something that even escaping may not help with. It still feels like a path resolution issue to me... |
I have convinced myself not to trapped in this Phar path issue, because after using phar and phpmicro sfx, everything related to the path became anxious, whether reading an internal file from inside Phar or outside. I once thought that the ULTIMATE is to manually generate a PHP file containing the test code for each extension, and then call it on demand: |
For me the best for now (till someone finds "better" way) is to inline the test files with trim as suggested by @crazywhalecc, provided an alternative PR: #182 Closing this one as no-go. |
This change simplifies testing of extensions against custom build PHP binaries, also inside the phar!