Completed
Push — develop ( 4146c2...e30e33 )
by Chris
35:42
created

CheckTest::testWithBadCSR()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 15
Code Lines 8

Duplication

Lines 15
Ratio 100 %

Code Coverage

Tests 9
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 15
loc 15
ccs 9
cts 9
cp 1
rs 9.4285
cc 1
eloc 8
nc 1
nop 0
crap 1
1
<?php
2
/**
3
 * @author     Chris Hilsdon <[email protected]>
4
 * @package    ComodoDecodeCSR
5
 * @copyright  2016 Xigen
6
 * @license    GNU General Public License v3
7
 * @link       https://github.com/XigenChris/ComodoDecodeCSR
8
 */
9
10
namespace Xigen\Tests\Console;
11
12
use Xigen\ComodoDecodeCSR;
13
use Xigen\Tests\XigenUnit;
14
use Xigen\Console\Check;
15
use Symfony\Component\Console\Tester\CommandTester;
16
17
class CheckTest extends XigenUnit
18
{
19
    protected $ComodoDecodeCSR;
20
21
    public function setUp()
22
    {
23 4
        register_shutdown_function(function () {
24
            if (file_exists('test.csr')) {
25
                unlink('test.csr');
26
            }
27 4
        });
28 4
    }
29
30 1 View Code Duplication
    public function testNoCSR()
1 ignored issue
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...
31
    {
32 1
        $command = new Check();
33 1
        $tester = new CommandTester($command);
34
35
        try {
36 1
            $tester->execute([]);
37 1
        } catch (\Exception $e) {
38 1
            $this->assertEmpty($tester->getDisplay(), "Message wan't empty");
39 1
            $this->assertSame($e->getMessage(), 'Not enough arguments (missing: "csr").');
40
        }
41 1
    }
42
43 4 View Code Duplication
    public function testWithInvalidCSR()
1 ignored issue
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...
44
    {
45 1
        $command = new Check();
46 1
        $tester = new CommandTester($command);
47
48
        //Create an empty
49 1
        file_put_contents('test.csr', '', FILE_APPEND | LOCK_EX);
50
51 1
        $tester->execute([
52
            'csr' => 'test.csr'
53 1
        ]);
54
55 1
        $this->assertSame($tester->getStatusCode(), (int) 3);
56 4
        $this->assertRegExp('/Error!/', $tester->getDisplay());
57 1
    }
58
59 4 View Code Duplication
    public function testWithBadCSR()
1 ignored issue
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...
60
    {
61 1
        $command = new Check();
62 1
        $tester = new CommandTester($command);
63
64
        //Create an empty
65 1
        file_put_contents('test.csr', ' ' . $this->createFakeCSR(), FILE_APPEND | LOCK_EX);
66
67 4
        $tester->execute([
68
            'csr' => 'test.csr'
69 1
        ]);
70
71 1
        $this->assertSame($tester->getStatusCode(), (int) 3);
72 4
        $this->assertRegExp('/Error!/', $tester->getDisplay());
73 1
    }
74
75 1 View Code Duplication
    public function testWithCorrectCSR()
1 ignored issue
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...
76
    {
77 1
        $command = new Check();
78 1
        $tester = new CommandTester($command);
79 1
        $tester->execute([
80
            'csr' => 'certificate/test.csr'
81 1
        ]);
82
83 1
        $this->assertSame($tester->getStatusCode(), (int) 0);
84 1
        $this->assertRegExp('/Success!/', $tester->getDisplay());
85 1
    }
86
}
87