Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 46 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
name: CI

on: [push, pull_request]

jobs:
build-test:
runs-on: ubuntu-latest
strategy:
matrix:
php_version: [8.1, 8.2, 8.3, 8.4]
composer_flags: ['', '--prefer-lowest']

steps:
- uses: actions/checkout@v2

- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php_version }}
extensions: xdebug

- name: Install dependencies
uses: php-actions/composer@v5
with:
php_version: ${{ matrix.php_version }}
args: ${{ matrix.composer_flags }}
command: update

- name: Run tests
run: ./vendor/bin/phpunit --coverage-clover ./tests/logs/clover.xml
env:
XDEBUG_MODE: coverage

- name: Run Codesniffer
run: vendor/bin/phpcs --standard=PSR2 ./src

# - name: Submit coverage to Coveralls
# # We use php-coveralls library for this, as the official Coveralls GitHub Action lacks support for clover reports:
# # https://github.com/coverallsapp/github-action/issues/15
# env:
# COVERALLS_REPO_TOKEN: ${{ secrets.GITHUB_TOKEN }}
# COVERALLS_PARALLEL: true
# COVERALLS_FLAG_NAME: ${{ github.job }}-PHP-${{ matrix.php_version }} ${{ matrix.composer_flags }}
# run: |
# composer global require php-coveralls/php-coveralls
# ~/.composer/vendor/bin/php-coveralls -v
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
vendor
composer.lock
.phpunit.cache
.phpunit.result.cache
15 changes: 7 additions & 8 deletions composer.json
Original file line number Diff line number Diff line change
@@ -1,16 +1,15 @@
{
"name": "rareloop/psr7-server-request-extension",
"require": {
"psr/http-message": "^1.0"
"psr/http-message": "^2",
"php": ">=8.1"
},
"require-dev": {
"laminas/laminas-diactoros": "^2.4",
"phpunit/phpunit": "^6.0",
"mockery/mockery": "^1.0.0",
"brain/monkey": "^2.0.2",
"satooshi/php-coveralls": "^1.0",
"squizlabs/php_codesniffer": "^3.5",
"codedungeon/phpunit-result-printer": "^0.4.4"
"laminas/laminas-diactoros": "^3.6",
"phpunit/phpunit": "^10.5",
"mockery/mockery": "^1.6",
"brain/monkey": "^2.6.2",
"squizlabs/php_codesniffer": "^3.7.2"
},
"autoload": {
"psr-4": {
Expand Down
32 changes: 11 additions & 21 deletions phpunit.xml
Original file line number Diff line number Diff line change
@@ -1,23 +1,13 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit bootstrap="vendor/autoload.php"
backupGlobals="false"
backupStaticAttributes="false"
colors="true"
verbose="true"
convertErrorsToExceptions="true"
convertNoticesToExceptions="true"
convertWarningsToExceptions="true"
processIsolation="false"
stopOnFailure="false"
printerClass="Codedungeon\PHPUnitPrettyResultPrinter\Printer">
<testsuites>
<testsuite name="Rareloop Lumberjack Validation">
<directory>tests</directory>
</testsuite>
</testsuites>
<filter>
<whitelist>
<directory suffix=".php">src/</directory>
</whitelist>
</filter>
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/12.3/phpunit.xsd" bootstrap="vendor/autoload.php" colors="true" cacheDirectory=".phpunit.cache" backupGlobals="false" backupStaticProperties="false">
<testsuites>
<testsuite name="Rareloop Lumberjack Validation">
<directory>tests</directory>
</testsuite>
</testsuites>
<source>
<include>
<directory suffix=".php">src/</directory>
</include>
</source>
</phpunit>
2 changes: 1 addition & 1 deletion tests/TestDiactorosServerRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

use Rareloop\Psr7ServerRequestExtension\InteractsWithInput;
use Rareloop\Psr7ServerRequestExtension\InteractsWithUri;
use Zend\Diactoros\ServerRequest;
use Laminas\Diactoros\ServerRequest;

class TestDiactorosServerRequest extends ServerRequest
{
Expand Down
33 changes: 17 additions & 16 deletions tests/Unit/Psr7ServerRequestExtensionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,44 +2,45 @@

namespace Rareloop\Psr7ServerRequestExtension\Test;

use PHPUnit\Framework\Attributes\Test;
use PHPUnit\Framework\TestCase;
use Rareloop\Psr7ServerRequestExtension\Test\TestDiactorosServerRequest as ServerRequest;

class Psr7ServerRequestExtensionTest extends TestCase
{
/** @test */
#[Test]
public function can_get_path()
{
$request = new ServerRequest([], [], '/test/123', 'GET');

$this->assertSame('/test/123', $request->path());
}

/** @test */
#[Test]
public function can_get_url_without_query_string()
{
$request = new ServerRequest([], [], 'https://test.com/test/123?foo=bar', 'GET');

$this->assertSame('https://test.com/test/123', $request->url());
}

/** @test */
#[Test]
public function can_get_url_with_query_string()
{
$request = new ServerRequest([], [], 'https://test.com/test/123?foo=bar', 'GET');

$this->assertSame('https://test.com/test/123?foo=bar', $request->fullUrl());
}

/** @test */
#[Test]
public function no_trailing_question_mark_is_added_when_no_query_params_are_present()
{
$request = new ServerRequest([], [], 'https://test.com/test/123', 'GET');

$this->assertSame('https://test.com/test/123', $request->fullUrl());
}

/** @test */
#[Test]
public function can_check_method()
{
$request = new ServerRequest([], [], '/test/123', 'GET');
Expand All @@ -50,7 +51,7 @@ public function can_check_method()
$this->assertFalse($request->isMethod('POST'));
}

/** @test */
#[Test]
public function can_get_all_input()
{
$request = new ServerRequest([], [], '/test/123', 'GET', 'php://input', [], [], ['foo' => 'bar'], ['baz' => 'qux']);
Expand All @@ -61,7 +62,7 @@ public function can_get_all_input()
$this->assertSame('qux', $input['baz']);
}

/** @test */
#[Test]
public function can_get_specific_input_with_key()
{
$request = new ServerRequest([], [], '/test/123', 'GET', 'php://input', [], [], ['foo' => 'bar'], ['baz' => 'qux']);
Expand All @@ -70,15 +71,15 @@ public function can_get_specific_input_with_key()
$this->assertSame('qux', $request->input('baz'));
}

/** @test */
#[Test]
public function can_get_default_when_key_is_not_found_in_input()
{
$request = new ServerRequest([], [], '/test/123', 'GET');

$this->assertSame('bar', $request->input('foo', 'bar'));
}

/** @test */
#[Test]
public function can_check_if_input_has_a_specific_key()
{
$request = new ServerRequest([], [], '/test/123', 'GET', 'php://input', [], [], ['foo' => 'bar']);
Expand All @@ -87,15 +88,15 @@ public function can_check_if_input_has_a_specific_key()
$this->assertFalse($request->has('baz'));
}

/** @test */
#[Test]
public function can_check_if_input_has_collection_of_keys()
{
$request = new ServerRequest([], [], '/test/123', 'GET', 'php://input', [], [], ['foo' => 'bar'], ['baz' => 'qux']);

$this->assertTrue($request->has(['foo', 'baz']));
}

/** @test */
#[Test]
public function can_get_all_query()
{
$request = new ServerRequest([], [], '/test/123', 'GET', 'php://input', [], [], ['foo' => 'bar'], ['baz' => 'qux']);
Expand All @@ -106,23 +107,23 @@ public function can_get_all_query()
$this->assertFalse(isset($input['baz']));
}

/** @test */
#[Test]
public function can_get_specific_query_with_key()
{
$request = new ServerRequest([], [], '/test/123', 'GET', 'php://input', [], [], ['foo' => 'bar'], ['baz' => 'qux']);

$this->assertSame('bar', $request->query('foo'));
}

/** @test */
#[Test]
public function can_get_default_when_key_is_not_found_in_query()
{
$request = new ServerRequest([], [], '/test/123', 'GET');

$this->assertSame('bar', $request->query('foo', 'bar'));
}

/** @test */
#[Test]
public function can_get_all_post()
{
$request = new ServerRequest([], [], '/test/123', 'GET', 'php://input', [], [], ['foo' => 'bar'], ['baz' => 'qux']);
Expand All @@ -133,15 +134,15 @@ public function can_get_all_post()
$this->assertFalse(isset($input['foo']));
}

/** @test */
#[Test]
public function can_get_specific_post_with_key()
{
$request = new ServerRequest([], [], '/test/123', 'GET', 'php://input', [], [], ['foo' => 'bar'], ['baz' => 'qux']);

$this->assertSame('qux', $request->post('baz'));
}

/** @test */
#[Test]
public function can_get_default_when_key_is_not_found_in_post()
{
$request = new ServerRequest([], [], '/test/123', 'GET');
Expand Down
Loading