Passed
Push — master ( 86c65e...d5128a )
by Harry
02:41
created

testPopulateTablesWithExistingTablesDoesNothing()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 10
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 5
nc 1
nop 0
dl 0
loc 10
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace Graze\Sprout\Test\Unit\Parser;
4
5
use Graze\Sprout\Config;
6
use Graze\Sprout\Parser\ParsedSchema;
7
use Graze\Sprout\Parser\SchemaParser;
8
use Graze\Sprout\Parser\TablePopulator;
9
use Graze\Sprout\Test\TestCase;
10
use League\Flysystem\AdapterInterface;
11
use Mockery;
12
13
class TablePopulatorTest extends TestCase
14
{
15
    /** @var TablePopulator */
16
    private $schemaParser;
17
    /** @var mixed */
18
    private $fileSystem;
19
    /** @var mixed */
20
    private $config;
0 ignored issues
show
introduced by
The private property $config is not used, and could be removed.
Loading history...
21
22
    public function setUp()
23
    {
24
        $this->fileSystem = Mockery::mock(AdapterInterface::class);
25
        $this->schemaParser = new TablePopulator($this->fileSystem);
0 ignored issues
show
Bug introduced by
$this->fileSystem of type Mockery\MockInterface is incompatible with the type League\Flysystem\AdapterInterface expected by parameter $filesystem of Graze\Sprout\Parser\TablePopulator::__construct(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

25
        $this->schemaParser = new TablePopulator(/** @scrutinizer ignore-type */ $this->fileSystem);
Loading history...
26
    }
27
28
    public function testPopulateTablesWithExistingTablesDoesNothing()
29
    {
30
        $config = Mockery::mock(Config\SchemaConfigInterface::class);
31
        $parsedSchema = new ParsedSchema($config, '/a/path', ['table1', 'table2']);
0 ignored issues
show
Bug introduced by
$config of type Mockery\MockInterface is incompatible with the type Graze\Sprout\Config\SchemaConfigInterface expected by parameter $schemaConfig of Graze\Sprout\Parser\ParsedSchema::__construct(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

31
        $parsedSchema = new ParsedSchema(/** @scrutinizer ignore-type */ $config, '/a/path', ['table1', 'table2']);
Loading history...
32
33
        $output = $this->schemaParser->populateTables($parsedSchema);
34
35
        $this->assertSame($parsedSchema, $output);
36
37
        $this->assertEquals(['table1', 'table2'], $parsedSchema->getTables());
38
    }
39
40
    public function testPopulateTablesWithNoTablesWillSearchTheFilesystemForTables()
41
    {
42
        $config = Mockery::mock(Config\SchemaConfigInterface::class);
43
        $parsedSchema = new ParsedSchema($config, '/a/path', []);
0 ignored issues
show
Bug introduced by
$config of type Mockery\MockInterface is incompatible with the type Graze\Sprout\Config\SchemaConfigInterface expected by parameter $schemaConfig of Graze\Sprout\Parser\ParsedSchema::__construct(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

43
        $parsedSchema = new ParsedSchema(/** @scrutinizer ignore-type */ $config, '/a/path', []);
Loading history...
44
45
        $this->fileSystem->allows()
46
                         ->has('/a/path')
47
                         ->andReturns(true);
48
49
        $file1 = ['path' => '/a/path/table1.sql', 'size' => 1234];
50
        $file2 = ['path' => '/a/path/table2.sql', 'size' => 1234];
51
52
        $this->fileSystem->allows()
53
                         ->listContents('/a/path')
54
                         ->andReturns([$file1, $file2]);
55
56
        $output = $this->schemaParser->populateTables($parsedSchema);
57
58
        $this->assertSame($parsedSchema, $output);
59
    }
60
61
    public function testPopulateTablesWhenFolderDoesNotExistReturnsNull()
62
    {
63
        $config = Mockery::mock(Config\SchemaConfigInterface::class);
64
        $parsedSchema = new ParsedSchema($config, '/a/path', []);
0 ignored issues
show
Bug introduced by
$config of type Mockery\MockInterface is incompatible with the type Graze\Sprout\Config\SchemaConfigInterface expected by parameter $schemaConfig of Graze\Sprout\Parser\ParsedSchema::__construct(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

64
        $parsedSchema = new ParsedSchema(/** @scrutinizer ignore-type */ $config, '/a/path', []);
Loading history...
65
66
        $this->fileSystem->allows()
67
                         ->has('/a/path')
68
                         ->andReturns(false);
69
70
        $output = $this->schemaParser->populateTables($parsedSchema);
71
72
        $this->assertNull($output);
73
    }
74
75
    public function testPopulateTablesWithNoFilesReturnsNull()
76
    {
77
        $config = Mockery::mock(Config\SchemaConfigInterface::class);
78
        $parsedSchema = new ParsedSchema($config, '/a/path', []);
0 ignored issues
show
Bug introduced by
$config of type Mockery\MockInterface is incompatible with the type Graze\Sprout\Config\SchemaConfigInterface expected by parameter $schemaConfig of Graze\Sprout\Parser\ParsedSchema::__construct(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

78
        $parsedSchema = new ParsedSchema(/** @scrutinizer ignore-type */ $config, '/a/path', []);
Loading history...
79
80
        $this->fileSystem->allows()
81
                         ->has('/a/path')
82
                         ->andReturns(true);
83
84
        $this->fileSystem->allows()
85
                         ->listContents('/a/path')
86
                         ->andReturns([]);
87
88
        $output = $this->schemaParser->populateTables($parsedSchema);
89
90
        $this->assertNull($output);
91
    }
92
}
93