-
Notifications
You must be signed in to change notification settings - Fork 132
/
Copy pathHelperContainer.php
66 lines (59 loc) · 1.59 KB
/
HelperContainer.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
declare(strict_types = 1);
namespace Magento\FunctionalTestingFramework\Helper;
use Magento\FunctionalTestingFramework\Exceptions\TestFrameworkException;
/**
* Class HelperContainer
*/
class HelperContainer extends \Codeception\Module
{
/**
* @var Helper[]
*/
private $helpers = [];
/**
* Create custom helper class.
*
* @param string $helperClass
* @return Helper
* @throws \Exception
*/
public function create(string $helperClass): Helper
{
if (get_parent_class($helperClass) !== Helper::class) {
throw new \Exception("Helper class must extend " . Helper::class);
}
if (!isset($this->helpers[$helperClass])) {
$this->helpers[$helperClass] = $this->moduleContainer->create($helperClass);
}
return $this->helpers[$helperClass];
}
/**
* Returns helper object by it's class name.
*
* @param string $className
* @return Helper
* @throws TestFrameworkException
*/
public function get(string $className): Helper
{
if ($this->has($className)) {
return $this->helpers[$className];
}
throw new TestFrameworkException('Custom helper ' . $className . 'not found.');
}
/**
* Verifies that helper object exist.
*
* @param string $className
* @return boolean
*/
public function has(string $className): bool
{
return array_key_exists($className, $this->helpers);
}
}