YamlFileLoaderTest::testSupports()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 8
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 0
1
<?php
2
3
namespace Tests\Behat\Gherkin\Loader;
4
5
use Behat\Gherkin\Loader\YamlFileLoader;
6
use PHPUnit\Framework\TestCase;
7
8
class YamlFileLoaderTest extends TestCase
9
{
10
    private $loader;
11
12
    protected function setUp()
13
    {
14
        $this->loader = new YamlFileLoader();
15
    }
16
17
    public function testSupports()
18
    {
19
        $this->assertFalse($this->loader->supports(__DIR__));
20
        $this->assertFalse($this->loader->supports(__FILE__));
21
        $this->assertFalse($this->loader->supports('string'));
22
        $this->assertFalse($this->loader->supports(__DIR__ . '/file.yml'));
23
        $this->assertTrue($this->loader->supports(__DIR__ . '/../Fixtures/etalons/addition.yml'));
24
    }
25
26
    public function testLoadAddition()
27
    {
28
        $basePath = __DIR__ . '/../Fixtures';
29
        $this->loader->setBasePath($basePath);
30
        $features = $this->loader->load('etalons/addition.yml');
31
32
        $this->assertEquals(1, count($features));
33
        $this->assertEquals(realpath($basePath . DIRECTORY_SEPARATOR . 'etalons' . DIRECTORY_SEPARATOR . 'addition.yml'), $features[0]->getFile());
34
        $this->assertEquals('Addition', $features[0]->getTitle());
35
        $this->assertEquals(2, $features[0]->getLine());
36
        $this->assertEquals('en', $features[0]->getLanguage());
37
        $expectedDescription = <<<EOS
38
In order to avoid silly mistakes
39
As a math idiot
40
I want to be told the sum of two numbers
41
EOS;
42
        $this->assertEquals($expectedDescription, $features[0]->getDescription());
43
44
        $scenarios = $features[0]->getScenarios();
45
46
        $this->assertEquals(2, count($scenarios));
47
        $this->assertInstanceOf('Behat\Gherkin\Node\ScenarioNode', $scenarios[0]);
48
        $this->assertEquals(7, $scenarios[0]->getLine());
49
        $this->assertEquals('Add two numbers', $scenarios[0]->getTitle());
50
        $steps = $scenarios[0]->getSteps();
51
        $this->assertEquals(4, count($steps));
52
        $this->assertEquals(9, $steps[1]->getLine());
53
        $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...
54
        $this->assertEquals('And', $steps[1]->getKeyword());
55
        $this->assertEquals('Given', $steps[1]->getKeywordType());
56
        $this->assertEquals('I have entered 12 into the calculator', $steps[1]->getText());
57
58
        $this->assertInstanceOf('Behat\Gherkin\Node\ScenarioNode', $scenarios[1]);
59
        $this->assertEquals(13, $scenarios[1]->getLine());
60
        $this->assertEquals('Div two numbers', $scenarios[1]->getTitle());
61
        $steps = $scenarios[1]->getSteps();
62
        $this->assertEquals(4, count($steps));
63
        $this->assertEquals(16, $steps[2]->getLine());
64
        $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...
65
        $this->assertEquals('When', $steps[2]->getKeyword());
66
        $this->assertEquals('When', $steps[2]->getKeywordType());
67
        $this->assertEquals('I press div', $steps[2]->getText());
68
    }
69
}
70