Passed
Push — develop ( 28c299...928e2a )
by Mathias
12:40
created

CommonContextTrait   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 81
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Importance

Changes 0
Metric Value
wmc 6
lcom 1
cbo 0
dl 0
loc 81
rs 10
c 0
b 0
f 0
1
<?php
2
/**
3
 * YAWIK
4
 *
5
 * @filesource
6
 * @license MIT
7
 * @copyright  2013 - 2017 Cross Solution <http://cross-solution.de>
8
 */
9
10
namespace Yawik\Behat;
11
12
13
use Auth\Entity\User;
14
use Behat\Behat\Hook\Scope\BeforeScenarioScope;
15
use Behat\MinkExtension\Context\MinkContext;
16
use Core\Repository\RepositoryInterface;
17
use Zend\View\Helper\Url;
18
19
trait CommonContextTrait
20
{
21
	/**
22
	 * @var MinkContext
23
	 */
24
	protected $minkContext;
25
	
26
	/**
27
	 * @var CoreContext
28
	 */
29
	protected $coreContext;
30
	
31
	/**
32
	 * @var UserContext
33
	 */
34
	protected $userContext;
35
	
36
	/**
37
	 * @var SummaryFormContext
38
	 */
39
	protected $summaryFormContext;
40
	
41
	/**
42
	 * @BeforeScenario
43
	 *
44
	 * @param BeforeScenarioScope $scope
45
	 */
46
	final public function gatherContexts(BeforeScenarioScope $scope)
47
	{
48
		$this->minkContext = $scope->getEnvironment()->getContext(MinkContext::class);
49
		$this->coreContext = $scope->getEnvironment()->getContext(CoreContext::class);
50
		$this->userContext = $scope->getEnvironment()->getContext(UserContext::class);
51
		$this->summaryFormContext = $scope->getEnvironment()->getContext(SummaryFormContext::class);
52
	}
53
	
54
	public function buildUrl($name, array $params=array(), array $options=array())
55
	{
56
	    $defaults = ['lang'=>'en'];
57
	    $params = array_merge($defaults,$params);
58
        /* @var Url $urlHelper */
59
        $urlHelper = $this
60
            ->getService('ViewHelperManager')
61
            ->get('url')
62
        ;
63
        $url = $urlHelper($name,$params,$options);
64
65
        return $this->coreContext->generateUrl($url);
66
	}
67
	
68
	public function visit($url)
69
	{
70
		$this->coreContext->iVisit($url);
71
	}
72
	
73
	/**
74
	 * @param $id
75
	 * @return mixed|object
76
	 */
77
	public function getService($id)
78
	{
79
		return $this->coreContext->getServiceManager()->get($id);
80
	}
81
	
82
	/**
83
	 * @param $id
84
	 *
85
	 * @return RepositoryInterface
86
	 */
87
	public function getRepository($id)
88
	{
89
		return $this->coreContext->getRepositories()->get($id);
90
	}
91
92
    /**
93
     * @return UserContext
94
     */
95
	public function getUserContext()
96
    {
97
        return $this->userContext;
98
    }
99
}
100