-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added documentation and fixed Module
- Loading branch information
Showing
4 changed files
with
257 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,93 @@ | ||
# codeception-http-mock | ||
HttpMock extension and module for Codeception. | ||
This Codeception Extension allows developers and testers to use HttpMock to mock external services when running codeception tests. | ||
|
||
codeception-http-mock runs an instance of http-mock before your tests run so they can mock external services. | ||
After the tests are finished it will close the connection and turn http-mock off. | ||
|
||
## See also | ||
|
||
* [http-mock library](https://github.com/InterNations/http-mock) | ||
|
||
## Installation | ||
|
||
### Composer: | ||
|
||
This project is published in packagist, so you just need to add it as a dependency in your composer.json: | ||
|
||
```javascript | ||
"require": { | ||
// ... | ||
"mcustiel/codeception-http-mock": "*" | ||
} | ||
``` | ||
|
||
If you want to access directly to this repo, adding this to your composer.json should be enough: | ||
|
||
```javascript | ||
{ | ||
"repositories": [ | ||
{ | ||
"type": "vcs", | ||
"url": "https://github.com/mcustiel/codeception-http-mock" | ||
} | ||
], | ||
"require": { | ||
"mcustiel/codeception-http-mock": "dev-master" | ||
} | ||
} | ||
``` | ||
|
||
Or just download the release and include it in your path. | ||
|
||
## Configuration Example | ||
|
||
### Extension | ||
|
||
```yaml | ||
# codeception.yml | ||
extensions: | ||
enabled: | ||
- Codeception\Extension\HttpMock | ||
config: | ||
Codeception\Extension\HttpMock: | ||
port: 18080 # defaults to http-mock default port | ||
host: name.for.my.server # defaults to http-mock default host | ||
``` | ||
### Module | ||
```yaml | ||
# acceptance.yml | ||
modules: | ||
enabled: | ||
- HttpMock | ||
``` | ||
## How to use | ||
### Prepare your application | ||
First of all, configure your application so when it is being tested it will replace its external services with http-mock. | ||
For instance, if you make some requests to a REST service located under http://your.rest.interface, replace that url in configuration with the host yoy set up in http-mock extension configuration. | ||
### Write your tests | ||
```php | ||
// YourCest.php | ||
class YourCest extends \Codeception\TestCase\Test | ||
{ | ||
// tests | ||
public function tryToTest(\AcceptanceTester $I) | ||
{ | ||
$I->expectRequest()->when() | ||
->methodIs('GET') | ||
->pathIs('/foo') | ||
->then() | ||
->body('mocked body') | ||
->end(); | ||
$I->doNotExpectAnyOtherRequest(); | ||
$response = file_get_contents('http://localhost:28080/foo'); | ||
$I->assertEquals('mocked body', $response); | ||
} | ||
} | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,163 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
|
||
<project name="Phing static code analysis" default="all"> | ||
<!-- Properties --> | ||
<property name="dir.base" value="." /> | ||
<property name="dir.tests" value="${project.basedir}/tests" /> | ||
<property name="dir.tests.unit" value="${project.basedir}/tests" /> | ||
<property name="dir.build" value="${project.basedir}/build" /> | ||
<property name="dir.docs" value="${dir.build}/docs" /> | ||
<property name="dir.docs.phpdoc" value="${dir.docs}/phpdoc" /> | ||
<property name="dir.reports" value="${dir.build}/logs" /> | ||
<property name="dir.reports.pdepend" value="${dir.reports}/pdepend" /> | ||
<property name="dir.reports.unit" value="${dir.reports}/phpunit" /> | ||
<property name="dir.reports.coverage" value="${dir.reports}/phpunit/coverage" /> | ||
<property name="dir.reports.build" value="${dir.reports}/htmlreport" /> | ||
|
||
<!-- ============================================ --> | ||
<!-- Fileset: sources (all php files but those in test) --> | ||
<!-- ============================================ --> | ||
<fileset expandsymboliclinks="true" dir="${dir.base}" id="sources"> | ||
<include name="src/**/*.php" /> | ||
</fileset> | ||
|
||
<!-- ============================================ --> | ||
<!-- Target: clean --> | ||
<!-- ============================================ --> | ||
<target name="clean" description="Clean up build directories."> | ||
<echo msg="Cleaning build directories ..." /> | ||
<delete dir="${dir.build}" verbose="false" /> | ||
</target> | ||
|
||
<!-- ============================================ --> | ||
<!-- Target: prepare --> | ||
<!-- ============================================ --> | ||
<target name="prepare" description="Create build directories."> | ||
<echo msg="Creating build directories ..." /> | ||
<mkdir dir="${dir.build}" /> | ||
<mkdir dir="${dir.docs}" /> | ||
<mkdir dir="${dir.docs.phpdoc}" /> | ||
<mkdir dir="${dir.reports}" /> | ||
<mkdir dir="${dir.reports.unit}" /> | ||
<mkdir dir="${dir.reports.coverage}" /> | ||
<mkdir dir="${dir.reports.pdepend}" /> | ||
<mkdir dir="${dir.reports.build}" /> | ||
</target> | ||
|
||
<!-- ============================================ --> | ||
<!-- Target: all (default target) --> | ||
<!-- ============================================ --> | ||
<target name="all" depends="clean, prepare"> | ||
<phingcall target="codecheck" /> | ||
<phingcall target="tests" /> | ||
<phingcall target="documentation" /> | ||
</target> | ||
|
||
<!-- ============================================ --> | ||
<!-- Target: codecheck (run all static code checks) --> | ||
<!-- ============================================ --> | ||
<target name="codecheck"> | ||
<phingcall target="lint" /> | ||
<phingcall target="codestyle" /> | ||
<phingcall target="mess" /> | ||
<phingcall target="copypaste" /> | ||
<phingcall target="measure" /> | ||
</target> | ||
|
||
<!-- ============================================ --> | ||
<!-- Target: tests (run all tests) --> | ||
<!-- ============================================ --> | ||
<target name="tests"> | ||
<!-- Now we are not running unit tests --> | ||
<!-- <phingcall target="unittests" /> --> | ||
</target> | ||
|
||
<!-- ============================================ --> | ||
<!-- Target: lint (Checks code syntax) --> | ||
<!-- ============================================ --> | ||
<target name="lint"> | ||
<echo msg="Running lint to check code syntax..." /> | ||
<phplint> | ||
<fileset refid="sources" /> | ||
</phplint> | ||
</target> | ||
|
||
<!-- ============================================ --> | ||
<!-- Target: codestyle (Checks code style compliance) --> | ||
<!-- ============================================ --> | ||
<target name="codestyle"> | ||
<echo msg="Running code sniffer to check PSR2 standard..." /> | ||
<phpcodesniffer standard="PSR2" showSniffs="true" showWarnings="true" verbosity="0" encoding="UTF-8"> | ||
<fileset refid="sources" /> | ||
<formatter type="full" outfile="${dir.reports}/reportcs.txt" /> | ||
<formatter type="checkstyle" outfile="${dir.reports}/checkstylecs.xml" /> | ||
</phpcodesniffer> | ||
</target> | ||
|
||
<!-- ============================================ --> | ||
<!-- Target: mess (Detects mess in code. Recommended rulesets: --> | ||
<!-- unusedcode,codesize,controversial,design,naming) --> | ||
<!-- ============================================ --> | ||
<target name="mess"> | ||
<echo msg="Running mess detector" /> | ||
<phpmd rulesets="unusedcode,codesize,controversial,design,naming"> | ||
<fileset refid="sources" /> | ||
<formatter type="xml" outfile="${dir.reports}/pmd.xml"/> | ||
</phpmd> | ||
</target> | ||
|
||
<!-- ============================================ --> | ||
<!-- Target: copypaste (detects copy/paste in code) --> | ||
<!-- ============================================ --> | ||
<target name="copypaste"> | ||
<echo msg="Running copy/paste detector..." /> | ||
<phpcpd> | ||
<fileset refid="sources" /> | ||
<formatter type="pmd" outfile="${dir.reports}/pmd-cpd.xml" /> | ||
</phpcpd> | ||
</target> | ||
|
||
<!-- ============================================ --> | ||
<!-- Target: measure (measures the code) --> | ||
<!-- ============================================ --> | ||
<target name="measure"> | ||
<echo msg="Running code measurements..." /> | ||
<phploc reportType="csv" reportName="phploc" reportDirectory="${dir.reports}"> | ||
<fileset refid="sources" /> | ||
</phploc> | ||
<phpdepend> | ||
<fileset refid="sources" /> | ||
<logger type="jdepend-xml" outfile="${dir.reports}/jdepend.xml"/> | ||
<analyzer type="coderank-mode" value="method"/> | ||
</phpdepend> | ||
</target> | ||
|
||
<!-- ============================================ --> | ||
<!-- Target: documentation (PHP Documentor parsing) --> | ||
<!-- ============================================ --> | ||
<target name="documentation"> | ||
<phpdoc2 title="Project Documentation" destdir="${dir.docs.phpdoc}" template="responsive-twig"> | ||
<fileset refid="sources" /> | ||
</phpdoc2> | ||
</target> | ||
|
||
<!-- ============================================ --> | ||
<!-- Target: unittests (unit testing) --> | ||
<!-- ============================================ --> | ||
<target name="unittests"> | ||
<echo msg="Running unit tests..." /> | ||
<coverage-setup database="${dir.reports.unit}/coverage.db"> | ||
<fileset refid="sources" /> | ||
</coverage-setup> | ||
<phpunit configuration="${dir.tests}/phpunit.xml" codecoverage="true"> | ||
<formatter todir="${dir.reports.unit}" type="xml" /> | ||
<formatter todir="${dir.reports.unit}" type="clover" /> | ||
<batchtest> | ||
<fileset dir="${dir.tests.unit}" /> | ||
</batchtest> | ||
</phpunit> | ||
<coverage-report outfile="${dir.reports.unit}/coverage.xml"> | ||
<report todir="${dir.reports.coverage}" title="Phing unit tests run" usesorttable="true"/> | ||
</coverage-report> | ||
</target> | ||
</project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters