Command line features in Magium

While the rest of you were on Spring Break I was , well, too. But I also managed to finegle some time in between building snow forts and violent illness to add some new features to Magium.

CLI tooling is fairly popular in PHP-land and given that I want to be popular too I figured it would be a good idea to add some CLI tooling to Magium. Some of this is in preparation for some new tooling I will be adding to the website in the next few weeks.

The CLI tool is found in vendor/bin/magium. If you have MagiumMagento installed, as of the time of this writing, these are the options you will see:

config:set Modifies a setting
config:unset Removes a setting
element:get Retrieves the default values for a configurable element
element:list Extracts all of the AbstractConfigurableElement-based objects
element:set Modifies a property value for a configurable element
element:unset Removes an abstract configurable element’s property
magento:extract-navigation-xpath Will run a series of tests on the provided URL to attempt to extract the navigation Xpath for the theme configuration
magium:init Creates the magium.json config file in the specified project root directory
magium:webdriver Configures the WebDriver settings

Magium Commands (init|webdriver)

Before running anything you need to initialize the environment. That basically means writing the magium.json file. Run:

vendor/bin/magium magium:init

And you’re set.

The webdriver command allows you to make some basic changes to the webdriver settings. More functionality will be expanded upon later.

You can set the webdriver URL

$ vendor/bin/magium webdriver --url
Wrote value for "magium\testcaseconfiguration:webDriverRemote" to /cygdrive/f/phpstorm-projects/MagiumMagento/magium.json

You can very easily change the browser

$ vendor/bin/magium webdriver --capability firefox
Wrote value for "magium\testcaseconfiguration:capabilities" to /cygdrive/f/phpstorm-projects/MagiumMagento/magium.json

Config Commands (set|unset)

These are not currently used but will be used with some of the SaaS features that I am working on. They will allow you to set various arbitrary project settings, though most will actually use commands in the element namespace.

Element Commands (get|list|set|unset)

These are used to set configuration options for elements that extend Magium\AbstractConfigurableElement. In other words, they have been designed on the class level to be configurable. Some examples of this are identities and themes.

Say that you want to change the default email address for your customer identity. You can create the /configuration/Magium/Magento/Identities/Customer.php file and define it there or you can execute the following series of commands.

First, find the email address property using element:get (the format is the class name followed by the (optional) stripos-based filter

$ vendor/bin/magium element:get Magium\\Magento\\Identities\\Customer email

        Default Value:

Now you know the email address property is called emailAddresss.

Next up is to set the new value.

$ vendor/bin/magium  element:set Magium\\Magento\\Identities\\Customer emailAddress
Wrote value for "magium\magento\identities\customer:emailAddress" to /cygdrive/f/phpstorm-projects/MagiumMagento/magium.json


Not sure what your options are? Try element:list.

$ vendor/bin/magium element:list 
Classes found: 

You can also make it copy and paste friendly (since CLI’s don’t know that the \ is the namespace separator).

$ vendor/bin/magium element:list --escape
Classes found: 

Magento Commands (extract-navigation-xpath)

Currently there is only one command for the Magento namespace, but others will be added. Extract-navigation-xpath can be used to help figure out what is the path to the navigation components are.

$ vendor/bin/magium magento:extract-navigation-xpath http://magento19.loc Accessories/Jewelry
Paste the following lines into your theme configuration file
$this->navigationBaseXPathSelector = '/html/body/div/div[2]/header/div/div[3]/nav';
$this->navigationChildXPathSelector = 'a[concat(" ",normalize-space(.)," ") = " %s "]/ancestor::li[1]';