Passed
Push — master ( b89ee9...82ea21 )
by Sebastian
03:18
created

CreatorTest   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 51
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 2
eloc 27
c 0
b 0
f 0
dl 0
loc 51
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A testFailConfigFileExists() 0 11 1
A testConfigureFileExtend() 0 22 1
1
<?php
2
3
/**
4
 * This file is part of CaptainHook
5
 *
6
 * (c) Sebastian Feldmann <[email protected]>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace CaptainHook\App\Runner\Config;
13
14
use CaptainHook\App\Config\Mockery as ConfigMockery;
15
use CaptainHook\App\Config;
16
use CaptainHook\App\Console\IO\Mockery as IOMockery;
17
use CaptainHook\App\Mockery as CHMockery;
18
use Exception;
19
use org\bovigo\vfs\vfsStream;
20
use PHPUnit\Framework\TestCase;
1 ignored issue
show
Bug introduced by
The type PHPUnit\Framework\TestCase was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
21
22
class CreatorTest extends TestCase
23
{
24
    use ConfigMockery;
25
    use IOMockery;
26
    use CHMockery;
27
28
    /**
29
     * Tests Creator::run
30
     */
31
    public function testFailConfigFileExists(): void
32
    {
33
        $this->expectException(Exception::class);
34
35
        $config = $this->createConfigMock(true);
36
        $io     = $this->createIOMock();
37
        $io->method('ask')->will($this->onConsecutiveCalls('y', 'y', '\\Foo\\Bar', 'y', 'n'));
1 ignored issue
show
Bug introduced by
The method method() does not exist on CaptainHook\App\Console\IO. ( Ignorable by Annotation )

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

37
        $io->/** @scrutinizer ignore-call */ 
38
             method('ask')->will($this->onConsecutiveCalls('y', 'y', '\\Foo\\Bar', 'y', 'n'));

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
39
        $runner = new Creator($io, $config);
40
        $runner->advanced(true)
41
               ->run();
42
    }
43
44
    /**
45
     * Tests Creator::run
46
     *
47
     * Check if a previously defined configuration will not be deleted if we extend the configuration.
48
     *
49
     * @throws \Exception
50
     */
51
    public function testConfigureFileExtend(): void
52
    {
53
        $configFileContentBefore = '{"pre-commit": {"enabled": false,"actions": [{"action": "phpunit"}]}}';
54
55
        $configDir  = vfsStream::setup('root', null, ['captainhook.json' => $configFileContentBefore]);
56
        $configFile = $configDir->url() . '/captainhook.json';
57
        $config     = Config\Factory::create($configFile);
58
59
        $io = $this->createIOMock();
60
        $io->method('ask')->will($this->onConsecutiveCalls('y', 'y', '\\Foo\\Bar', 'y', 'n'));
61
        $io->expects($this->once())->method('askAndValidate')->willReturn('foo:bar');
1 ignored issue
show
Bug introduced by
The method expects() does not exist on CaptainHook\App\Console\IO. ( Ignorable by Annotation )

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

61
        $io->/** @scrutinizer ignore-call */ 
62
             expects($this->once())->method('askAndValidate')->willReturn('foo:bar');

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...
62
63
        $runner = new Creator($io, $config);
64
        $runner->extend(true)
65
               ->advanced(true)
66
               ->run();
67
68
        $configFileContentAfter = $configDir->getChild('captainhook.json')->getContent();
0 ignored issues
show
Bug introduced by
The method getContent() does not exist on org\bovigo\vfs\vfsStreamContent. It seems like you code against a sub-type of org\bovigo\vfs\vfsStreamContent such as org\bovigo\vfs\vfsStreamFile. ( Ignorable by Annotation )

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

68
        $configFileContentAfter = $configDir->getChild('captainhook.json')->/** @scrutinizer ignore-call */ getContent();
Loading history...
69
        $this->assertFileExists($configFile);
70
        $this->assertStringContainsString('pre-commit', $configFileContentAfter);
71
        $this->assertStringContainsString('pre-push', $configFileContentAfter);
72
        $this->assertStringContainsString('phpunit', $configFileContentAfter);
73
    }
74
}
75