Passed
Pull Request — master (#3)
by Harry
03:37 queued 01:14
created

TablePopulatorTest   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 87
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 48
dl 0
loc 87
rs 10
c 0
b 0
f 0
wmc 5

5 Methods

Rating   Name   Duplication   Size   Complexity  
A testPopulateTablesWithNoFilesReturnsNull() 0 16 1
A testPopulateTablesWithExistingTablesDoesNothing() 0 10 1
A testPopulateTablesWhenFolderDoesNotExistReturnsNull() 0 12 1
A setUp() 0 4 1
A testPopulateTablesWithNoTablesWillSearchTheFilesystemForTables() 0 28 1
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 = Mockery::mock(\SplFileInfo::class);
50
        $file1->allows(['getExtension' => 'sql', 'getSize' => 1234]);
51
        $file1->allows()
52
              ->getBasename('.sql')
0 ignored issues
show
Bug introduced by
The method getBasename() does not exist on Mockery\Expectation. ( Ignorable by Annotation )

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

52
              ->/** @scrutinizer ignore-call */ getBasename('.sql')

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
Bug introduced by
The method getBasename() does not exist on Mockery\ExpectationInterface. It seems like you code against a sub-type of Mockery\ExpectationInterface such as Mockery\CompositeExpectation. ( Ignorable by Annotation )

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

52
              ->/** @scrutinizer ignore-call */ getBasename('.sql')
Loading history...
53
              ->andReturns('table1');
54
55
        $file2 = Mockery::mock(\SplFileInfo::class);
56
        $file2->allows(['getExtension' => 'sql', 'getSize' => 1235]);
57
        $file2->allows()
58
              ->getBasename('.sql')
59
              ->andReturns('table2');
60
61
        $this->fileSystem->allows()
62
                         ->listContents('/a/path')
63
                         ->andReturns([$file1, $file2]);
64
65
        $output = $this->schemaParser->populateTables($parsedSchema);
66
67
        $this->assertSame($parsedSchema, $output);
68
    }
69
70
    public function testPopulateTablesWhenFolderDoesNotExistReturnsNull()
71
    {
72
        $config = Mockery::mock(Config\SchemaConfigInterface::class);
73
        $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

73
        $parsedSchema = new ParsedSchema(/** @scrutinizer ignore-type */ $config, '/a/path', []);
Loading history...
74
75
        $this->fileSystem->allows()
76
                         ->has('/a/path')
77
                         ->andReturns(false);
78
79
        $output = $this->schemaParser->populateTables($parsedSchema);
80
81
        $this->assertNull($output);
82
    }
83
84
    public function testPopulateTablesWithNoFilesReturnsNull()
85
    {
86
        $config = Mockery::mock(Config\SchemaConfigInterface::class);
87
        $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

87
        $parsedSchema = new ParsedSchema(/** @scrutinizer ignore-type */ $config, '/a/path', []);
Loading history...
88
89
        $this->fileSystem->allows()
90
                         ->has('/a/path')
91
                         ->andReturns(true);
92
93
        $this->fileSystem->allows()
94
                         ->listContents('/a/path')
95
                         ->andReturns([]);
96
97
        $output = $this->schemaParser->populateTables($parsedSchema);
98
99
        $this->assertNull($output);
100
    }
101
}
102