|
1 | | -# How to contribute |
| 1 | +# Contributing |
2 | 2 |
|
3 | | -Firstly, thank you for considering contributing! |
| 3 | +Thank you for considering a contribution to magento2-configurator! |
4 | 4 |
|
5 | | -When creating the original configurator for Magento 1, we knew it was something that can be valuable to the Magento Communnity. |
6 | | -Now what Magento 2 is out, it is something we want to do again however this time, we want to get this it out at the earliest stage possible for the Magento community to also build from the ground up. |
| 5 | +## Setting Up for Development |
7 | 6 |
|
8 | | -## The Ideal Setup |
| 7 | +The simplest approach is to install the extension as a path repository inside a working Magento 2 |
| 8 | +instance, which lets you test your changes against a real store. |
9 | 9 |
|
10 | | -Although your setup preferences may differ, the easiest way to get started is by including this project via composer into an fully setup Magento 2 install. |
11 | | - |
12 | | -``` |
13 | | -composer require ctidigital/magento2-configurator |
| 10 | +```bash |
| 11 | +# In your Magento root's composer.json, add a path repository pointing to your fork: |
| 12 | +composer config repositories.configurator path /path/to/your/fork/magento2-configurator |
| 13 | +composer require ctidigital/magento2-configurator:@dev |
14 | 14 | ``` |
15 | 15 |
|
16 | | -Fork the project to your own GitHub Account and then set the remote URLs to point to your fork as detailed here: https://help.github.com/articles/changing-a-remote-s-url/. |
17 | | - |
18 | | -### Making use of the sample data |
| 16 | +`vendor/ctidigital/magento2-configurator` will then be a symlink to your fork — edits are live |
| 17 | +immediately, no reinstall needed. |
19 | 18 |
|
20 | | -If you symlink the `Samples\Components` directory 1 level outside the Magento Root and symlink the `Samples\master.yaml` file in your Magento's `app/etc` directory. |
| 19 | +To install the dev tools (phpcs, phpmd, phpunit) without a Magento installation, configure the |
| 20 | +public [Mage-OS mirror] to resolve `magento/magento-coding-standard` without credentials, then |
| 21 | +run composer from inside the extension directory: |
21 | 22 |
|
| 23 | +```bash |
| 24 | +composer config --global repositories.mage-os composer https://mirror.mage-os.org/ |
| 25 | +cd /path/to/your/fork/magento2-configurator |
| 26 | +composer install |
| 27 | +``` |
22 | 28 |
|
23 | | -### CLI Based Logging Styles |
24 | | -@todo |
| 29 | +## Before Submitting a Pull Request |
25 | 30 |
|
26 | | -## Pull Requests |
| 31 | +All checks below are run automatically by GitHub Actions on every PR. Passing them locally before |
| 32 | +you push saves round-trips. |
27 | 33 |
|
28 | | -Before submitting a pull request there are a few things that you should ensure. These include: |
| 34 | +### 1 — Unit tests |
29 | 35 |
|
30 | | -1) Running Code Sniffer / Mess Detector / Duplicate Code Detector test. |
31 | | -``` |
32 | | -php vendor/bin/phpcs --standard=PSR2 vendor/ctidigital/magento2-configurator/Model/ vendor/ctidigital/magento2-configurator/Console/ vendor/ctidigital/magento2-configurator/Test/ vendor/ctidigital/magento2-configurator/Api/ vendor/ctidigital/magento2-configurator/Component/ vendor/ctidigital/magento2-configurator/Exception/ |
33 | | -php vendor/bin/phpmd vendor/ctidigital/magento2-configurator/Model/,vendor/ctidigital/magento2-configurator/Console/,vendor/ctidigital/magento2-configurator/Test/,vendor/ctidigital/magento2-configurator/Api/,vendor/ctidigital/magento2-configurator/Component/,vendor/ctidigital/magento2-configurator/Exception/ text cleancode,codesize,controversial,design,naming,unusedcode |
34 | | -php vendor/bin/phpcpd vendor/ctidigital/magento2-configurator/Model/ vendor/ctidigital/magento2-configurator/Console vendor/ctidigital/magento2-configurator/Test/ vendor/ctidigital/magento2-configurator/Api/ vendor/ctidigital/magento2-configurator/Component/ vendor/ctidigital/magento2-configurator/Exception/ |
| 36 | +```bash |
| 37 | +composer test |
35 | 38 | ``` |
36 | | -2) Include PHP Unit tests. If you're developing a new component, it is important that the component fits the framework by extending `ComponentAbstractTestCase` within `Test\Unit\Component`. |
37 | | -Then you would have to run the unit tests to ensure there are no failures. |
| 39 | + |
| 40 | +This runs 175 unit tests via PHPUnit. No Magento installation is required — the suite uses a |
| 41 | +standalone bootstrap and class stubs. Alternatively, without a `composer install`: |
| 42 | + |
| 43 | +```bash |
| 44 | +curl -sL https://phar.phpunit.de/phpunit-10.phar -o phpunit.phar |
| 45 | +php phpunit.phar --configuration phpunit.xml |
38 | 46 | ``` |
39 | | -php vendor/bin/phpunit --coverage-clover build/logs/clover.xml vendor/ctidigital/magento2-configurator/Test/Unit/ |
| 47 | + |
| 48 | +**New components must have a corresponding unit test.** Place it in `Test/Unit/Component/` |
| 49 | +following the naming and structure of the existing test files (e.g. `BlocksTest.php`). |
| 50 | + |
| 51 | +### 2 — Static analysis |
| 52 | + |
| 53 | +```bash |
| 54 | +composer cs # PHP_CodeSniffer — Magento2 standard, errors only |
| 55 | +composer md # PHP Mess Detector |
| 56 | +composer analyse # Both together |
40 | 57 | ``` |
41 | 58 |
|
42 | | -3) Include Samples. If you have developed/modified a component and it requires a change in the sample data to test the new feature/change this should be included with its corresponding component in the `Samples` directory and `master.yaml` should be updated to reflect this. |
| 59 | +Current baseline: **0 phpcs errors, 0 phpmd violations.** The CI build will fail if either |
| 60 | +tool reports a new issue against your changes. |
43 | 61 |
|
44 | | -4) Run configurator. If you've developed a component ensure it actually works with configurator and shows appropriate CLI based logging to feedback to the user. |
| 62 | +### 3 — Sample files |
| 63 | + |
| 64 | +If your change affects accepted YAML fields, column names, or data format for any component, |
| 65 | +update the corresponding file in `Samples/Components/` and ensure `Samples/master.yaml` reflects |
| 66 | +it. Sample files are the contract between the extension and its operators. |
| 67 | + |
| 68 | +### 4 — Manual smoke test |
| 69 | + |
| 70 | +Run the affected component against a real Magento instance to confirm the CLI output and |
| 71 | +behaviour are correct: |
| 72 | + |
| 73 | +```bash |
| 74 | +bin/magento configurator:run --env="<environment>" --component="<your-component>" |
| 75 | +bin/magento configurator:run --env="<environment>" --component="<your-component>" -v |
45 | 76 | ``` |
46 | | -bin/magento configurator:run --env="<environment>" --components="<your component>" |
47 | | -``` |
| 77 | + |
| 78 | +## Coding Standards |
| 79 | + |
| 80 | +- PHP 8.3+, `declare(strict_types=1)` in every file. |
| 81 | +- Constructor property promotion with `readonly` for injected dependencies. |
| 82 | +- Native types on all properties, parameters, and return values. |
| 83 | +- Use Magento service contracts (Repository / API interfaces) in preference to concrete |
| 84 | + models wherever they exist. |
| 85 | +- No `ObjectManager` usage in components. |
| 86 | +- Suppressed PHPMD warnings (`@SuppressWarnings`) must be specific rule names |
| 87 | + (e.g. `PHPMD.CyclomaticComplexity`), not blanket `@SuppressWarnings(PHPMD)`. |
| 88 | + |
| 89 | +## Pull Request Checklist |
| 90 | + |
| 91 | +- [ ] `composer test` passes (175 tests, 0 errors) |
| 92 | +- [ ] `composer analyse` passes (0 phpcs errors, 0 phpmd violations) |
| 93 | +- [ ] New/changed component has a unit test |
| 94 | +- [ ] Sample file updated if YAML format changed |
| 95 | +- [ ] Manually verified against a Magento instance |
| 96 | + |
| 97 | +[Mage-OS mirror]: https://mage-os.org/ |
0 commit comments