Completed
Pull Request — master (#112)
by Christophe
03:09
created

YamlFileLoaderTest   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 61
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 5

Importance

Changes 2
Bugs 1 Features 1
Metric Value
c 2
b 1
f 1
dl 0
loc 61
wmc 3
lcom 1
cbo 5
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
B testLoadAddition() 0 42 1
A setUp() 0 4 1
A testSupports() 0 8 1
1
<?php
2
3
namespace Tests\Behat\Gherkin\Loader;
4
5
use Behat\Gherkin\Loader\YamlFileLoader;
6
7
class YamlFileLoaderTest extends \PHPUnit_Framework_TestCase
8
{
9
    private $loader;
10
11
    protected function setUp()
12
    {
13
        $this->loader = new YamlFileLoader();
14
    }
15
16
    public function testSupports()
17
    {
18
        $this->assertFalse($this->loader->supports(__DIR__));
19
        $this->assertFalse($this->loader->supports(__FILE__));
20
        $this->assertFalse($this->loader->supports('string'));
21
        $this->assertFalse($this->loader->supports(__DIR__ . '/file.yml'));
22
        $this->assertTrue($this->loader->supports(__DIR__ . '/../Fixtures/etalons/addition.yml'));
23
    }
24
25
    public function testLoadAddition()
26
    {
27
        $this->loader->setBasePath(__DIR__ . '/../Fixtures');
28
        $features = $this->loader->load('etalons/addition.yml');
29
30
        $this->assertEquals(1, count($features));
31
        $this->assertEquals('etalons'.DIRECTORY_SEPARATOR.'addition.yml', $features[0]->getFile());
32
        $this->assertEquals('Addition', $features[0]->getTitle());
33
        $this->assertEquals(2, $features[0]->getLine());
34
        $this->assertEquals('en', $features[0]->getLanguage());
35
        $expectedDescription = <<<EOS
36
In order to avoid silly mistakes
37
As a math idiot
38
I want to be told the sum of two numbers
39
EOS;
40
        $this->assertEquals($expectedDescription, $features[0]->getDescription());
41
42
        $scenarios = $features[0]->getScenarios();
43
44
        $this->assertEquals(2, count($scenarios));
45
        $this->assertInstanceOf('Behat\Gherkin\Node\ScenarioNode', $scenarios[0]);
46
        $this->assertEquals(7, $scenarios[0]->getLine());
47
        $this->assertEquals('Add two numbers', $scenarios[0]->getTitle());
48
        $steps = $scenarios[0]->getSteps();
49
        $this->assertEquals(4, count($steps));
50
        $this->assertEquals(9, $steps[1]->getLine());
51
        $this->assertEquals('And', $steps[1]->getType());
0 ignored issues
show
Deprecated Code introduced by
The method Behat\Gherkin\Node\StepNode::getType() has been deprecated with message: use getKeyword() instead

This method has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.

Loading history...
52
        $this->assertEquals('And', $steps[1]->getKeyword());
53
        $this->assertEquals('Given', $steps[1]->getKeywordType());
54
        $this->assertEquals('I have entered 12 into the calculator', $steps[1]->getText());
55
56
        $this->assertInstanceOf('Behat\Gherkin\Node\ScenarioNode', $scenarios[1]);
57
        $this->assertEquals(13, $scenarios[1]->getLine());
58
        $this->assertEquals('Div two numbers', $scenarios[1]->getTitle());
59
        $steps = $scenarios[1]->getSteps();
60
        $this->assertEquals(4, count($steps));
61
        $this->assertEquals(16, $steps[2]->getLine());
62
        $this->assertEquals('When', $steps[2]->getType());
0 ignored issues
show
Deprecated Code introduced by
The method Behat\Gherkin\Node\StepNode::getType() has been deprecated with message: use getKeyword() instead

This method has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.

Loading history...
63
        $this->assertEquals('When', $steps[2]->getKeyword());
64
        $this->assertEquals('When', $steps[2]->getKeywordType());
65
        $this->assertEquals('I press div', $steps[2]->getText());
66
    }
67
}
68