Skip to content

Commit 9043746

Browse files
committed
First commit generating the basic structure to work
1 parent bf31337 commit 9043746

File tree

8 files changed

+174
-0
lines changed

8 files changed

+174
-0
lines changed

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
vendor
2+
.idea
3+
composer.lock

Makefile

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
2+
SHELL:=/bin/bash
3+
.DEFAULT_GOAL:=help
4+
.PHONY: help install up code-sniff code-format code-find-bugs code-find-bugs code-find-smells
5+
PHP_CONTAINER_NAME=php
6+
7+
help: ## Display this help
8+
@awk 'BEGIN {FS = ":.*##"; printf "\nUsage:\n make \033[36m<target>\033[0m\n\nTargets:\n"} /^[a-zA-Z0-9_-]+:.*?##/ { printf " \033[36m%-25s\033[0m %s\n", $$1, $$2 }' $(MAKEFILE_LIST)
9+
10+
11+
install: composer-install up ## Install required software and initialize your local configuration
12+
13+
up: ## Start application containers and required services
14+
@docker-compose up -d
15+
16+
down: ## Stop application containers and required services
17+
@docker-compose down
18+
19+
console: ## Execute php container console
20+
@docker exec -it ${PHP_CONTAINER_NAME} bash
21+
22+
test: ## Execute all phpunit test
23+
@docker-compose exec ${PHP_CONTAINER_NAME} ./vendor/bin/phpunit
24+
25+
code-sniff cs: ## Detect coding standard violations in all project files using code sniffer
26+
@docker-compose exec ${PHP_CONTAINER_NAME} ./vendor/bin/phpcs
27+
28+
code-format cf: ## Fix coding standard violations in all project files
29+
@docker-compose exec ${PHP_CONTAINER_NAME} ./vendor/bin/phpcbf
30+
31+
code-find-bugs phpstan: ## Run static analysis tool to find possible bugs using phpstan
32+
@docker-compose exec ${PHP_CONTAINER_NAME} ./vendor/bin/phpstan analyse
33+
34+
code-find-smells md: ## Run static analysis tool to find code smells using mess detector
35+
@docker-compose exec ${PHP_CONTAINER_NAME} ./vendor/bin/phpmd src,tests text phpmd.xml --suffixes php --exclude src/Infrastructure/Persistence/Doctrine/Migrations,tests/_support,tests/acceptance
36+
37+
composer-update: ## Run composer update
38+
@docker run --rm --interactive --tty --volume $PWD:/app composer update
39+
40+
composer-install: ## Run composer update
41+
@docker run --rm --interactive --tty --volume $PWD:/app composer install
42+
43+

composer.json

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
{
2+
"name": "devizzent/codeception-mockserver-helper",
3+
"description": "Codeception helper to manage and verify MockServer expectations",
4+
"type": "dev",
5+
"license": "library",
6+
"autoload": {
7+
"psr-4": {
8+
"DEVizzent\\CodeceptionMockServerHelper\\": "src/"
9+
}
10+
},
11+
"authors": [
12+
{
13+
"name": "Vicent Valls",
14+
"email": "vizzent@gmail.com",
15+
"role": "creator"
16+
}
17+
],
18+
"minimum-stability": "stable",
19+
"require": {
20+
"php": "7.4.*||8.*",
21+
"guzzlehttp/guzzle": "^7.0",
22+
"codeception/codeception": "4.*||5.*",
23+
"phpunit/phpunit": "8.* || 9.*"
24+
},
25+
"require-dev": {
26+
"phpmd/phpmd": "2.*",
27+
"phpstan/phpstan": "1.*",
28+
"squizlabs/php_codesniffer": "3.*"
29+
}
30+
}

docker-compose.yml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
version: "3"
2+
services:
3+
php:
4+
container_name: php
5+
build:
6+
dockerfile: docker/php/Dockerfile
7+
context: .
8+
volumes:
9+
- .:/app
10+
tty: true
11+
mockserver:
12+
image: mockserver/mockserver

docker/php/Dockerfile

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
FROM php:8.1
2+
3+
WORKDIR /app

phpunit.xml

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
3+
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.5/phpunit.xsd"
4+
bootstrap="vendor/autoload.php"
5+
cacheResultFile="var/phpunit/test-results"
6+
executionOrder="depends,defects"
7+
forceCoversAnnotation="true"
8+
beStrictAboutCoversAnnotation="true"
9+
beStrictAboutOutputDuringTests="true"
10+
beStrictAboutTodoAnnotatedTests="true"
11+
convertDeprecationsToExceptions="true"
12+
failOnRisky="true"
13+
failOnWarning="true"
14+
verbose="true">
15+
<testsuites>
16+
<testsuite name="default">
17+
<directory>tests</directory>
18+
</testsuite>
19+
</testsuites>
20+
21+
<coverage cacheDirectory="var/phpunit//code-coverage"
22+
processUncoveredFiles="true">
23+
<include>
24+
<directory suffix=".php">src</directory>
25+
</include>
26+
</coverage>
27+
</phpunit>

src/MockServerHelper.php

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
<?php
2+
3+
namespace DEVizzent\CodeceptionMockServerHelper;
4+
5+
use Codeception\Module;
6+
use GuzzleHttp\Client;
7+
use GuzzleHttp\Psr7\Request;
8+
use PHPUnit\Framework\Assert;
9+
10+
class MockServerHelper extends Module
11+
{
12+
private Client $mockserverClient;
13+
14+
public function __construct()
15+
{
16+
$this->mockserverClient = new Client(['base_uri' => 'http://mockserver:1080']);
17+
}
18+
19+
public function seeMockRequestWasCalled(string $expectationId, int $times = 1): void
20+
{
21+
$body = [
22+
'expectationId' => ['id' => $expectationId],
23+
'times' => ['atLeast' => $times, 'atMost' => $times]
24+
];
25+
$request = new Request('PUT', '/mockserver/verify', [], json_encode($body));
26+
$response = $this->mockserverClient->sendRequest($request);
27+
Assert::assertEquals(
28+
202,
29+
$response->getStatusCode(),
30+
$response->getBody()->getContents()
31+
);
32+
}
33+
34+
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
<?php
2+
3+
namespace Integration;
4+
5+
use DEVizzent\CodeceptionMockServerHelper\MockServerHelper;
6+
use PHPUnit\Framework\TestCase;
7+
8+
class SeeMockRequestWasCalledTest extends TestCase
9+
{
10+
private MockServerHelper $sot;
11+
12+
protected function setUp(): void
13+
{
14+
parent::setUp();
15+
$this->sot = new MockServerHelper();
16+
}
17+
18+
public function testExpectationNotWasCalledThrowException(): void
19+
{
20+
$this->sot->seeMockRequestWasCalled('some-expectation');
21+
}
22+
}

0 commit comments

Comments
 (0)