Skip to content

Commit f57568b

Browse files
committed
added tests for formatters
1 parent edd1f33 commit f57568b

23 files changed

+1297
-586
lines changed

fixtures/filesJSONRecursiveJSONContent.txt

Lines changed: 435 additions & 0 deletions
Large diffs are not rendered by default.

fixtures/filesJSONRecursiveYAMLContent.txt

Lines changed: 435 additions & 0 deletions
Large diffs are not rendered by default.
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
File file1.json content:
2+
Property 'common.setting1' has value 'Value 1'
3+
Property 'common.setting2' has value '200'
4+
Property 'common.setting3' has value true
5+
Property 'common.setting6.key' has value 'value'
6+
Property 'common.setting6.doge.wow' has value ''
7+
Property 'group1.baz' has value 'bas'
8+
Property 'group1.foo' has value 'bar'
9+
Property 'group1.nest.key' has value 'value'
10+
Property 'group1.best' has value 'str'
11+
Property 'group2.abc' has value '12345'
12+
Property 'group2.deep.id' has value '45'
13+
File file2.json content:
14+
Property 'common.follow' has value false
15+
Property 'common.setting1' has value 'Value 1'
16+
Property 'common.setting3' has value null
17+
Property 'common.setting4' has value 'blah blah'
18+
Property 'common.setting5.key5' has value 'value5'
19+
Property 'common.setting6.key' has value 'value'
20+
Property 'common.setting6.ops' has value 'vops'
21+
Property 'common.setting6.doge.wow' has value 'so much'
22+
Property 'group1.foo' has value 'bar'
23+
Property 'group1.baz' has value 'bars'
24+
Property 'group1.nest' has value 'str'
25+
Property 'group1.best.key' has value 'value'
26+
Property 'group3.deep.id.number' has value '45'
27+
Property 'group3.fee' has value '100500'
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
File file1.yaml content:
2+
Property 'common.setting1' has value 'Value 1'
3+
Property 'common.setting2' has value '200'
4+
Property 'common.setting3' has value true
5+
Property 'common.setting6.key' has value 'value'
6+
Property 'common.setting6.doge.wow' has value ''
7+
Property 'group1.baz' has value 'bas'
8+
Property 'group1.foo' has value 'bar'
9+
Property 'group1.nest.key' has value 'value'
10+
Property 'group1.best' has value 'str'
11+
Property 'group2.abc' has value '12345'
12+
Property 'group2.deep.id' has value '45'
13+
File file2.yaml content:
14+
Property 'common.follow' has value false
15+
Property 'common.setting1' has value 'Value 1'
16+
Property 'common.setting3' has value null
17+
Property 'common.setting4' has value 'blah blah'
18+
Property 'common.setting5.key5' has value 'value5'
19+
Property 'common.setting6.key' has value 'value'
20+
Property 'common.setting6.ops' has value 'vops'
21+
Property 'common.setting6.doge.wow' has value 'so much'
22+
Property 'group1.foo' has value 'bar'
23+
Property 'group1.baz' has value 'bars'
24+
Property 'group1.nest' has value 'str'
25+
Property 'group1.best.key' has value 'value'
26+
Property 'group3.deep.id.number' has value '45'
27+
Property 'group3.fee' has value '100500'
File renamed without changes.
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
File file1.json content:
2+
{
3+
common: {
4+
setting1: Value 1
5+
setting2: 200
6+
setting3: true
7+
setting6: {
8+
key: value
9+
doge: {
10+
wow:
11+
}
12+
}
13+
}
14+
group1: {
15+
baz: bas
16+
foo: bar
17+
nest: {
18+
key: value
19+
}
20+
best: str
21+
}
22+
group2: {
23+
abc: 12345
24+
deep: {
25+
id: 45
26+
}
27+
}
28+
}
29+
File file2.json content:
30+
{
31+
common: {
32+
follow: false
33+
setting1: Value 1
34+
setting3: null
35+
setting4: blah blah
36+
setting5: {
37+
key5: value5
38+
}
39+
setting6: {
40+
key: value
41+
ops: vops
42+
doge: {
43+
wow: so much
44+
}
45+
}
46+
}
47+
group1: {
48+
foo: bar
49+
baz: bars
50+
nest: str
51+
best: {
52+
key: value
53+
}
54+
}
55+
group3: {
56+
deep: {
57+
id: {
58+
number: 45
59+
}
60+
}
61+
fee: 100500
62+
}
63+
}
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
File file1.yaml content:
2+
{
3+
common: {
4+
setting1: Value 1
5+
setting2: 200
6+
setting3: true
7+
setting6: {
8+
key: value
9+
doge: {
10+
wow:
11+
}
12+
}
13+
}
14+
group1: {
15+
baz: bas
16+
foo: bar
17+
nest: {
18+
key: value
19+
}
20+
best: str
21+
}
22+
group2: {
23+
abc: 12345
24+
deep: {
25+
id: 45
26+
}
27+
}
28+
}
29+
File file2.yaml content:
30+
{
31+
common: {
32+
follow: false
33+
setting1: Value 1
34+
setting3: null
35+
setting4: blah blah
36+
setting5: {
37+
key5: value5
38+
}
39+
setting6: {
40+
key: value
41+
ops: vops
42+
doge: {
43+
wow: so much
44+
}
45+
}
46+
}
47+
group1: {
48+
foo: bar
49+
baz: bars
50+
nest: str
51+
best: {
52+
key: value
53+
}
54+
}
55+
group3: {
56+
deep: {
57+
id: {
58+
number: 45
59+
}
60+
}
61+
fee: 100500
62+
}
63+
}

