-
Notifications
You must be signed in to change notification settings - Fork 13
Expand file tree
/
Copy pathCommitCommandTest.php
More file actions
90 lines (80 loc) · 3.38 KB
/
CommitCommandTest.php
File metadata and controls
90 lines (80 loc) · 3.38 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
<?php
declare(strict_types=1);
namespace Damianopetrungaro\PHPCommitizen;
use Damianopetrungaro\PHPCommitizen\Exception\InvalidArgumentException;
use Damianopetrungaro\PHPCommitizen\Section\Body;
use Damianopetrungaro\PHPCommitizen\Section\Footer;
use Damianopetrungaro\PHPCommitizen\Section\Subject;
use PHPUnit\Framework\TestCase;
use Prophecy\Argument;
use Prophecy\PhpUnit\ProphecyTrait;
use Symfony\Component\Console\Application;
use Symfony\Component\Console\Tester\CommandTester;
final class CommitCommandTest extends TestCase
{
use ProphecyTrait;
public function testCustomConfigurationFileNotFound(): void
{
$this->expectException(InvalidArgumentException::class);
$this->expectExceptionMessage("Custom configuration file does not exists: 'not_existing_file.php'");
$configuration = require __DIR__ . '/../../.php-commitizen.php';
$app = new Application('PHP Commitizen');
$app->add(new CommitCommand($configuration, new CreateConventionalCommit()));
$command = $app->find('commit');
$commandTester = new CommandTester($command);
$commandTester->execute([
'command' => $command->getName(),
'config' => 'not_existing_file.php'
]);
}
public function testCustomConfigurationFileDoesNotReturnAnArray(): void
{
$this->expectException(InvalidArgumentException::class);
$this->expectExceptionMessage('Custom configuration file must return an array');
$configuration = require __DIR__ . '/../../.php-commitizen.php';
$app = new Application('PHP Commitizen');
$app->add(new CommitCommand($configuration, new CreateConventionalCommit()));
$command = $app->find('commit');
$commandTester = new CommandTester($command);
$commandTester->execute([
'command' => $command->getName(),
'config' => __DIR__ . '/../../tests/Unit/Fixture/configuration.php',
]);
}
public function testCustomConfigurationIsMerged(): void
{
$that = $this;
$createConventionalCommitProphecy = $this->prophesize(CreateConventionalCommit::class);
$createConventionalCommitProphecy
->__invoke(
Argument::type(Subject::class),
Argument::type(Body::class),
Argument::type(Footer::class),
false
)
->shouldBeCalledTimes(1)
->will(function (array $data) use ($that) {
[$subject, $body, $footer, $addAllToStage] = $data;
$that->assertSame('fix(scope): commit description', (string)$subject);
$that->assertSame('commit body', (string)$body);
$that->assertSame('commit footer', (string)$footer);
$that->assertFalse($addAllToStage);
});
$commitCommand = new CommitCommand([], $createConventionalCommitProphecy->reveal());
$app = new Application('PHP Commitizen');
$app->add($commitCommand);
$command = $app->find('commit');
$commandTester = new CommandTester($command);
$commandTester->setInputs([
'fix',
'scope',
'commit description',
'commit body',
'commit footer',
]);
$commandTester->execute([
'command' => $command->getName(),
'config' => '.php-commitizen.php'
]);
}
}