Documentation
¶
Overview ¶
Package testhelper provides shared fixture builders for tests: writing files into temp directories and rendering the composer.json / composer.lock shapes that Shopware project and extension tests need over and over.
Index ¶
- func AppDir(tb testing.TB, m AppManifest) string
- func ComposerLock(packages ...LockPackage) string
- func ExtensionDir(tb testing.TB, c ComposerJSON) string
- func NewApp(tb testing.TB, name string) string
- func NewPlugin(tb testing.TB, name string) string
- func WriteFile(tb testing.TB, filePath, content string)
- type AppManifest
- type ComposerJSON
- type LockPackage
- type Project
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func AppDir ¶
func AppDir(tb testing.TB, m AppManifest) string
AppDir writes manifest.xml into a fresh temp directory and returns the directory: a standalone Shopware app root.
func ComposerLock ¶
func ComposerLock(packages ...LockPackage) string
ComposerLock renders a composer.lock with the given packages and an empty packages-dev section.
func ExtensionDir ¶
func ExtensionDir(tb testing.TB, c ComposerJSON) string
ExtensionDir writes composer.json into a fresh temp directory and returns the directory: a standalone plugin or bundle root. Use it when the test cares about the composer content — the manifest stays visible at the call site; reach for NewPlugin when any valid plugin will do.
func NewApp ¶
NewApp returns a directory containing a valid app manifest for tests that just need one and don't assert its metadata.
func NewPlugin ¶
NewPlugin returns a directory containing a valid platform plugin for tests that just need one and don't assert its metadata. The composer name and bootstrap class are derived from name: "FroshTools" becomes "test/frosh-tools" with class `FroshTools\FroshTools` at version 1.0.0. Tests that assert those values should use ExtensionDir with an explicit ComposerJSON instead.
Types ¶
type AppManifest ¶
type AppManifest struct {
Name string
Label map[string]string // lang -> text; "" is the default language
Description map[string]string // lang -> text; "" is the default language
Compatibility string
Author string
Copyright string
Version string
License string
Icon string
SetupSecret string
}
AppManifest describes a manifest.xml fixture for a Shopware app. Zero-valued fields are omitted from the output, so validator tests can express a manifest missing exactly one required element by clearing that field on the value NewAppManifest returns.
func NewAppManifest ¶
func NewAppManifest(name string) AppManifest
NewAppManifest returns a complete, valid app manifest with placeholder metadata. Tests clear or override individual fields to build variants.
func (AppManifest) String ¶
func (m AppManifest) String() string
String renders the manifest as XML.
type ComposerJSON ¶
type ComposerJSON struct {
Name string
Type string
Version string
License string
Description string
Authors []string // rendered as [{"name": ...}, ...]
Require map[string]string
RequireDev map[string]string
PluginClass string // extra.shopware-plugin-class
Label map[string]string // extra.label
Extra map[string]any // additional extra entries, merged last
Psr4 map[string]string // autoload.psr-4
Repositories []map[string]any // composer repositories, e.g. path or composer type
}
ComposerJSON describes a composer.json fixture. Zero-valued fields are left out of the rendered JSON, so partial and degenerate manifests (only a version, an empty object) stay expressible.
func PluginComposer ¶
func PluginComposer(name, version, class string) ComposerJSON
PluginComposer returns the composer.json for a Shopware platform plugin. class is the fully qualified bootstrap class (e.g. `Swag\Demo\Demo`); the en-GB label and the PSR-4 autoload prefix are derived from it. Callers can override any field before rendering.
func (ComposerJSON) String ¶
func (c ComposerJSON) String() string
String renders the manifest as JSON.
type LockPackage ¶
type LockPackage struct {
Name string `json:"name"`
Version string `json:"version"`
Type string `json:"type,omitempty"`
Require map[string]string `json:"require,omitempty"`
Dist map[string]string `json:"dist,omitempty"` // e.g. {"type": "path", "url": "custom/static-plugins/Foo"}
}
LockPackage is one entry in a composer.lock packages list.
type Project ¶
Project is a Shopware project rooted in a temp directory that tests can populate file by file.
func NewProject ¶
NewProject creates an empty project in a fresh temp directory.
func (*Project) CustomPlugin ¶
func (p *Project) CustomPlugin(dirName string, composer ComposerJSON) *Project
CustomPlugin writes custom/plugins/<dirName>/composer.json for a locally installed plugin.
func (*Project) Dir ¶
Dir creates an empty directory at the slash-separated path relative to the project root.
func (*Project) File ¶
File writes content at the slash-separated path relative to the project root.
func (*Project) VendorPackage ¶
func (p *Project) VendorPackage(name string, composer ComposerJSON) *Project
VendorPackage writes vendor/<name>/composer.json for a Composer-managed package.