Test Failed
Push — master ( 440ce5...0cdbc1 )
by Siad
07:01
created

WikiPublishTaskTest::testApiEdit()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 42
Code Lines 30

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 30
nc 1
nop 0
dl 0
loc 42
rs 9.44
c 0
b 0
f 0
1
<?php
2
/*
3
 *
4
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
5
 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
6
 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
7
 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
8
 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
9
 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
10
 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
11
 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
12
 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
13
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
14
 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
15
 *
16
 * This software consists of voluntary contributions made by many individuals
17
 * and is licensed under the LGPL. For more information please see
18
 * <http://phing.info>.
19
 */
20
21
/**
22
 * WikiPublish task test
23
 * @author  Piotr Lewandowski <[email protected]>
24
 * @package phing.tasks.ext
25
 */
26
class WikiPublishTaskTest extends BuildFileTest
27
{
28
29
    /**
30
     * Test Wiki api success request and response sequence
31
     */
32
    public function testApiEdit()
33
    {
34
        $task = $this->getWikiPublishMock();
35
36
        $task->setApiUrl('http://localhost/testApi.php');
37
        $task->setApiUser('testUser');
38
        $task->setApiPassword('testPassword');
39
40
        $task->setTitle('some page');
41
        $task->setContent('some content');
42
        $task->setMode('prepend');
43
44
        $task->expects($this->at(0))
0 ignored issues
show
Bug introduced by
The method expects() does not exist on WikiPublishTask. ( Ignorable by Annotation )

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

44
        $task->/** @scrutinizer ignore-call */ 
45
               expects($this->at(0))

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...
45
            ->method('callApi')
46
            ->with(
47
                'action=login',
48
                ['lgname' => 'testUser', 'lgpassword' => 'testPassword']
49
            )
50
            ->will($this->returnValue(['login' => ['result' => 'NeedToken', 'token' => 'testLgToken']]));
51
52
        $task->expects($this->at(1))
53
            ->method('callApi')
54
            ->with(
55
                'action=login',
56
                ['lgname' => 'testUser', 'lgpassword' => 'testPassword', 'lgtoken' => 'testLgToken']
57
            )
58
            ->will($this->returnValue(['login' => ['result' => 'Success']]));
59
60
        $task->expects($this->at(2))
61
            ->method('callApi')
62
            ->with('action=tokens&type=edit')
63
            ->will($this->returnValue(['tokens' => ['edittoken' => 'testEditToken+/']]));
64
65
        $task->expects($this->at(3))
66
            ->method('callApi')
67
            ->with(
68
                'action=edit&token=testEditToken%2B%2F',
69
                ['minor' => '', 'title' => 'some page', 'prependtext' => 'some content']
70
            )
71
            ->will($this->returnValue(['edit' => ['result' => 'Success']]));
72
73
        $task->main();
74
    }
75
76
    /**
77
     * Test invalid input attributes
78
     */
79
    public function testInvalidAttributes()
80
    {
81
        $task = $this->getWikiPublishMock();
82
83
        try {
84
            $task->main();
85
        } catch (BuildException $e) {
86
            $this->assertEquals('Wiki apiUrl is required', $e->getMessage());
87
        }
88
89
        $task->setApiUrl('http://localhost/testApi.php');
90
        try {
91
            $task->main();
92
        } catch (BuildException $e) {
93
            $this->assertEquals('Wiki page id or title is required', $e->getMessage());
94
        }
95
    }
96
97
    /**
98
     * Creates WikiPublishTask mock
99
     * @return WikiPublishTask
100
     */
101
    private function getWikiPublishMock()
102
    {
103
        $result = $this->getMockBuilder('WikiPublishTask');
104
105
        return $result->setMethods(['callApi'])->getMock();
0 ignored issues
show
Bug Best Practice introduced by
The expression return $result->setMetho...('callApi'))->getMock() returns the type PHPUnit\Framework\MockObject\MockObject which is incompatible with the documented return type WikiPublishTask.
Loading history...
106
    }
107
}
108