Skip to content
This repository was archived by the owner on Jul 4, 2023. It is now read-only.

Commit 22e0d87

Browse files
committed
Running version
1 parent f8153e7 commit 22e0d87

File tree

9 files changed

+373
-71
lines changed

9 files changed

+373
-71
lines changed

build.xml

Lines changed: 163 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,163 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
3+
<project name="Phing static code analysis" default="all">
4+
<!-- Properties -->
5+
<property name="dir.base" value="." />
6+
<property name="dir.tests" value="${project.basedir}/tests" />
7+
<property name="dir.tests.unit" value="${project.basedir}/tests" />
8+
<property name="dir.build" value="${project.basedir}/build" />
9+
<property name="dir.docs" value="${dir.build}/docs" />
10+
<property name="dir.docs.phpdoc" value="${dir.docs}/phpdoc" />
11+
<property name="dir.reports" value="${dir.build}/logs" />
12+
<property name="dir.reports.pdepend" value="${dir.reports}/pdepend" />
13+
<property name="dir.reports.unit" value="${dir.reports}/phpunit" />
14+
<property name="dir.reports.coverage" value="${dir.reports}/phpunit/coverage" />
15+
<property name="dir.reports.build" value="${dir.reports}/htmlreport" />
16+
17+
<!-- ============================================ -->
18+
<!-- Fileset: sources (all php files but those in test) -->
19+
<!-- ============================================ -->
20+
<fileset expandsymboliclinks="true" dir="${dir.base}" id="sources">
21+
<include name="src/**/*.php" />
22+
</fileset>
23+
24+
<!-- ============================================ -->
25+
<!-- Target: clean -->
26+
<!-- ============================================ -->
27+
<target name="clean" description="Clean up build directories.">
28+
<echo msg="Cleaning build directories ..." />
29+
<delete dir="${dir.build}" verbose="false" />
30+
</target>
31+
32+
<!-- ============================================ -->
33+
<!-- Target: prepare -->
34+
<!-- ============================================ -->
35+
<target name="prepare" description="Create build directories.">
36+
<echo msg="Creating build directories ..." />
37+
<mkdir dir="${dir.build}" />
38+
<mkdir dir="${dir.docs}" />
39+
<mkdir dir="${dir.docs.phpdoc}" />
40+
<mkdir dir="${dir.reports}" />
41+
<mkdir dir="${dir.reports.unit}" />
42+
<mkdir dir="${dir.reports.coverage}" />
43+
<mkdir dir="${dir.reports.pdepend}" />
44+
<mkdir dir="${dir.reports.build}" />
45+
</target>
46+
47+
<!-- ============================================ -->
48+
<!-- Target: all (default target) -->
49+
<!-- ============================================ -->
50+
<target name="all" depends="clean, prepare">
51+
<phingcall target="codecheck" />
52+
<phingcall target="tests" />
53+
<phingcall target="documentation" />
54+
</target>
55+
56+
<!-- ============================================ -->
57+
<!-- Target: codecheck (run all static code checks) -->
58+
<!-- ============================================ -->
59+
<target name="codecheck">
60+
<phingcall target="lint" />
61+
<phingcall target="codestyle" />
62+
<phingcall target="mess" />
63+
<phingcall target="copypaste" />
64+
<phingcall target="measure" />
65+
</target>
66+
67+
<!-- ============================================ -->
68+
<!-- Target: tests (run all tests) -->
69+
<!-- ============================================ -->
70+
<target name="tests">
71+
<!-- Now we are not running unit tests -->
72+
<!-- <phingcall target="unittests" /> -->
73+
</target>
74+
75+
<!-- ============================================ -->
76+
<!-- Target: lint (Checks code syntax) -->
77+
<!-- ============================================ -->
78+
<target name="lint">
79+
<echo msg="Running lint to check code syntax..." />
80+
<phplint>
81+
<fileset refid="sources" />
82+
</phplint>
83+
</target>
84+
85+
<!-- ============================================ -->
86+
<!-- Target: codestyle (Checks code style compliance) -->
87+
<!-- ============================================ -->
88+
<target name="codestyle">
89+
<echo msg="Running code sniffer to check PSR2 standard..." />
90+
<phpcodesniffer standard="PSR2" showSniffs="true" showWarnings="true" verbosity="0" encoding="UTF-8">
91+
<fileset refid="sources" />
92+
<formatter type="full" outfile="${dir.reports}/reportcs.txt" />
93+
<formatter type="checkstyle" outfile="${dir.reports}/checkstylecs.xml" />
94+
</phpcodesniffer>
95+
</target>
96+
97+
<!-- ============================================ -->
98+
<!-- Target: mess (Detects mess in code. Recommended rulesets: -->
99+
<!-- unusedcode,codesize,controversial,design,naming) -->
100+
<!-- ============================================ -->
101+
<target name="mess">
102+
<echo msg="Running mess detector" />
103+
<phpmd rulesets="unusedcode,codesize,controversial,design,naming">
104+
<fileset refid="sources" />
105+
<formatter type="xml" outfile="${dir.reports}/pmd.xml"/>
106+
</phpmd>
107+
</target>
108+
109+
<!-- ============================================ -->
110+
<!-- Target: copypaste (detects copy/paste in code) -->
111+
<!-- ============================================ -->
112+
<target name="copypaste">
113+
<echo msg="Running copy/paste detector..." />
114+
<phpcpd>
115+
<fileset refid="sources" />
116+
<formatter type="pmd" outfile="${dir.reports}/pmd-cpd.xml" />
117+
</phpcpd>
118+
</target>
119+
120+
<!-- ============================================ -->
121+
<!-- Target: measure (measures the code) -->
122+
<!-- ============================================ -->
123+
<target name="measure">
124+
<echo msg="Running code measurements..." />
125+
<phploc reportType="csv" reportName="phploc" reportDirectory="${dir.reports}">
126+
<fileset refid="sources" />
127+
</phploc>
128+
<phpdepend>
129+
<fileset refid="sources" />
130+
<logger type="jdepend-xml" outfile="${dir.reports}/jdepend.xml"/>
131+
<analyzer type="coderank-mode" value="method"/>
132+
</phpdepend>
133+
</target>
134+
135+
<!-- ============================================ -->
136+
<!-- Target: documentation (PHP Documentor parsing) -->
137+
<!-- ============================================ -->
138+
<target name="documentation">
139+
<phpdoc2 title="Project Documentation" destdir="${dir.docs.phpdoc}" template="responsive-twig">
140+
<fileset refid="sources" />
141+
</phpdoc2>
142+
</target>
143+
144+
<!-- ============================================ -->
145+
<!-- Target: unittests (unit testing) -->
146+
<!-- ============================================ -->
147+
<target name="unittests">
148+
<echo msg="Running unit tests..." />
149+
<coverage-setup database="${dir.reports.unit}/coverage.db">
150+
<fileset refid="sources" />
151+
</coverage-setup>
152+
<phpunit configuration="${dir.tests}/phpunit.xml" codecoverage="true">
153+
<formatter todir="${dir.reports.unit}" type="xml" />
154+
<formatter todir="${dir.reports.unit}" type="clover" />
155+
<batchtest>
156+
<fileset dir="${dir.tests.unit}" />
157+
</batchtest>
158+
</phpunit>
159+
<coverage-report outfile="${dir.reports.unit}/coverage.xml">
160+
<report todir="${dir.reports.coverage}" title="Phing unit tests run" usesorttable="true"/>
161+
</coverage-report>
162+
</target>
163+
</project>

