-
Notifications
You must be signed in to change notification settings - Fork 24
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
feat: add command settings:publish
#80
base: develop
Are you sure you want to change the base?
feat: add command settings:publish
#80
Conversation
d52ebc4
to
0b113d9
Compare
settings:publish
settings:publish
|
||
if (is_file($filepath)) { | ||
copy($filepath, APPPATH . 'Config/Settings.php.bak'); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why do you need this? Since there's no unlinking in the tearDown, this operation would unnecessarily pollute the next test and the filesystem.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@paulbalandan In fact, testPublishConfigFileWithForce()
depends on this. I wanted to write in the following way, but apparently the notification will be removed in phpunit v10.1:
/**
* @depends testPublishConfigFile
*/
public function testPublishConfigFileWithForce(): void
{
// ...
}
phpunit v10.1:
#[Depends('testPublishConfigFile')]
public function testPublishConfigFileWithForce(): void
{
// ...
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think instead of depending on the other test, in the 2nd test you should run the command twice. First without the -f
flag asserting the file exists. Then another command run with the -f
flag.
- APP_NAMESPACE | ||
- CI_DEBUG | ||
- ENVIRONMENT | ||
parameters: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What was changed here? Tabs to spaces?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@datamweb Please keep this file as close to the DevKit template as possible so updates are easier.
|
||
try { | ||
$publisher->addPath('Config/Settings.php') | ||
->merge($this->overwrites); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If $this->overwrites
is only needed in this particular place, then you don't need the property. You can simply use array_key_exists('f', $params)
here or use an intermediate variable.
$publisher->addPath('Config/Settings.php') | ||
->merge($this->overwrites); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you align ->addPath
to the ->merge
below?
$publisher->addPath('Config/Settings.php') | |
->merge($this->overwrites); | |
$publisher | |
->addPath('Config/Settings.php') | |
->merge($this->overwrites); |
|
||
if (is_file($filepath)) { | ||
copy($filepath, APPPATH . 'Config/Settings.php.bak'); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think instead of depending on the other test, in the 2nd test you should run the command twice. First without the -f
flag asserting the file exists. Then another command run with the -f
flag.
* @depends testPublishConfigFile | ||
*/ | ||
public function testPublishConfigFileWithForce(): void | ||
{ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remove extra whitespaces after {
and before }
.
$filepath = APPPATH . 'Config/Settings.php'; | ||
|
||
helper('filesystem'); | ||
write_file($filepath, 'fake text.'); | ||
$contents = $this->getFileContents($filepath); | ||
|
||
$this->assertFileExists($filepath); | ||
$this->assertStringContainsString('fake text.', $contents); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This part basically tests write_file
, not the command.
clearstatcache(true, $expectedConfigFile); | ||
if (is_file($expectedConfigFile)) { | ||
unlink($expectedConfigFile); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
cleanup should be done in teardown.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If the cleanup is only for the test method, I think it is okay to put it in the test method.
tearDown()
is called after each test method.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The advantage of tearDown()
is that it will always run regardless of test failures. Especially if there are multiple tests that might leave this file lingering I like the idea of an idempotent cleanup after every test.
@datamweb This looks good, and close! Can you get the recommendations in place and we can get this in for next release? |
@MGatner I'm currently traveling, I'll try to get back to the reviews as soon as I get back to my PC. |
@datamweb any chance you'd be able to wrap this up? I've got another command about ready to merge and it would be great to release them together. |
No description provided.