Skip to content

Commit 8b30c24

Browse files
committed
Import tests from other project - not tested ;)
1 parent 06bdb0e commit 8b30c24

File tree

4 files changed

+284
-0
lines changed

4 files changed

+284
-0
lines changed

tests/config/bootstrap.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
<?php
2+
3+
ini_set('error_reporting', E_ALL);
4+
ini_set('display_errors', '1');
5+
ini_set('display_startup_errors', '1');

tests/config/phpunit.xml

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
3+
<phpunit bootstrap = "bootstrap.php"
4+
backupGlobals = "false"
5+
backupStaticAttributes = "false"
6+
colors = "true"
7+
convertErrorsToExceptions = "true"
8+
convertNoticesToExceptions = "true"
9+
convertWarningsToExceptions = "true"
10+
processIsolation = "false"
11+
stopOnFailure = "false">
12+
13+
<testsuites>
14+
<testsuite name="Unit Tests">
15+
<directory>../unit</directory>
16+
</testsuite>
17+
<testsuite name="Integration Tests">
18+
<directory>../integration</directory>
19+
</testsuite>
20+
</testsuites>
21+
22+
<php>
23+
<ini name="display_errors" value="On" />
24+
<ini name="display_startup_errors" value="On" />
25+
<env name="APP_ENV" value="test"/>
26+
</php>
27+
28+
</phpunit>
Lines changed: 128 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,128 @@
1+
<?php
2+
3+
namespace PlotBox\PhpcsParse\Phpcs\ReportType;
4+
5+
use Mockery\Adapter\Phpunit\MockeryTestCase;
6+
use PlotBox\PhpcsParse\CodeIssue;
7+
use PlotBox\PhpcsParse\RelativeFile;
8+
use stdClass;
9+
10+
class ReportAggregatorTest extends MockeryTestCase
11+
{
12+
/** @var ReportAggregator */
13+
private $reportAggregator;
14+
15+
public function setUp()
16+
{
17+
$this->reportAggregator = new ReportAggregator();
18+
}
19+
20+
public function testGetReportData()
21+
{
22+
$issues = $this->getIssues();
23+
$result = $this->reportAggregator->getReportData($issues);
24+
$this->assertEquals($this->getExpected(), $result);
25+
}
26+
27+
/**
28+
* @return mixed[]
29+
*/
30+
private function getIssues()
31+
{
32+
return [
33+
new CodeIssue(
34+
new RelativeFile('src/AnotherBadClass.php'),
35+
1,
36+
1,
37+
"PSR1.Files.SideEffects.FoundWithSymbols",
38+
"A file should declare new symbols (classes, functions, constants, etc.) and cause no other side effects, or it should execute logic with side effects, but should not do both. The first symbol is defined on line 8 and the first side effect is on line 29.",
39+
"warning",
40+
5,
41+
false
42+
),
43+
new CodeIssue(
44+
new RelativeFile('src/AnotherBadClass.php'),
45+
14,
46+
1,
47+
'..DisallowContiguousNewlines.ContiguousNewlines',
48+
"Contiguous blank lines found",
49+
"error",
50+
5,
51+
true
52+
),
53+
new CodeIssue(
54+
new RelativeFile('src/SomeOtherBadClass.php'),
55+
123,
56+
5,
57+
'..DisallowContiguousNewlines.ContiguousNewlines',
58+
"Contiguous blank lines found",
59+
"error",
60+
5,
61+
false
62+
),
63+
];
64+
}
65+
66+
/**
67+
* @return stdClass
68+
*/
69+
private function getExpected()
70+
{
71+
return (object) [
72+
'totals' =>
73+
(object) [
74+
'errors' => 2,
75+
'warnings' => 1,
76+
'fixable' => 1,
77+
],
78+
'files' =>
79+
(object) [
80+
'src/AnotherBadClass.php' =>
81+
(object) [
82+
'errors' => 1,
83+
'warnings' => 1,
84+
'fixable' => 1,
85+
'messages' =>
86+
[
87+
(object) [
88+
'message' => 'A file should declare new symbols (classes, functions, constants, etc.) and cause no other side effects, or it should execute logic with side effects, but should not do both. The first symbol is defined on line 8 and the first side effect is on line 29.',
89+
'source' => 'PSR1.Files.SideEffects.FoundWithSymbols',
90+
'severity' => 5,
91+
'fixable' => false,
92+
'type' => 'warning',
93+
'line' => 1,
94+
'column' => 1,
95+
],
96+
(object) [
97+
'message' => 'Contiguous blank lines found',
98+
'source' => '..DisallowContiguousNewlines.ContiguousNewlines',
99+
'severity' => 5,
100+
'fixable' => true,
101+
'type' => 'error',
102+
'line' => 14,
103+
'column' => 1,
104+
],
105+
],
106+
],
107+
'src/SomeOtherBadClass.php' =>
108+
(object) [
109+
'errors' => 1,
110+
'warnings' => 0,
111+
'fixable' => 0,
112+
'messages' =>
113+
[
114+
(object) [
115+
'message' => 'Contiguous blank lines found',
116+
'source' => '..DisallowContiguousNewlines.ContiguousNewlines',
117+
'severity' => 5,
118+
'fixable' => false,
119+
'type' => 'error',
120+
'line' => 123,
121+
'column' => 5,
122+
],
123+
],
124+
],
125+
],
126+
];
127+
}
128+
}
Lines changed: 123 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,123 @@
1+
<?php
2+
3+
namespace PlotBox\PhpcsParse\Git\Phpcs\ReportType;
4+
5+
use Mockery as m;
6+
use Mockery\Adapter\Phpunit\MockeryTestCase;
7+
use Mockery\MockInterface as Mock;
8+
use PlotBox\PhpcsParse\Phpcs\ReportType\ReportAggregator;
9+
use PlotBox\PhpcsParse\Phpcs\ReportType\XmlReport;
10+
use stdClass;
11+
12+
class XmlReportTest extends MockeryTestCase
13+
{
14+
/** @var XmlReport */
15+
private $xmlReport;
16+
17+
/**
18+
* @var ReportAggregator|Mock
19+
*/
20+
private $reportAggregator;
21+
22+
public function setUp()
23+
{
24+
$this->reportAggregator = m::mock(ReportAggregator::class);
25+
$this->xmlReport = new XmlReport($this->reportAggregator);
26+
}
27+
28+
public function testToString()
29+
{
30+
$mockIssues = [];
31+
32+
$this->reportAggregator
33+
->shouldReceive('getReportData')
34+
->andReturn($this->getAggregatedReportData());
35+
36+
$result = $this->xmlReport->toString($mockIssues);
37+
38+
$this->assertEquals($this->getExpectedResult(), $result);
39+
}
40+
41+
/**
42+
* @return stdClass
43+
*/
44+
private function getAggregatedReportData()
45+
{
46+
return (object) [
47+
'totals' =>
48+
(object) [
49+
'errors' => 2,
50+
'warnings' => 1,
51+
'fixable' => 1,
52+
],
53+
'files' =>
54+
(object) [
55+
'/app/tests/integration/fixtures/phpcs-shim-fixture/src/AnotherBadClass.php' =>
56+
(object) [
57+
'errors' => 1,
58+
'warnings' => 1,
59+
'fixable' => 1,
60+
'messages' =>
61+
[
62+
(object) [
63+
'message' => 'A file should declare new symbols (classes, functions, constants, etc.) and cause no other side effects, or it should execute logic with side effects, but should not do both. The first symbol is defined on line 8 and the first side effect is on line 29.',
64+
'source' => 'PSR1.Files.SideEffects.FoundWithSymbols',
65+
'severity' => 5,
66+
'fixable' => false,
67+
'type' => 'WARNING',
68+
'line' => 1,
69+
'column' => 1,
70+
],
71+
(object) [
72+
'message' => 'Contiguous blank lines found',
73+
'source' => '..DisallowContiguousNewlines.ContiguousNewlines',
74+
'severity' => 5,
75+
'fixable' => true,
76+
'type' => 'ERROR',
77+
'line' => 14,
78+
'column' => 1,
79+
],
80+
],
81+
],
82+
'/app/tests/integration/fixtures/phpcs-shim-fixture/src/SomeOtherBadClass.php' =>
83+
(object) [
84+
'errors' => 1,
85+
'warnings' => 0,
86+
'fixable' => 0,
87+
'messages' =>
88+
[
89+
(object) [
90+
'message' => 'Contiguous blank lines found',
91+
'source' => '..DisallowContiguousNewlines.ContiguousNewlines',
92+
'severity' => 5,
93+
'fixable' => false,
94+
'type' => 'ERROR',
95+
'line' => 123,
96+
'column' => 5,
97+
],
98+
],
99+
],
100+
],
101+
];
102+
}
103+
104+
/**
105+
* @return string
106+
*/
107+
private function getExpectedResult()
108+
{
109+
return <<<XML
110+
<?xml version="1.0" encoding="utf-8"?>
111+
<phpcs version="3.4.2">
112+
<file name="/app/tests/integration/fixtures/phpcs-shim-fixture/src/AnotherBadClass.php" errors="1" warnings="1" fixable="1">
113+
<warning line="1" column="1" source="PSR1.Files.SideEffects.FoundWithSymbols" severity="5" fixable="0">A file should declare new symbols (classes, functions, constants, etc.) and cause no other side effects, or it should execute logic with side effects, but should not do both. The first symbol is defined on line 8 and the first side effect is on line 29.</warning>
114+
<error line="14" column="1" source="..DisallowContiguousNewlines.ContiguousNewlines" severity="5" fixable="1">Contiguous blank lines found</error>
115+
</file>
116+
<file name="/app/tests/integration/fixtures/phpcs-shim-fixture/src/SomeOtherBadClass.php" errors="1" warnings="0" fixable="0">
117+
<error line="123" column="5" source="..DisallowContiguousNewlines.ContiguousNewlines" severity="5" fixable="0">Contiguous blank lines found</error>
118+
</file>
119+
</phpcs>
120+
121+
XML;
122+
}
123+
}

0 commit comments

Comments
 (0)