Closed bitwombat closed 6 years ago
@bitwombat Thanks for sharing this use case. I believe this falls under a known issue. The current implementation can only match one definition per line.
https://github.com/wp-cli/wp-config-transformer/blob/master/README.md#known-issues
But there is only one definition per line...
I think you're confusing my original wp-config.php input, which has one definition per line, with the $config string that parse_wp_config makes. See above.
@bitwombat ah that makes sense. What version of WP-CLI are you using? I just tried to reproduce locally with 2.0.1 and couldn't.
I'm using 2.0.1
Try with my original text up there verbatim. The trailing // is what causes the space.
Then:
$ wp config set DB_NAME fjarrett
Success: Updated the constant 'DB_NAME' in the 'wp-config.php' file with the value 'fjarrett'.
$ cat wp-config.php
<?php
define('WP_CACHE', true); //
define('DB_NAME', 'wtngcoma_wtng');
I can write a test and attempt to fix it, but I'm not sure where to put the test.
Take a look at https://github.com/wp-cli/wp-config-transformer/tree/master/tests for prior art on how to structure your tests. If you could write a failing test case for this in a pull request, it would be a great way to document the bug.
So, it looks like I should be adding to 2-UpdateTest.php
And the way it works is that there's an empty file created that then gets variables and constants added to it by the tests.
The values are from raw-data.txt
and string-data.txt
.
testRawConstants
, testStringConstants
, testRawVariables
, and testStringVariables
(four combinations) are all looping through raw data or string data and adding variables or constants to the test file.
The remaining tests are testing random behaviours.
Finally testConfigValues
reads the created test file in and verifies all the raw data and string data test values, and the misc test's results.
All this means that all tests in 2-UpdateTest
are dependent on each other, so all must be run at once.
Ah bloody @#(! @fjarrett's commit on master (#ad435a) fixed it back in April! Just not released yet.
Though the change wasn't intended to fix this problem, so I'll probably still write a test.
Ah bloody @#(! @fjarrett's commit on master (#ad435a) fixed it back in April! Just not released yet.
Sorry about that, @bitwombat :( I'll tag a 1.2.2 release when your test passes.
My test passes now because of #ad435a. So should be all set then #8 gets merged?
Fixed in v1.2.2
If I have this as my wp-config.php
This is what $config ends up being in WPConfigTransformer->parse_wp_config:
See that space before the second define? That messes up the preg_replace in
update
.I can write a test and attempt to fix it, but I'm not sure where to put the test. Some guidance there and/or opinion about this bug?