Passed
Push — master ( 813fe9...62056b )
by Sebastian
06:01
created

ConfiguratorTest   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 70
Duplicated Lines 30 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 4
c 1
b 0
f 0
lcom 1
cbo 2
dl 21
loc 70
rs 10

4 Methods

Rating   Name   Duplication   Size   Complexity  
A testConfigureCliHook() 10 10 1
A testConfigurePHPHook() 0 11 1
A testConfigureFileExists() 11 11 1
A testConfigureFileExtend() 0 17 1

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

1
<?php
2
/**
3
 * This file is part of CaptainHook.
4
 *
5
 * (c) Sebastian Feldmann <[email protected]>
6
 *
7
 * For the full copyright and license information, please view the LICENSE
8
 * file that was distributed with this source code.
9
 */
10
namespace CaptainHook\App\Runner;
11
12
class ConfiguratorTest extends BaseTestRunner
13
{
14
    /**
15
     * Tests Installer::installHook
16
     */
17 View Code Duplication
    public function testConfigureCliHook()
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...
18
    {
19
        $io     = $this->getIOMock();
20
        $config = $this->getConfigMock();
21
        $repo   = $this->getRepositoryMock();
22
        $runner = new Configurator($io, $config, $repo);
23
        $config->method('getHookConfig')->willReturn($this->getHookConfigMock());
0 ignored issues
show
Bug introduced by
The method method() does not seem to exist on object<CaptainHook\App\Config>.

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...
24
        $io->method('ask')->will($this->onConsecutiveCalls('y', 'y', 'echo \'foo\'', 'n'));
0 ignored issues
show
Bug introduced by
The method method() does not seem to exist on object<CaptainHook\App\Console\IO\DefaultIO>.

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...
25
        $runner->configureHook($config, 'pre-push', true);
0 ignored issues
show
Unused Code introduced by
The call to Configurator::configureHook() has too many arguments starting with true.

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.

In this case you can add the @ignore PhpDoc annotation to the duplicate definition and it will be ignored.

Loading history...
26
    }
27
28
    /**
29
     * Tests Installer::installHook
30
     */
31
    public function testConfigurePHPHook()
32
    {
33
        $io     = $this->getIOMock();
34
        $config = $this->getConfigMock();
35
        $repo   = $this->getRepositoryMock();
36
        $runner = new Configurator($io, $config, $repo);
37
        $config->method('getHookConfig')->willReturn($this->getHookConfigMock());
0 ignored issues
show
Bug introduced by
The method method() does not seem to exist on object<CaptainHook\App\Config>.

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...
38
        $io->method('ask')->will($this->onConsecutiveCalls('y', 'y', '\\Foo\\Bar', 'y', 'n'));
0 ignored issues
show
Bug introduced by
The method method() does not seem to exist on object<CaptainHook\App\Console\IO\DefaultIO>.

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...
39
        $io->expects($this->once())->method('askAndValidate')->willReturn('foo:bar');
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<CaptainHook\App\Console\IO\DefaultIO>.

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...
40
        $runner->configureHook($config, 'pre-push', true);
0 ignored issues
show
Unused Code introduced by
The call to Configurator::configureHook() has too many arguments starting with true.

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.

In this case you can add the @ignore PhpDoc annotation to the duplicate definition and it will be ignored.

Loading history...
41
    }
42
43
    /**
44
     * Tests Installer::installHook
45
     *
46
     * @expectedException \Exception
47
     */
48 View Code Duplication
    public function testConfigureFileExists()
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...
49
    {
50
        $io     = $this->getIOMock();
51
        $config = $this->getConfigMock();
52
        $repo   = $this->getRepositoryMock();
53
        $runner = new Configurator($io, $config, $repo);
54
        $config->expects($this->once())->method('isLoadedFromFile')->willReturn(true);
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<CaptainHook\App\Config>.

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...
55
        $io->method('ask')->will($this->onConsecutiveCalls('y', 'y', '\\Foo\\Bar', 'y', 'n'));
0 ignored issues
show
Bug introduced by
The method method() does not seem to exist on object<CaptainHook\App\Console\IO\DefaultIO>.

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...
56
        $runner->run();
57
58
    }
59
60
61
    /**
62
     * Tests Installer::installHook
63
     */
64
    public function testConfigureFileExtend()
65
    {
66
        $path   = sys_get_temp_dir() . DIRECTORY_SEPARATOR . md5(__FILE__);
67
        $io     = $this->getIOMock();
68
        $config = $this->getConfigMock();
69
        $repo   = $this->getRepositoryMock();
70
        $runner = new Configurator($io, $config, $repo);
71
        $config->method('getHookConfig')->willReturn($this->getHookConfigMock());
0 ignored issues
show
Bug introduced by
The method method() does not seem to exist on object<CaptainHook\App\Config>.

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...
72
        $config->method('getPath')->willReturn($path);
0 ignored issues
show
Bug introduced by
The method method() does not seem to exist on object<CaptainHook\App\Config>.

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...
73
        $io->method('ask')->will($this->onConsecutiveCalls('y', 'y', '\\Foo\\Bar', 'y', 'n'));
0 ignored issues
show
Bug introduced by
The method method() does not seem to exist on object<CaptainHook\App\Console\IO\DefaultIO>.

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...
74
        $io->expects($this->once())->method('askAndValidate')->willReturn('foo:bar');
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<CaptainHook\App\Console\IO\DefaultIO>.

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...
75
        $runner->extend(true);
76
        $runner->run();
77
78
        $this->assertTrue(file_exists($path));
79
        unlink($path);
80
    }
81
}
82