Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions fixture/discovery/sansec.store/app/etc/env.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?php

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

would break tests otherwise:

could not parse fixture//magento2/configs/empty.php, missing user or db name
open /do/not/exist: no such file or directory
--- FAIL: TestDiscoverStores (0.05s)
    store_test.go:24: 
                Error Trace:    store_test.go:24
                Error:          "[%!s(*gocommerce.Store=&{fixture/discovery/applications/123456789/public_html 0x1016eec60 0x1d8fb903abe8})]" should have 2 item(s), but has 1
                Test:           TestDiscoverStores
panic: runtime error: index out of range [1] with length 1 [recovered, repanicked]

the configs should never be empty anyways(?), so I added a minimal placeholder

return [
'db' => [
'table_prefix' => '',
'connection' => [
'default' => [
'host' => 'localhost',
'dbname' => 'magento2',
'username' => 'app',
'password' => 'secret',
],
],
],
];
5 changes: 4 additions & 1 deletion store.go
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,10 @@ func DiscoverStores() []*Store {

func docrootToStore(docroot string, pl PlatformInterface) *Store {
cfgPath := filepath.Join(docroot, pl.ConfigPath())
cfg, _ := pl.ParseConfig(cfgPath)
cfg, err := pl.ParseConfig(cfgPath)
if err != nil {
return nil
}
return &Store{docroot, pl, cfg}
}

Expand Down
9 changes: 9 additions & 0 deletions store_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,15 @@ func TestDiscoverSymlinkedStore(t *testing.T) {
assert.Contains(t, stores[0].DocRoot, "discovery/sansec.store")
}

func TestFindStoreAtRootUnreadableConfig(t *testing.T) {
root := t.TempDir()
// a directory named wp-config.php makes os.ReadFile fail while os.Stat succeeds
if err := os.Mkdir(root+"/wp-config.php", 0o755); err != nil {
t.Fatal(err)
}
assert.Nil(t, FindStoreAtRoot(root))
}

func TestDiscoverStoresEmpty(t *testing.T) {
oldHome := os.Getenv("HOME")
defer os.Setenv("HOME", oldHome)
Expand Down
Loading