Completed
Push — master ( 9af361...a55b85 )
by Rafał
09:23
created

CsvFileContext::theCsvFileShouldContainElements()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 11

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 11
rs 9.9
c 0
b 0
f 0
cc 2
nc 2
nop 2
1
<?php
2
3
declare(strict_types=1);
4
5
namespace SWP\Behat\Contexts;
6
7
use Behatch\Context\BaseContext;
8
use SplFileObject;
9
10
class CsvFileContext extends BaseContext
11
{
12
    /** @var string */
13
    private $projectDir;
14
15
    public function __construct(string $projectDir)
16
    {
17
        $this->projectDir = $projectDir;
18
    }
19
20
    /**
21
     * @Given the CSV file :path should contain :number rows
22
     * @Given the CSV file :path should contain :number row
23
     */
24
    public function theCsvFileShouldContainElements(string $path, int $number): void
25
    {
26
        $file = new SplFileObject($this->projectDir.$path, 'r');
27
28
        $file->seek(PHP_INT_MAX);
29
        $elements = $file->key() + 1;
30
31
        if ($elements !== $number) {
32
            throw new \Exception("The file contains $elements rows but expected $number!");
33
        }
34
    }
35
}
36