Skip to content

Commit

Permalink
Rollback to PHPUnit 9 (#26)
Browse files Browse the repository at this point in the history
  • Loading branch information
SmetDenis committed Apr 17, 2023
1 parent 14fffbc commit 55f8fe5
Show file tree
Hide file tree
Showing 7 changed files with 17 additions and 40 deletions.
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@ server-start: ##@ProjectSpecific Run PHP web-server for PHPUnit tests


server-stop: ##@ProjectSpecific Run PHP web-server for PHPUnit tests
@-pgrep --full "$(JBZOO_TEST_SERVER_HOST):$(JBZOO_TEST_SERVER_FAKE)" | xargs kill -15 || true;
@-pgrep --full "$(JBZOO_TEST_SERVER_HOST):$(JBZOO_TEST_SERVER_PHPUNIT)" | xargs kill -15 || true;
@pgrep -f "$(JBZOO_TEST_SERVER_HOST):$(JBZOO_TEST_SERVER_FAKE)" | xargs kill -15 || true;
@pgrep -f "$(JBZOO_TEST_SERVER_HOST):$(JBZOO_TEST_SERVER_PHPUNIT)" | xargs kill -15 || true;
@sleep 1


Expand Down
3 changes: 2 additions & 1 deletion bin/phpunit-server.sh
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,11 @@ if [ "$3" != "" ]; then HTTP_ROOT=$3; else HTTP_ROOT="."; fi
if [ "$4" != "" ]; then HTTP_FILE=$4; else HTTP_FILE="./index.php"; fi
if [ "$5" != "" ]; then ARGUMENTS=$5; else ARGUMENTS=""; fi

$PHP_BIN -v -v | head -n1
echo "Host: $HTTP_HOST:$HTTP_PORT";
echo "Root: $HTTP_ROOT";
echo "File: $HTTP_FILE";
echo "Args: $ARGUMENTS";
echo "";

XDEBUG_MODE=coverage PHPUNINT_ARGUMENTS="$ARGUMENTS" php -S "$HTTP_HOST:$HTTP_PORT" -t "$HTTP_ROOT" "$HTTP_FILE" &
XDEBUG_MODE=coverage PHPUNINT_ARGUMENTS="$ARGUMENTS" $PHP_BIN -S "$HTTP_HOST:$HTTP_PORT" -t "$HTTP_ROOT" "$HTTP_FILE" &
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
"ext-filter" : "*",
"ext-mbstring" : "*",

"phpunit/phpunit" : ">=10.0.19",
"phpunit/phpunit" : "^9.6.7",
"ulrichsg/getopt-php" : ">=4.0.3",
"jbzoo/markdown" : "7.x-dev"
},
Expand Down
13 changes: 1 addition & 12 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -12,19 +12,8 @@
-->
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
bootstrap="tests/autoload.php"
convertErrorsToExceptions="true"
convertNoticesToExceptions="true"
convertWarningsToExceptions="true"
convertDeprecationsToExceptions="true"
executionOrder="random"
processIsolation="false"
stopOnError="false"
stopOnFailure="false"
stopOnIncomplete="false"
stopOnSkipped="false"
stopOnRisky="false"
verbose="true"
colors="false"
colors="true"
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.3/phpunit.xsd"
>
<coverage processUncoveredFiles="true">
Expand Down
2 changes: 1 addition & 1 deletion src/CovCatcher.php
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ protected function start(): void
{
if (!$this->isStarted) {
$this->isStarted = true;
$this->coverage?->start($this->hash, null, true);
$this->coverage?->start($this->hash, true);
}
}

Expand Down
17 changes: 10 additions & 7 deletions src/functions/tools.php
Original file line number Diff line number Diff line change
Expand Up @@ -72,11 +72,16 @@ function openFile(string $path): ?string
}

/**
* @param array<mixed>|string $args
* @param array<bool|int|string> $options
* @param null|array<mixed>|string $args
* @param array<bool|int|string> $options
* @codeCoverageIgnore
*/
function httpRequest(string $url, $args = null, string $method = Request::GET, array $options = []): Response
{
function httpRequest(
string $url,
array|string $args = null,
string $method = Request::GET,
array $options = [],
): Response {
if (!\class_exists(HttpClient::class)) {
throw new Exception('jbzoo/http-client is required for httpRequest() function');
}
Expand All @@ -85,9 +90,7 @@ function httpRequest(string $url, $args = null, string $method = Request::GET, a
$options['timeout'] = 600; // For PHPUnit coverage
}

$client = new HttpClient($options);

return $client->request($url, $args, $method, $options);
return (new HttpClient($options))->request($url, $args, $method, $options);
}

function getTestName(bool $withNamespace = false): ?string
Expand Down
16 changes: 0 additions & 16 deletions tests/PHPUnitToolsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,22 +18,6 @@

class PHPUnitToolsTest extends PHPUnit
{
public function testHttpRequest(): void
{
$uniq = \uniqid('', true);
$url = 'https://httpbin.org/post';
$args = ['qwerty' => $uniq];

$result = httpRequest($url, $args, 'post');

isSame(200, $result->code);
isContain('application/json', $result->getHeader('content-type'));

$body = $result->getJSON();
isContain('httpbin.org/post', $body->find('url'));
isSame($body->find('form.qwerty'), $uniq);
}

public function testCliError(): void
{
skip('Some message...');
Expand Down

0 comments on commit 55f8fe5

Please sign in to comment.