Completed
Push — dev ( 94208d...ada7da )
by James Ekow Abaka
02:35
created

NegativeMockAssertor   A

Complexity

Total Complexity 1

Size/Duplication

Total Lines 6
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
dl 0
loc 6
rs 10
c 0
b 0
f 0
wmc 1

1 Method

Rating   Name   Duplication   Size   Complexity  
A __call() 0 3 1
1
<?php
2
3
/*
4
 * The MIT License
5
 *
6
 * Copyright 2014 ekow.
7
 *
8
 * Permission is hereby granted, free of charge, to any person obtaining a copy
9
 * of this software and associated documentation files (the "Software"), to deal
10
 * in the Software without restriction, including without limitation the rights
11
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
12
 * copies of the Software, and to permit persons to whom the Software is
13
 * furnished to do so, subject to the following conditions:
14
 *
15
 * The above copyright notice and this permission notice shall be included in
16
 * all copies or substantial portions of the Software.
17
 *
18
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
21
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
23
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
24
 * THE SOFTWARE.
25
 */
26
27
namespace yentu\tests\cases;
28
29
use org\bovigo\vfs\vfsStream;
30
use yentu\commands\Import;
31
32
class ImportTest extends \yentu\tests\YentuTest
33
{
34
35
    public function setUp()
36
    {
37
        $this->testDatabase = 'yentu_import_test';
38
        parent::setup();
39
        $this->createDb($GLOBALS['DB_NAME']);
40
        $this->initYentu($GLOBALS['DB_NAME']);
41
    }
42
43
    public function testImport()
44
    {
45
        $this->initDb($GLOBALS['DB_FULL_DSN'], file_get_contents("tests/sql/{$GLOBALS['DRIVER']}/system.sql"));
46
        $codeWriter = $this->createMock('\\yentu\\CodeWriter', array('getTimestamp'));
0 ignored issues
show
Unused Code introduced by
The call to PHPUnit\Framework\TestCase::createMock() has too many arguments starting with array('getTimestamp'). ( Ignorable by Annotation )

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

46
        /** @scrutinizer ignore-call */ 
47
        $codeWriter = $this->createMock('\\yentu\\CodeWriter', array('getTimestamp'));

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress. Please note the @ignore annotation hint above.

Loading history...
47
        $codeWriter->method('getTimestamp')->willReturn('25th August, 2014 14:30:13');
0 ignored issues
show
Bug introduced by
The method method() does not exist on PHPUnit\Framework\MockObject\MockObject. ( Ignorable by Annotation )

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

47
        $codeWriter->/** @scrutinizer ignore-call */ 
48
                     method('getTimestamp')->willReturn('25th August, 2014 14:30:13');

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...
48
49
        $import = new Import($this->yentu, $this->getManipulatorFactory(), $this->io);
50
        $import->setCodeWriter($codeWriter);
51
        $description = $import->run(array());
0 ignored issues
show
Unused Code introduced by
The call to yentu\commands\Import::run() has too many arguments starting with array(). ( Ignorable by Annotation )

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

51
        /** @scrutinizer ignore-call */ 
52
        $description = $import->run(array());

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress. Please note the @ignore annotation hint above.

Loading history...
52
        $newVersion = $import->getNewVersion();
53
        $this->assertFileExists(
54
            vfsStream::url("home/yentu/migrations/{$newVersion}_import.php")
55
        );
56
57
        require "tests/expected/{$GLOBALS['DRIVER']}/import.php";
58
        $descriptionArray = $description->getArray();
59
60
        unset($descriptionArray['tables']['yentu_history']);
61
        $this->assertEquals(
62
            $expectedDescription, [
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable $expectedDescription seems to be never defined.
Loading history...
63
            'schemata' => $descriptionArray['schemata'],
64
            'tables' => $descriptionArray['tables'],
65
            'views' => $descriptionArray['views']
66
        ]);
67
    }
68
69
    public function testSchemaImport()
70
    {
71
        $this->skipSchemaTests();
72
        $this->connect($GLOBALS['DB_FULL_DSN']);
73
        $this->pdo->query('DROP SCHEMA IF EXISTS hr');
74
        $this->pdo->query('DROP SCHEMA IF EXISTS common');
75
76
        $this->initDb($GLOBALS['DB_FULL_DSN'], file_get_contents("tests/sql/{$GLOBALS['DRIVER']}/import_schema.sql"));
77
        $this->connect($GLOBALS['DB_FULL_DSN']);
78
79
        $codeWriter = $this->createMock('\\yentu\\CodeWriter', array('getTimestamp'));
0 ignored issues
show
Unused Code introduced by
The call to PHPUnit\Framework\TestCase::createMock() has too many arguments starting with array('getTimestamp'). ( Ignorable by Annotation )

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

79
        /** @scrutinizer ignore-call */ 
80
        $codeWriter = $this->createMock('\\yentu\\CodeWriter', array('getTimestamp'));

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress. Please note the @ignore annotation hint above.

Loading history...
80
        $codeWriter->method('getTimestamp')->willReturn('25th August, 2014 14:30:13');
81
        $import = new Import($this->yentu, $this->getManipulatorFactory(), $this->io);
82
        $import->setCodeWriter($codeWriter);
83
        $import->run(array());
0 ignored issues
show
Unused Code introduced by
The call to yentu\commands\Import::run() has too many arguments starting with array(). ( Ignorable by Annotation )

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

83
        $import->/** @scrutinizer ignore-call */ 
84
                 run(array());

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress. Please note the @ignore annotation hint above.

Loading history...
84
        $newVersion = $import->getNewVersion();
85
        $this->assertFileExists(
86
            vfsStream::url("home/yentu/migrations/{$newVersion}_import.php")
87
        );
88
        $this->assertSchemaExists('common');
89
        $this->assertSchemaExists('hr');
90
    }
91
92
    public function testViewImport()
93
    {
94
        $this->initDb($GLOBALS['DB_FULL_DSN'], file_get_contents("tests/sql/{$GLOBALS['DRIVER']}/import_views.sql"));
95
        $this->connect($GLOBALS['DB_FULL_DSN']);
96
97
        $codeWriter = $this->createMock('\\yentu\\CodeWriter', array('getTimestamp'));
0 ignored issues
show
Unused Code introduced by
The call to PHPUnit\Framework\TestCase::createMock() has too many arguments starting with array('getTimestamp'). ( Ignorable by Annotation )

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

97
        /** @scrutinizer ignore-call */ 
98
        $codeWriter = $this->createMock('\\yentu\\CodeWriter', array('getTimestamp'));

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress. Please note the @ignore annotation hint above.

Loading history...
98
        $codeWriter->method('getTimestamp')->willReturn('25th August, 2014 14:30:13');
99
        $import = new Import($this->yentu, $this->getManipulatorFactory(), $this->io);
100
        $import->setCodeWriter($codeWriter);
101
        $import->run(array());
0 ignored issues
show
Unused Code introduced by
The call to yentu\commands\Import::run() has too many arguments starting with array(). ( Ignorable by Annotation )

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

101
        $import->/** @scrutinizer ignore-call */ 
102
                 run(array());

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress. Please note the @ignore annotation hint above.

Loading history...
102
        $newVersion = $import->getNewVersion();
103
        $this->assertFileExists(
104
            vfsStream::url("home/yentu/migrations/{$newVersion}_import.php")
105
        );
106
107
        $this->assertTableExists('employees_view');
108
        $this->assertTableExists('disabled_employees_view');
109
    }
110
111
    /**
112
     * @expectedException \yentu\exceptions\CommandException
113
     */
114
    public function testImportNonEmptyMigrations()
115
    {
116
        file_put_contents(vfsStream::url('home/yentu/migrations/1234568901234_existing.php'), 'nothing');
117
        $import = new Import($this->yentu, $this->getManipulatorFactory(), $this->io);
118
        $import->run(array());
0 ignored issues
show
Unused Code introduced by
The call to yentu\commands\Import::run() has too many arguments starting with array(). ( Ignorable by Annotation )

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

118
        $import->/** @scrutinizer ignore-call */ 
119
                 run(array());

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress. Please note the @ignore annotation hint above.

Loading history...
119
    }
120
121
    public function testDatabaseNotExisting()
122
    {
123
        $this->skipSchemaTests();
124
        $this->connect($GLOBALS['DB_FULL_DSN']);
125
        try {
126
            $this->pdo->query('DROP TABLE IF EXISTS yentu_history');
127
            $this->pdo->query('DROP SEQUENCE IF EXISTS yentu_history_id_seq');
128
        } catch (\PDOException $e) {
0 ignored issues
show
Coding Style Comprehensibility introduced by
Consider adding a comment why this CATCH block is empty.
Loading history...
129
            
130
        }
131
        $import = new Import($this->yentu, $this->getManipulatorFactory(), $this->io);
132
        $import->run(array());
0 ignored issues
show
Unused Code introduced by
The call to yentu\commands\Import::run() has too many arguments starting with array(). ( Ignorable by Annotation )

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

132
        $import->/** @scrutinizer ignore-call */ 
133
                 run(array());

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress. Please note the @ignore annotation hint above.

Loading history...
133
        $this->assertTableExists('yentu_history');
134
    }
135
136
}
137
138
class NegativeMockAssertor
139
{
140
141
    public function __call($name, $arguments)
142
    {
143
        return false;
144
    }
145
146
}
147