Skip to content

Commit e088545

Browse files
authored
APPS-5345 Enabled passing organization, application, and module via codeception configuration. (#9639)
APPS-5345 Enable configurable class resolving via Codeception configuration
1 parent 714838a commit e088545

File tree

10 files changed

+122
-158
lines changed

10 files changed

+122
-158
lines changed

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
"description": "Testify module",
55
"license": "proprietary",
66
"require": {
7-
"codeception/codeception": "^3.6.1 || ^4.0.0",
7+
"codeception/codeception": "^3.6.1 || ^4.0.0 || ^5.0.0",
88
"dms/phpunit-arraysubset-asserts": "^0.4.0",
99
"fakerphp/faker": "^1.16.0",
1010
"mikey179/vfsstream": "^1.6",

tests/SprykerTest/Client/Testify/_support/Helper/DependencyProviderHelper.php

Lines changed: 2 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77

88
namespace SprykerTest\Client\Testify\Helper;
99

10-
use Codeception\Configuration;
1110
use Codeception\Module;
1211
use Codeception\Stub;
1312
use Codeception\TestInterface;
@@ -17,22 +16,19 @@
1716
use Spryker\Shared\Kernel\ContainerMocker\ContainerGlobals;
1817
use Spryker\Shared\Kernel\ContainerMocker\ContainerMocker;
1918
use SprykerTest\Shared\Testify\Helper\ClassResolverTrait;
19+
use SprykerTest\Shared\Testify\Helper\ModuleNameTrait;
2020

2121
class DependencyProviderHelper extends Module
2222
{
2323
use ContainerMocker;
2424
use ClassResolverTrait;
25+
use ModuleNameTrait;
2526

2627
/**
2728
* @var string
2829
*/
2930
protected const DEPENDENCY_PROVIDER_CLASS_NAME_PATTERN = '\%1$s\Client\%3$s\%3$sDependencyProvider';
3031

31-
/**
32-
* @var int
33-
*/
34-
protected const MODULE_NAME_POSITION = 2;
35-
3632
/**
3733
* @var \Spryker\Client\Kernel\AbstractDependencyProvider|null
3834
*/
@@ -117,23 +113,6 @@ public function getModuleContainer(?string $moduleName = null): Container
117113
return $container;
118114
}
119115

120-
/**
121-
* @param string|null $moduleName
122-
*
123-
* @return string
124-
*/
125-
protected function getModuleName(?string $moduleName = null): string
126-
{
127-
if ($moduleName) {
128-
return $moduleName;
129-
}
130-
131-
$config = Configuration::config();
132-
$namespaceParts = explode('\\', $config['namespace']);
133-
134-
return $namespaceParts[static::MODULE_NAME_POSITION];
135-
}
136-
137116
/**
138117
* @param string $moduleName
139118
*

tests/SprykerTest/Client/Testify/_support/Helper/FactoryHelper.php

Lines changed: 2 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77

88
namespace SprykerTest\Client\Testify\Helper;
99

10-
use Codeception\Configuration;
1110
use Codeception\Module;
1211
use Codeception\Stub;
1312
use Codeception\TestInterface;
@@ -18,23 +17,20 @@
1817
use SprykerTest\Shared\Testify\Helper\ClassResolverTrait;
1918
use SprykerTest\Shared\Testify\Helper\ConfigHelper;
2019
use SprykerTest\Shared\Testify\Helper\ConfigHelperTrait;
20+
use SprykerTest\Shared\Testify\Helper\ModuleNameTrait;
2121

2222
class FactoryHelper extends Module
2323
{
2424
use DependencyProviderHelperTrait;
2525
use ConfigHelperTrait;
2626
use ClassResolverTrait;
27+
use ModuleNameTrait;
2728

2829
/**
2930
* @var string
3031
*/
3132
protected const FACTORY_CLASS_NAME_PATTERN = '\%1$s\Client\%3$s\%3$sFactory';
3233

33-
/**
34-
* @var int
35-
*/
36-
protected const MODULE_NAME_POSITION = 2;
37-
3834
/**
3935
* @var array<\Spryker\Client\Kernel\AbstractFactory>
4036
*/
@@ -99,23 +95,6 @@ public function getFactory(?string $moduleName = null): AbstractFactory
9995
return $moduleFactory;
10096
}
10197

102-
/**
103-
* @param string|null $moduleName
104-
*
105-
* @return string
106-
*/
107-
protected function getModuleName(?string $moduleName = null): string
108-
{
109-
if ($moduleName) {
110-
return $moduleName;
111-
}
112-
113-
$config = Configuration::config();
114-
$namespaceParts = explode('\\', $config['namespace']);
115-
116-
return $namespaceParts[static::MODULE_NAME_POSITION];
117-
}
118-
11998
/**
12099
* @param string|null $moduleName
121100
*

tests/SprykerTest/Glue/Testify/_support/Helper/DependencyProviderHelper.php

Lines changed: 2 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -16,21 +16,18 @@
1616
use Spryker\Glue\Kernel\Container;
1717
use Spryker\Shared\Kernel\ContainerMocker\ContainerGlobals;
1818
use Spryker\Shared\Kernel\ContainerMocker\ContainerMocker;
19+
use SprykerTest\Shared\Testify\Helper\ModuleNameTrait;
1920

2021
class DependencyProviderHelper extends Module
2122
{
2223
use ContainerMocker;
24+
use ModuleNameTrait;
2325

2426
/**
2527
* @var string
2628
*/
2729
protected const DEPENDENCY_PROVIDER_CLASS_NAME_PATTERN = '\%1$s\Glue\%2$s\%2$sDependencyProvider';
2830

29-
/**
30-
* @var int
31-
*/
32-
protected const MODULE_NAME_POSITION = 2;
33-
3431
/**
3532
* @var \Spryker\Glue\Kernel\AbstractBundleDependencyProvider|null
3633
*/
@@ -115,23 +112,6 @@ public function getModuleContainer(?string $moduleName = null): Container
115112
return $container;
116113
}
117114

