I'm running the static tests for one of my magento 2 modules php bin/magento dev:tests:run static
and I get the following errors.
Data set: [ROOT]/app/code/Sample/News/Block/Adminhtml/Author/Edit/Buttons/Generic.php
Module Sample\News has undeclared dependencies: hard [Magento\Backend]
[ROOT]/dev/tests/static/testsuite/Magento/Test/Integrity/DependencyTest.php:313
[ROOT]/lib/internal/Magento/Framework/App/Utility/AggregateInvoker.php:56
[ROOT]/dev/tests/static/testsuite/Magento/Test/Integrity/DependencyTest.php:316
and others like that.
My module.xml
file looks like this:
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Module/etc/module.xsd">
<module name="Sample_News" setup_version="2.0.0">
<sequence>
<module name="Magento_Backend"/>
<module name="Magento_Ui" />
<module name="Magento_Store" />
<module name="Magento_Theme" />
<module name="Magento_Cms" />
</sequence>
</module>
</config>
my composer.json
file looks like this:
{
"name": "tzyganu/magento2-sample-module",
"description": "Magento 2 Sample crud module",
"version": "2.0.0",
"license": "MIT",
"require": {
"magento/module-backend": "~100.0.0",
"magento/module-cms": "~100.0.0",
"magento/module-ui": "~100.0.0",
"magento/module-store": "100.0.*",
"magento/framework": "100.0.*",
"magento/module-media-storage": "100.0.*",
"magento/module-directory": "100.0.*"
},
"type": "magento2-module",
"repositories": [
{
"type": "git",
"url": "https://github.com/tzyganu/Magento2SampleModule"
}
],
"autoload": {
"files": [
"registration.php"
],
"psr-4": {
"Sample\\News\\": ""
}
}
}
Is there an other place where I should declare these dependencies?
[EDIT]
While debigging I found out that the module name that is used here to check for dependencies is Sample\News
but in the dependency $_mapDependencies
static var in the same class the module appears as sample/sample-news
. This means that even if I add all the dependencies correctly it will still say that there is no declared dependency because of this.
Best Answer
The test verifies the declaration of dependencies in
composer.json
.But looks like you copy/pasted the module name in composer file. You should name your module like
"sample/module-news"
, and not"tzyganu/magento2-sample-module"