Skip to content
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

magento/magento2#28579:DependencyTest does not analyze GraphQL schema… #28747

Conversation

sasha19957099
Copy link
Contributor

@sasha19957099 sasha19957099 commented Jun 16, 2020

… files - added tests and missing dependency for SwatchesGraphQl module

Description (*)

Related Pull Requests

https://github.com/magento/partners-magento2-infrastructure/pull/8

Fixed Issues (if relevant)

  1. Fixes magento/magento2#<issue_number>

Manual testing scenarios (*)

  1. ...
  2. ...

Questions or comments

Contribution checklist (*)

  • Pull request has a meaningful description of its purpose
  • All commits are accompanied by meaningful commit messages
  • All new or changed code is covered with unit/integration tests (if applicable)
  • All automated tests passed successfully (all builds are green)

…added tests and missing dependency for SwatchesGraphQl module
@m2-assistant
Copy link

m2-assistant bot commented Jun 16, 2020

Hi @sasha19957099. Thank you for your contribution
Here is some useful tips how you can test your changes using Magento test environment.
Add the comment under your pull request to deploy test or vanilla Magento instance:

  • @magento give me test instance - deploy test instance based on PR changes
  • @magento give me 2.4-develop instance - deploy vanilla Magento instance

❗ Automated tests can be triggered manually with an appropriate comment:

  • @magento run all tests - run or re-run all required tests against the PR changes
  • @magento run <test-build(s)> - run or re-run specific test build(s)
    For example: @magento run Unit Tests

<test-build(s)> is a comma-separated list of build names. Allowed build names are:

  1. Database Compare
  2. Functional Tests CE
  3. Functional Tests EE,
  4. Functional Tests B2B
  5. Integration Tests
  6. Magento Health Index
  7. Sample Data Tests CE
  8. Sample Data Tests EE
  9. Sample Data Tests B2B
  10. Static Tests
  11. Unit Tests
  12. WebAPI Tests

You can find more information about the builds here

ℹ️ Please run only needed test builds instead of all when developing. Please run all test builds before sending your PR for review.

For more details, please, review the Magento Contributor Guide documentation.

@sasha19957099
Copy link
Contributor Author

@magento run all tests

@sasha19957099
Copy link
Contributor Author

@magento run all tests

@sasha19957099 sasha19957099 linked an issue Jun 17, 2020 that may be closed by this pull request
@sasha19957099 sasha19957099 self-assigned this Jun 17, 2020
@ghost ghost unassigned sasha19957099 Jun 17, 2020
@ghost
Copy link

ghost commented Jun 17, 2020

@sasha19957099 unfortunately, only members of the maintainers team are allowed to assign developers to the pull request

@sasha19957099
Copy link
Contributor Author

@magento run all tests

@sasha19957099
Copy link
Contributor Author

@magento run Magento Health Index
@magento run Static Tests

@sasha19957099
Copy link
Contributor Author

@magento run Static Tests

@sasha19957099
Copy link
Contributor Author

Here is a problem. Running static tests on the Magento build we don't have Magento app instance. It is a cause of failing static tests https://public-results-storage-prod.magento-testing-service.engineering/reports/magento/magento2/pull/28747/3fbd463f86fe3e705dc9d439abe63716/Statics/allure-report-ee/index.html#categories/f8421ffb12c0de5091bdf17e30c0fef2/1774e386c6824151/
So interface Magento\Framework\GraphQlSchemaStitching\GraphQlReader\TypeMetaReaderInterface can't be instantiated. How we can solve it?

@sasha19957099
Copy link
Contributor Author

@magento run all tests

@nrkapoor nrkapoor requested review from dthampy and cpartica and removed request for dthampy June 20, 2020 13:23
@nrkapoor nrkapoor added this to the 2.4.1 milestone Jun 20, 2020
@sasha19957099
Copy link
Contributor Author

@magento run all tests