118-
/**
119-
* @param string|null $moduleName
120-
*
121-
* @return string
122-
*/
123-
protected function getModuleName(?string $moduleName = null): string
124-
{
125-
if ($moduleName) {
126-
return $moduleName;
127-
}
128-
129-
$config = Configuration::config();
130-
$namespaceParts = explode('\\', $config['namespace']);
131-
132-
return $namespaceParts[static::MODULE_NAME_POSITION];
133-
}
134-
135115
/**
136116
* @param string $moduleName
137117
*

tests/SprykerTest/Glue/Testify/_support/Helper/FactoryHelper.php

Lines changed: 2 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -17,22 +17,19 @@
1717
use Spryker\Glue\Kernel\Container;
1818
use SprykerTest\Shared\Testify\Helper\ConfigHelper;
1919
use SprykerTest\Shared\Testify\Helper\ConfigHelperTrait;
20+
use SprykerTest\Shared\Testify\Helper\ModuleNameTrait;
2021

2122
class FactoryHelper extends Module
2223
{
2324
use DependencyProviderHelperTrait;
2425
use ConfigHelperTrait;
26+
use ModuleNameTrait;
2527

2628
/**
2729
* @var string
2830
*/
2931
protected const FACTORY_CLASS_NAME_PATTERN = '\%1$s\Glue\%2$s\%2$sFactory';
3032

31-
/**
32-
* @var int
33-
*/
34-
protected const MODULE_NAME_POSITION = 2;
35-
3633
/**
3734
* @var array<\Spryker\Glue\Kernel\AbstractFactory>
3835
*/
@@ -97,23 +94,6 @@ public function getFactory(?string $moduleName = null): AbstractFactory
9794
return $moduleFactory;
9895
}
9996

