HgTest::testHgStackCommandsWithTagMessage()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 15

Duplication

Lines 15
Ratio 100 %

Importance

Changes 0
Metric Value
dl 15
loc 15
rs 9.7666
c 0
b 0
f 0
cc 1
nc 1
nop 0
1
<?php
2
3
use AspectMock\Test as test;
0 ignored issues
show
Bug introduced by
This use statement conflicts with another class in this namespace, test.

Let’s assume that you have a directory layout like this:

.
|-- OtherDir
|   |-- Bar.php
|   `-- Foo.php
`-- SomeDir
    `-- Foo.php

and let’s assume the following content of Bar.php:

// Bar.php
namespace OtherDir;

use SomeDir\Foo; // This now conflicts the class OtherDir\Foo

If both files OtherDir/Foo.php and SomeDir/Foo.php are loaded in the same runtime, you will see a PHP error such as the following:

PHP Fatal error:  Cannot use SomeDir\Foo as Foo because the name is already in use in OtherDir/Foo.php

However, as OtherDir/Foo.php does not necessarily have to be loaded and the error is only triggered if it is loaded before OtherDir/Bar.php, this problem might go unnoticed for a while. In order to prevent this error from surfacing, you must import the namespace with a different alias:

// Bar.php
namespace OtherDir;

use SomeDir\Foo as SomeDirFoo; // There is no conflict anymore.
Loading history...
4
5
class HgTest extends \Codeception\TestCase\Test
6
{
7
    /**
8
     * @var \AspectMock\Proxy\ClassProxy
9
     */
10
    protected $hg;
11
12
    /**
13
     * @var \Robo\Task\Vcs\HgStack
14
     */
15
    protected $hgStack;
16
17
    protected function _before()
18
    {
19
        $this->hg = Test::double('Robo\Task\Vcs\HgStack', [
20
            'executeCommand' => new \AspectMock\Proxy\Anything(),
21
            'output' => new \Symfony\Component\Console\Output\NullOutput(),
22
            'logger' => new \Psr\Log\NullLogger(),
23
        ]);
24
        $this->hgStack = (new \Robo\Task\Vcs\HgStack('hg'));
25
    }
26
27
    // tests
28
    public function testHgStackRun()
29
    {
30
        $this->hgStack->stopOnFail()->add()->pull()->run();
31
        $this->hg->verifyInvoked('executeCommand', ['hg add']);
32
        $this->hg->verifyInvoked('executeCommand', ['hg pull']);
33
34
        (new \Robo\Task\Vcs\HgStack('hg'))->add()->pull()->run();
35
        $this->hg->verifyInvoked('executeCommand', ['hg add && hg pull']);
36
    }
37
38
    public function testHgStackPull()
39
    {
40
        $this->assertEquals(
41
            'hg pull',
42
            $this->hgStack
43
                ->pull()
44
                ->getCommand()
45
        );
46
    }
47
48
    public function testHgStackAddFiles()
49
    {
50
        $this->assertEquals(
51
            'hg add -I *.php -X *.css',
52
            $this->hgStack
53
                ->add('*.php', '*.css')
54
                ->getCommand()
55
        );
56
    }
57
58 View Code Duplication
    public function testHgStackCommands()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
59
    {
60
        $this->assertEquals(
61
            "hg clone https://bitbucket.org/durin42/hgsubversion && hg pull && hg add && hg commit -m 'changed' && hg push && hg tag 0.6.0 && hg push -b '0.6.0'",
62
            $this->hgStack
63
                ->cloneRepo('https://bitbucket.org/durin42/hgsubversion')
64
                ->pull()
65
                ->add()
66
                ->commit('changed')
67
                ->push()
68
                ->tag('0.6.0')
69
                ->push('0.6.0')
70
                ->getCommand()
71
        );
72
    }
73
74 View Code Duplication
    public function testHgStackCommandsWithTagMessage()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
75
    {
76
        $this->assertEquals(
77
            "hg clone https://bitbucket.org/durin42/hgsubversion && hg pull && hg add && hg commit -m 'changed' && hg push && hg tag -m 'message' 0.6.0 && hg push -b '0.6.0'",
78
            $this->hgStack
79
                ->cloneRepo('https://bitbucket.org/durin42/hgsubversion')
80
                ->pull()
81
                ->add()
82
                ->commit('changed')
83
                ->push()
84
                ->tag('0.6.0', 'message')
85
                ->push('0.6.0')
86
                ->getCommand()
87
        );
88
    }
89
}
90