src/ConsoleApp.php

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,8 @@ public function run(): void
2424
->execute($this->nextCommand);
2525

2626
$formatCommand = $this->commandFactory->getCommand("format");
27-
$formatter = $formatCommand->execute($parseCommand);
28-
29-
$this->nextCommand = $formatter->execute($this->nextCommand);
27+
$this->nextCommand = $formatCommand->selectFormat($parseCommand)
28+
->execute($this->nextCommand);
3029

3130
$displayCommand = $this->commandFactory->getCommand("show");
3231
$displayCommand->execute($this->nextCommand);

src/Differ.php

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,8 @@ function genDiff(string $pathToFile1, string $pathToFile2, string $format = 'sty
2626
$nextCommand = $differenceCommand->execute($nextCommand);
2727

2828
$formatCommand = $commandFactory->getCommand('format');
29-
$formatter = $formatCommand->execute($parseCommand);
30-
31-
$nextCommand = $formatter->execute($nextCommand);
29+
$nextCommand = $formatCommand->selectFormat($parseCommand)
30+
->execute($nextCommand);
3231

3332
return $nextCommand->getFilesDiffs();
3433
}

src/Formatters.php

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ class Formatters implements CommandInterface
66
{
77
private CommandInterface $formatCommand;
88

9-
public function execute(CommandInterface $command = null): CommandInterface
9+
public function selectFormat(CommandInterface $command = null): CommandInterface
1010
{
1111
$commandFactory = new CommandFactory(
1212
new \Docopt(),
@@ -22,6 +22,23 @@ public function execute(CommandInterface $command = null): CommandInterface
2222
throw new DifferException("input error: unknown output format\nUse gendiff -h\n");
2323
}
2424

25-
return $this->formatCommand;
25+
return $this;
26+
}
27+
28+
public function execute(CommandInterface $command = null): CommandInterface
29+
{
30+
$this->formatCommand = $this->formatCommand->execute($command);
31+
32+
return $this;
33+
}
34+
35+
public function getFilesContent(): string
36+
{
37+
return $this->formatCommand->filesContentString;
38+
}
39+
40+
public function getFilesDiffs(): string
41+
{
42+
return $this->formatCommand->filesDiffsString;
2643
}
2744
}

0 commit comments

Comments
 (0)