100-
/**
101-
* @param string|null $moduleName
102-
*
103-
* @return string
104-
*/
105-
protected function getModuleName(?string $moduleName = null): string
106-
{
107-
if ($moduleName) {
108-
return $moduleName;
109-
}
110-
111-
$config = Configuration::config();
112-
$namespaceParts = explode('\\', $config['namespace']);
113-
114-
return $namespaceParts[static::MODULE_NAME_POSITION];
115-
}
116-
11797
/**
11898
* @param string|null $moduleName
11999
*

tests/SprykerTest/Shared/Testify/_support/Helper/ClassResolverTrait.php

Lines changed: 26 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -64,17 +64,21 @@ protected function resolveClassName(string $classNamePattern, string $moduleName
6464
/**
6565
* @param string $classNamePattern
6666
* @param string $moduleName
67-
* @param string|null $applicationName
6867
*
6968
* @return array<string>
7069
*/
71-
protected function getClassNameCandidates(string $classNamePattern, string $moduleName, ?string $applicationName = null): array
70+
protected function getClassNameCandidates(string $classNamePattern, string $moduleName): array
7271
{
72+
$classNameFromConfiguration = $this->getClassNameFromConfiguration($classNamePattern, $moduleName);
73+
7374
$config = Configuration::config();
7475
$namespaceParts = explode('\\', $config['namespace']);
76+
77+
// When `application` is configured in the codeception.yml use this value instead of guessing it.
78+
$application = $config['application'] ?? $namespaceParts[1];
79+
7580
$classNameCandidates = [];
76-
$application = $applicationName ?? $namespaceParts[1];
77-
$classNameCandidates[] = sprintf($classNamePattern, $this->trimTestNamespacePostfix($namespaceParts[0]), $application, $moduleName);
81+
$classNameCandidates[] = $classNameFromConfiguration;
7882

7983
foreach ($this->coreNamespaces as $coreNamespace) {
8084
$classNameCandidates[] = sprintf($classNamePattern, $coreNamespace, $application, $moduleName);
@@ -83,6 +87,24 @@ protected function getClassNameCandidates(string $classNamePattern, string $modu
8387
return $classNameCandidates;
8488
}
8589

90+
/**
91+
* @param string $classNamePattern
92+
* @param string $moduleName
93+
*
94+
* @return string
95+
*/
96+
protected function getClassNameFromConfiguration(string $classNamePattern, string $moduleName): string
97+
{
98+
$config = Configuration::config();
99+
$namespaceParts = explode('\\', $config['namespace']);
100+
101+
// When `organization` and or `application` is configured in the codeception.yml use these value instead of guessing them.
102+
$organization = $config['organization'] ?? $namespaceParts[0];
103+
$application = $config['application'] ?? $namespaceParts[1];
104+
105+
return sprintf($classNamePattern, $this->trimTestNamespacePostfix($organization), $application, $moduleName);
106+
}
107+
86108
/**
87109
* @param string $namespacePart
88110
*

tests/SprykerTest/Shared/Testify/_support/Helper/ModuleNameTrait.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,11 @@ protected function getModuleName(?string $moduleName = null): string
2323
}
2424

2525
$config = Configuration::config();
26+
27+
if (isset($config['module'])) {
28+
return $config['module'];
29+
}
30+
2631
$namespaceParts = explode('\\', $config['namespace']);
2732

2833
return $namespaceParts[2];

tests/SprykerTest/Yves/Testify/_support/Helper/DependencyProviderHelper.php

Lines changed: 2 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -16,21 +16,18 @@
1616
use Spryker\Shared\Kernel\ContainerMocker\ContainerMocker;
1717
use Spryker\Yves\Kernel\AbstractBundleDependencyProvider;
1818
use Spryker\Yves\Kernel\Container;
19+
use SprykerTest\Shared\Testify\Helper\ModuleNameTrait;
1920

2021
class DependencyProviderHelper extends Module
2122
{
2223
use ContainerMocker;
24+
use ModuleNameTrait;
2325

2426
/**
2527
* @var string
2628
*/
2729
protected const DEPENDENCY_PROVIDER_CLASS_NAME_PATTERN = '\%1$s\Yves\%2$s\%2$sDependencyProvider';
2830

29-
/**
30-
* @var int
31-
*/
32-
protected const MODULE_NAME_POSITION = 2;
33-
3431
/**
3532
* @var \Spryker\Yves\Kernel\AbstractBundleDependencyProvider|null
3633
*/
@@ -115,23 +112,6 @@ public function getModuleContainer(?string $moduleName = null): Container
115112
return $container;
116113
}
117114

118-
/**
119-
* @param string|null $moduleName
120-
*
121-
* @return string
122-
*/
123-
protected function getModuleName(?string $moduleName = null): string
124-
{
125-
if ($moduleName) {
126-
return $moduleName;
127-
}
128-
129-
$config = Configuration::config();
130-
$namespaceParts = explode('\\', $config['namespace']);
131-
132-
return $namespaceParts[static::MODULE_NAME_POSITION];
133-
}
134-
135115
/**
136116
* @param string $moduleName
137117
*

tests/SprykerTest/Yves/Testify/_support/Helper/FactoryHelper.php

Lines changed: 2 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77

88
namespace SprykerTest\Yves\Testify\Helper;
99

10-
use Codeception\Configuration;
1110
use Codeception\Module;
1211
use Codeception\Stub;
1312
use Codeception\TestInterface;
@@ -18,23 +17,20 @@
1817
use SprykerTest\Shared\Testify\Helper\ClassResolverTrait;
1918
use SprykerTest\Shared\Testify\Helper\ConfigHelper;
2019
use SprykerTest\Shared\Testify\Helper\ConfigHelperTrait;
20+
use SprykerTest\Shared\Testify\Helper\ModuleNameTrait;
2121

2222
class FactoryHelper extends Module
2323
{
2424
use DependencyProviderHelperTrait;
2525
use ConfigHelperTrait;
2626
use ClassResolverTrait;
27+
use ModuleNameTrait;
2728

2829
/**
2930
* @var string
3031
*/
3132
protected const FACTORY_CLASS_NAME_PATTERN = '\%1$s\Yves\%3$s\%3$sFactory';
3233

33-
/**
34-
* @var int
35-
*/
36-
protected const MODULE_NAME_POSITION = 2;
37-
3834
/**
3935
* @var array<\Spryker\Yves\Kernel\AbstractFactory>
4036
*/
@@ -99,23 +95,6 @@ public function getFactory(?string $moduleName = null): AbstractFactory
9995
return $moduleFactory;
10096
}
10197

102-
/**
103-
* @param string|null $moduleName
104-
*
105-
* @return string
106-
*/
107-
protected function getModuleName(?string $moduleName = null): string
108-
{
109-
if ($moduleName) {
110-
return $moduleName;
111-
}
112-
113-
$config = Configuration::config();
114-
$namespaceParts = explode('\\', $config['namespace']);
115-
116-
return $namespaceParts[static::MODULE_NAME_POSITION];
117-
}
118-
11998
/**
12099
* @param string|null $moduleName
121100
*

0 commit comments

Comments
 (0)