@sasha19957099 sasha19957099 requested a review from cpartica June 24, 2020 15:00
*/
public function __construct()
{
$this->initDeclaredDependencies();
Copy link
Contributor

Choose a reason for hiding this comment

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

this would make this class instantiate very slowly unless you use a Proxy class.
the other solution would be to call init before calling addDependencies or getDeclaredDependencies. basically any public method of this class

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yes, you're right, changed to the proxy.

Copy link
Contributor

Choose a reason for hiding this comment

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

what I meant that instead of using a proxy ..better call that initDeclaredDependencies within addDependencies and getDeclaredDependencies and remove it from constructor.
It's even better than a proxy.

Copy link
Contributor

Choose a reason for hiding this comment

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

to avoid using an init in the constructor you can move it into the method where it is needed.
e.g.

function getDependencies(){
    if(empty($dependencies)){
        doInit();
    }
    return $this->dependencies;
}

@cpartica cpartica added the PAP Partners acceleration program label Jun 25, 2020
@sasha19957099
Copy link
Contributor Author

@magento run all tests

/**
* Types of dependency between modules.
*/
const TYPE_HARD = 'hard';
Copy link
Contributor

Choose a reason for hiding this comment

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

/**
* DependencyProvider constructor.
* @throws \Magento\Framework\Exception\LocalizedException
* @throws \Magento\TestFramework\Inspection\Exception
Copy link
Contributor

Choose a reason for hiding this comment

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

try to add all namespaces and move the to a "use" statement


/**
* @var array
* DeclarativeSchemaDependencyProvider constructor.
Copy link
Contributor

Choose a reason for hiding this comment

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

you don't need a comment description in constructors

public function __construct(\Magento\Test\Integrity\Dependency\DependencyProvider\Proxy $dependencyProvider)
{
$this->dependencyProvider = $dependencyProvider;
$this->getGraphQlSchemaDeclaration();
Copy link
Contributor

Choose a reason for hiding this comment

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

this will again do constructor processing delaying instantiation of the class

*/
public function __construct()
{
$this->initDeclaredDependencies();
Copy link
Contributor

Choose a reason for hiding this comment

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

what I meant that instead of using a proxy ..better call that initDeclaredDependencies within addDependencies and getDeclaredDependencies and remove it from constructor.
It's even better than a proxy.

$interfaces = array_keys($type['implements']);
foreach ($interfaces as $interface) {
$dependOnModule = $schema[$interface]['module'];
if ($dependOnModule != $moduleName) {
Copy link
Contributor

Choose a reason for hiding this comment

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

!==

$dependencies = [];

foreach ($schema as $type) {
if (isset($type['module']) && $type['module'] == $moduleName && isset($type['implements'])) {
Copy link
Contributor

Choose a reason for hiding this comment

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

===

break;
}
}
if (empty($foundModuleName)) {
Copy link
Contributor

Choose a reason for hiding this comment

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

isn't $foundModuleName = ''; already empty if not set by foreach?

@ghost ghost assigned danielrenaud Jun 25, 2020
@sasha19957099
Copy link
Contributor Author

@magento run Static Tests

1 similar comment
@sasha19957099
Copy link
Contributor Author

@magento run Static Tests

@sasha19957099
Copy link
Contributor Author

@magento run Static Tests

@sasha19957099
Copy link
Contributor Author

@magento run all tests

*/
private function readJsonFile(string $file, bool $asArray = false)
{
$decodedJson = json_decode(file_get_contents($file), $asArray);
if (null == $decodedJson) {
//phpcs:ignore Magento2.Exceptions.DirectThrow
throw new \Exception("Invalid Json: $file");
throw new InspectionException("Invalid Json: $file");
Copy link
Contributor

Choose a reason for hiding this comment

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

missed this, we usually do a localized exception that's translatable and any parameters like file go into a "%1" or "%s" if using sprintf.
This is probably fine because it's a test. But "Invalid Json: $file" would still be a risky practice and sprintf would be preferred.

@m2-assistant
Copy link

m2-assistant bot commented Jul 15, 2020

Hi @sasha19957099, thank you for your contribution!
Please, complete Contribution Survey, it will take less than a minute.
Your feedback will help us to improve contribution process.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

DependencyTest does not analyze GraphQL schema files
5 participants