src/Extension/WireMock.php

Lines changed: 34 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -2,62 +2,75 @@
22
namespace Codeception\Extension;
33

44
use Codeception\Platform\Extension as CodeceptionExtension;
5+
use WireMock\Client\WireMock as WireMockClient;
56

7+
/**
8+
* Codeception Extension for WireMock
9+
*/
610
class WireMock extends CodeceptionExtension
711
{
8-
const DEFAULT_LOGS_PATH = '/tmp/codeceptionWireMock/logs/';
9-
1012
/**
1113
*
1214
* @var WireMockDownloader
1315
*/
1416
private $downloader;
1517
/**
1618
*
17-
* @var WireMockServer
19+
* @var WireMockProcess
1820
*/
19-
private $server;
21+
private $process;
2022
/**
2123
*
2224
* @var WireMockArguments
2325
*/
2426
private $argumentsManager;
2527

28+
/**
29+
* Class constructor.
30+
*
31+
* @param array $config
32+
* @param array $options
33+
* @param WireMockDownloader $downloader optional WireMockDownloader object
34+
* @param WireMockProcess $process optional WireMockProcess object
35+
* @param WireMockArguments $argumentsManager optional WireMockArguments object
36+
*/
2637
public function __construct(
2738
$config,
2839
$options,
2940
WireMockDownloader $downloader = null,
30-
WireMockServer $server = null,
41+
WireMockProcess $process = null,
3142
WireMockArguments $argumentsManager = null
3243
) {
3344
parent::__construct($config, $options);
3445

3546
$this->initWireMockDownloader($downloader);
36-
$this->initWireMockServer($server);
47+
$this->initWireMockProcess($process);
3748
$this->initWireMockArgumentsManager($argumentsManager);
3849

3950
$this->config = $this->argumentsManager->sanitize($this->config);
4051

4152
if (! empty($this->config['host'])) {
53+
echo "Connecting to wiremock host {$this->config['host']}" . PHP_EOL;
4254
$host = $this->config['host'];
4355
} else {
44-
$this->server->start(
56+
echo "Starting local wiremock" . PHP_EOL;
57+
$this->process->start(
4558
$this->getJarPath(),
46-
$this->getLogsPath(),
59+
$this->config['logs-path'],
4760
$this->mapConfigToWireMockArguments($this->config)
4861
);
4962
$host = 'localhost';
5063
sleep($this->config['start-delay']);
5164
}
52-
WireMockConnection::setConnection(\WireMock\Client\WireMock::create($host, $this->config['port']));
65+
WireMockConnection::setConnection(WireMockClient::create($host, $this->config['port']));
5366
}
5467

55-
private function initWireMockServer($server)
68+
private function initWireMockProcess($process)
5669
{
57-
if ($server === null) {
58-
$this->server = new WireMockServer();
70+
if ($process === null) {
71+
$this->process = new WireMockProcess();
5972
} else {
60-
$this->server = $server;
73+
$this->process = $process;
6174
}
6275
}
6376

@@ -79,14 +92,20 @@ private function initWireMockArgumentsManager($argumentsManager)
7992
}
8093
}
8194

95+
/**
96+
* Class destructor.
97+
*/
8298
public function __destruct()
8399
{
84-
$this->server->stop();
100+
if (WireMockConnection::get()->isAlive()) {
101+
WireMockConnection::get()->shutdownServer();
102+
}
103+
$this->process->stop();
85104
}
86105

87106
private function getJarPath()
88107
{
89-
if (! empty($this->config['jar-path'])) {
108+
if (!empty($this->config['jar-path'])) {
90109
$this->checkJarExists($this->config['jar-path']);
91110
$jarPath = $this->config['jar-path'];
92111
} elseif (!empty($this->config['download-version'])) {
@@ -97,27 +116,6 @@ private function getJarPath()
97116
return $jarPath;
98117
}
99118

100-
private function getLogsPath()
101-
{
102-
if (! empty($this->config['logs-path'])) {
103-
$logsPath = $this->config['logs-path'];
104-
$this->checkLogsPath($logsPath);
105-
} else {
106-
$logsPath = self::DEFAULT_LOGS_PATH;
107-
if (! is_dir($logsPath)) {
108-
mkdir($logsPath, 0777, true);
109-
}
110-
}
111-
return $logsPath;
112-
}
113-
114-
private function checkLogsPath($logsPath)
115-
{
116-
if (!is_dir($logsPath) || !is_writable($logsPath)) {
117-
throw \Exception("Directory $logsPath does not exist");
118-
}
119-
}
120-
121119
private function checkJarExists($jar)
122120
{
123121
if (!file_exists($jar)) {

0 commit comments

Comments
 (0)