SeleniumTestTrait   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 31
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 2

Importance

Changes 0
Metric Value
dl 0
loc 31
rs 10
c 0
b 0
f 0
wmc 3
lcom 0
cbo 2

2 Methods

Rating   Name   Duplication   Size   Complexity  
A setUpWebDriver() 0 13 2
A getWebDriverSession() 0 4 1
1
<?php
2
/**
3
 * Webino (http://webino.sk/)
4
 *
5
 * @link        https://github.com/webino/WebinoDev/ for the canonical source repository
6
 * @copyright   Copyright (c) 2012-2019 Webino, s. r. o. (http://webino.sk/)
7
 * @license     BSD-3-Clause
8
 */
9
10
namespace WebinoDev\Test\Functional;
11
12
use PHPUnit_Framework_MockObject_MockObject as MockObject;
13
use PHPWebDriver_WebDriver as WebDriver;
14
use WebinoDev\Test\Selenium\WebDriver\TestSession;
15
use WebinoDev\Test\Selenium\WebDriver\TestWebDriver;
16
use WebinoDev\Test\Selenium\WebDriver\TestWindow;
17
18
/**
19
 * Trait for selenium tests functional testing
20
 */
21
trait SeleniumTestTrait
22
{
23
    /**
24
     * Setup Selenium WebDriver mock with session
25
     *
26
     * @return $this
27
     */
28
    public function setUpWebDriver()
29
    {
30
        TestWebDriver::$session = $this->getMock(TestSession::class);
0 ignored issues
show
Bug introduced by
It seems like getMock() must be provided by classes using this trait. How about adding it as abstract method to this trait?

This check looks for methods that are used by a trait but not required by it.

To illustrate, let’s look at the following code example

trait Idable {
    public function equalIds(Idable $other) {
        return $this->getId() === $other->getId();
    }
}

The trait Idable provides a method equalsId that in turn relies on the method getId(). If this method does not exist on a class mixing in this trait, the method will fail.

Adding the getId() as an abstract method to the trait will make sure it is available.

Loading history...
31
        TestWebDriver::$session
32
            ->expects($this->any())
0 ignored issues
show
Bug introduced by
It seems like any() must be provided by classes using this trait. How about adding it as abstract method to this trait?

This check looks for methods that are used by a trait but not required by it.

To illustrate, let’s look at the following code example

trait Idable {
    public function equalIds(Idable $other) {
        return $this->getId() === $other->getId();
    }
}

The trait Idable provides a method equalsId that in turn relies on the method getId(). If this method does not exist on a class mixing in this trait, the method will fail.

Adding the getId() as an abstract method to the trait will make sure it is available.

Loading history...
33
            ->method('window')
34
            ->will($this->returnValue(new TestWindow));
0 ignored issues
show
Bug introduced by
It seems like returnValue() must be provided by classes using this trait. How about adding it as abstract method to this trait?

This check looks for methods that are used by a trait but not required by it.

To illustrate, let’s look at the following code example

trait Idable {
    public function equalIds(Idable $other) {
        return $this->getId() === $other->getId();
    }
}

The trait Idable provides a method equalsId that in turn relies on the method getId(). If this method does not exist on a class mixing in this trait, the method will fail.

Adding the getId() as an abstract method to the trait will make sure it is available.

Loading history...
35
36
        class_exists(WebDriver::class, false)
37
            or class_alias(TestWebDriver::class, WebDriver::class);
38
39
        return $this;
40
    }
41
42
    /**
43
     * Returns Selenium WebDriver session mock
44
     *
45
     * @return \PHPWebDriver_WebDriverSession|\WebinoDev\Test\Selenium\WebDriver\SessionInterface|MockObject
46
     */
47
    public function getWebDriverSession()
48
    {
49
        return TestWebDriver::$session;
50
    }
51
}
52