From ae82410bc4d97d8f7f66a37bc7d167ae8d35f15e Mon Sep 17 00:00:00 2001 From: James Arnold Date: Mon, 3 Apr 2023 18:04:02 +0100 Subject: [PATCH 1/8] Fixed deprecated issue in HttpRequest, updated Phpunit, fixed tests and added Github CI --- .github/workflows/push-run-test-suite.yml | 28 +++++++++++++++++++++ .travis.yml | 4 +-- composer.json | 2 +- src/HttpRequest.php | 3 ++- test/Unit/CookieBuilderTest.php | 2 +- test/Unit/HttpCookieTest.php | 2 +- test/Unit/HttpRequestTest.php | 30 ++++++----------------- test/Unit/HttpResponseTest.php | 2 +- 8 files changed, 44 insertions(+), 29 deletions(-) create mode 100644 .github/workflows/push-run-test-suite.yml diff --git a/.github/workflows/push-run-test-suite.yml b/.github/workflows/push-run-test-suite.yml new file mode 100644 index 0000000..461d500 --- /dev/null +++ b/.github/workflows/push-run-test-suite.yml @@ -0,0 +1,28 @@ +name: push-run-test-suite +run-name: ${{ github.event.repository.name }} ${{ github.event.ref }} ${{ github.event.head_commit.message }} run test suite. +on: [push] +jobs: + run-test-suite: + runs-on: ubuntu-latest + steps: + - name: Checkout code + uses: actions/checkout@v3 + - name: Setup PHP + uses: shivammathur/setup-php@v3 + with: + php-version: 8.2 + coverage: none + tools: composer:v2 + - name: Set + - name: Install dependencies + run: composer install --dev --no-interaction + - name: Create build directory + run: mkdir -p build/logs + - name: Run test suite + run: ./vendor/bin/phpunit --bootstrap vendor/autoload.php --coverage-clover build/logs/clover.xml test + - name: Upload coverage to Coveralls + uses: coverallsapp/github-action@master + with: + github-token: ${{ secrets.GITHUB_TOKEN }} + path-to-lcov: build/logs/clover.xml + \ No newline at end of file diff --git a/.travis.yml b/.travis.yml index 927655c..24fd26e 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,9 +1,9 @@ language: php php: - - "5.5" + - "8.2" install: - - composer require satooshi/php-coveralls:~0.6@stable + - composer require php-coveralls/php-coveralls:~2.5 before_script: - mkdir -p build/logs diff --git a/composer.json b/composer.json index 35ac94a..1d40c81 100644 --- a/composer.json +++ b/composer.json @@ -14,7 +14,7 @@ "php": ">=5.5.0" }, "require-dev": { - "phpunit/phpunit": "4.0.*" + "phpunit/phpunit": "^10" }, "autoload": { "psr-4": { diff --git a/src/HttpRequest.php b/src/HttpRequest.php index b9dbd36..babd2b3 100644 --- a/src/HttpRequest.php +++ b/src/HttpRequest.php @@ -9,6 +9,7 @@ class HttpRequest implements Request protected $server; protected $files; protected $cookies; + protected $inputStream; public function __construct( array $get, @@ -16,7 +17,7 @@ public function __construct( array $cookies, array $files, array $server, - $inputStream = '' + string $inputStream = '' ) { $this->getParameters = $get; $this->postParameters = $post; diff --git a/test/Unit/CookieBuilderTest.php b/test/Unit/CookieBuilderTest.php index f858c64..cc677e4 100644 --- a/test/Unit/CookieBuilderTest.php +++ b/test/Unit/CookieBuilderTest.php @@ -4,7 +4,7 @@ use Http\CookieBuilder; -class CookieBuilderTest extends \PHPUnit_Framework_TestCase +class CookieBuilderTest extends \PHPUnit\Framework\TestCase { public function testSetDefaultDomain() { diff --git a/test/Unit/HttpCookieTest.php b/test/Unit/HttpCookieTest.php index 42545b2..a2bdb4b 100644 --- a/test/Unit/HttpCookieTest.php +++ b/test/Unit/HttpCookieTest.php @@ -4,7 +4,7 @@ use Http\HttpCookie; -class HttpCookieTest extends \PHPUnit_Framework_TestCase +class HttpCookieTest extends \PHPUnit\Framework\TestCase { public function testGetName() { diff --git a/test/Unit/HttpRequestTest.php b/test/Unit/HttpRequestTest.php index f47fd3f..17e48fd 100644 --- a/test/Unit/HttpRequestTest.php +++ b/test/Unit/HttpRequestTest.php @@ -4,7 +4,7 @@ use Http\HttpRequest; -class HttpRequestTest extends \PHPUnit_Framework_TestCase +class HttpRequestTest extends \PHPUnit\Framework\TestCase { public function testGetParameter() { @@ -241,11 +241,9 @@ public function testGetMethod() ); } - /** - * @expectedException Http\MissingRequestMetaVariableException - */ public function testGetMethodException() { + $this->expectException(\Http\MissingRequestMetaVariableException::class); $request = new HttpRequest([], [], [], [], []); $request->getMethod(); } @@ -271,11 +269,9 @@ public function testGetUri() ); } - /** - * @expectedException Http\MissingRequestMetaVariableException - */ public function testGetUriException() { + $this->expectException(\Http\MissingRequestMetaVariableException::class); $request = new HttpRequest([], [], [], [], []); $request->getUri(); } @@ -313,11 +309,9 @@ public function testGetHttpAccept() ); } - /** - * @expectedException Http\MissingRequestMetaVariableException - */ public function testGetHttpAcceptException() { + $this->expectException(\Http\MissingRequestMetaVariableException::class); $request = new HttpRequest([], [], [], [], []); $request->getHttpAccept(); } @@ -334,11 +328,9 @@ public function testGetReferer() ); } - /** - * @expectedException Http\MissingRequestMetaVariableException - */ public function testGetRefererException() { + $this->expectException(\Http\MissingRequestMetaVariableException::class); $request = new HttpRequest([], [], [], [], []); $request->getReferer(); } @@ -355,11 +347,9 @@ public function testGetUserAgent() ); } - /** - * @expectedException Http\MissingRequestMetaVariableException - */ public function testGetUserAgentException() { + $this->expectException(\Http\MissingRequestMetaVariableException::class); $request = new HttpRequest([], [], [], [], []); $request->getUserAgent(); } @@ -376,11 +366,9 @@ public function testGetIpAddress() ); } - /** - * @expectedException Http\MissingRequestMetaVariableException - */ public function testGetIpAddressException() { + $this->expectException(\Http\MissingRequestMetaVariableException::class); $request = new HttpRequest([], [], [], [], []); $request->getIpAddress(); } @@ -409,11 +397,9 @@ public function testGetQueryString() ); } - /** - * @expectedException Http\MissingRequestMetaVariableException - */ public function testGetQueryStringException() { + $this->expectException(\Http\MissingRequestMetaVariableException::class); $request = new HttpRequest([], [], [], [], []); $request->getQueryString(); } diff --git a/test/Unit/HttpResponseTest.php b/test/Unit/HttpResponseTest.php index d0f7a58..0d2eb8f 100644 --- a/test/Unit/HttpResponseTest.php +++ b/test/Unit/HttpResponseTest.php @@ -4,7 +4,7 @@ use Http\HttpResponse; -class HttpResponseTest extends \PHPUnit_Framework_TestCase +class HttpResponseTest extends \PHPUnit\Framework\TestCase { public function testSetStatusCode() { From 3c70dc97ca7aaf3c98a8ec7fc0b162d5f199ccd8 Mon Sep 17 00:00:00 2001 From: James Arnold Date: Mon, 3 Apr 2023 18:06:09 +0100 Subject: [PATCH 2/8] fixed typo in workflow --- .github/workflows/push-run-test-suite.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/.github/workflows/push-run-test-suite.yml b/.github/workflows/push-run-test-suite.yml index 461d500..1ca34cb 100644 --- a/.github/workflows/push-run-test-suite.yml +++ b/.github/workflows/push-run-test-suite.yml @@ -13,7 +13,6 @@ jobs: php-version: 8.2 coverage: none tools: composer:v2 - - name: Set - name: Install dependencies run: composer install --dev --no-interaction - name: Create build directory From 5124651a709b6ba6c557fcb1e3c353d43927bd22 Mon Sep 17 00:00:00 2001 From: James Arnold Date: Mon, 3 Apr 2023 21:57:21 +0100 Subject: [PATCH 3/8] changed setup-php version --- .github/workflows/push-run-test-suite.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/push-run-test-suite.yml b/.github/workflows/push-run-test-suite.yml index 1ca34cb..6eddb23 100644 --- a/.github/workflows/push-run-test-suite.yml +++ b/.github/workflows/push-run-test-suite.yml @@ -8,7 +8,7 @@ jobs: - name: Checkout code uses: actions/checkout@v3 - name: Setup PHP - uses: shivammathur/setup-php@v3 + uses: shivammathur/setup-php@v2 with: php-version: 8.2 coverage: none From b88004fed052b78ddc7622d811394705adf08385 Mon Sep 17 00:00:00 2001 From: James Arnold Date: Mon, 3 Apr 2023 21:59:21 +0100 Subject: [PATCH 4/8] added step to install php-coveralls --- .github/workflows/push-run-test-suite.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.github/workflows/push-run-test-suite.yml b/.github/workflows/push-run-test-suite.yml index 6eddb23..a19199f 100644 --- a/.github/workflows/push-run-test-suite.yml +++ b/.github/workflows/push-run-test-suite.yml @@ -13,6 +13,8 @@ jobs: php-version: 8.2 coverage: none tools: composer:v2 + - name : Install php-coveralls + run: composer require php-coveralls/php-coveralls:~2.5 - name: Install dependencies run: composer install --dev --no-interaction - name: Create build directory From 8d82448655b5ad3c499e9b9c8caa7198b4eb6fcd Mon Sep 17 00:00:00 2001 From: James Arnold Date: Mon, 3 Apr 2023 22:09:10 +0100 Subject: [PATCH 5/8] added xdebug to build script --- .github/workflows/push-run-test-suite.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/push-run-test-suite.yml b/.github/workflows/push-run-test-suite.yml index a19199f..a9d83aa 100644 --- a/.github/workflows/push-run-test-suite.yml +++ b/.github/workflows/push-run-test-suite.yml @@ -11,7 +11,7 @@ jobs: uses: shivammathur/setup-php@v2 with: php-version: 8.2 - coverage: none + coverage: xdebug tools: composer:v2 - name : Install php-coveralls run: composer require php-coveralls/php-coveralls:~2.5 From 0e673c2abdcff421195dbe8788fe2168638372fd Mon Sep 17 00:00:00 2001 From: James Arnold Date: Mon, 3 Apr 2023 22:21:09 +0100 Subject: [PATCH 6/8] created phpunit coverage filter --- .gitignore | 3 ++- phpunit.xml | 23 +++++++++++++++++++++++ 2 files changed, 25 insertions(+), 1 deletion(-) create mode 100644 phpunit.xml diff --git a/.gitignore b/.gitignore index 116f35f..60ab8f2 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ vendor composer.lock -.idea \ No newline at end of file +.idea +.phpunit.cache \ No newline at end of file diff --git a/phpunit.xml b/phpunit.xml new file mode 100644 index 0000000..2f6c642 --- /dev/null +++ b/phpunit.xml @@ -0,0 +1,23 @@ + + + + + tests + + + + + + src + + + From a7da0e38ee64a3442622504e2cb40ae146ec47f1 Mon Sep 17 00:00:00 2001 From: James Arnold Date: Tue, 4 Apr 2023 22:04:21 +0100 Subject: [PATCH 7/8] added covers annotations to unit tests --- .gitignore | 3 ++- test/Unit/CookieBuilderTest.php | 4 ++++ test/Unit/HttpCookieTest.php | 3 +++ test/Unit/HttpRequestTest.php | 4 ++++ test/Unit/HttpResponseTest.php | 3 +++ 5 files changed, 16 insertions(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index 60ab8f2..245be7d 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,5 @@ vendor composer.lock .idea -.phpunit.cache \ No newline at end of file +.phpunit.cache +build \ No newline at end of file diff --git a/test/Unit/CookieBuilderTest.php b/test/Unit/CookieBuilderTest.php index cc677e4..9e90357 100644 --- a/test/Unit/CookieBuilderTest.php +++ b/test/Unit/CookieBuilderTest.php @@ -4,6 +4,10 @@ use Http\CookieBuilder; +/** + * @covers Http\CookieBuilder + * @covers Http\HttpCookie + */ class CookieBuilderTest extends \PHPUnit\Framework\TestCase { public function testSetDefaultDomain() diff --git a/test/Unit/HttpCookieTest.php b/test/Unit/HttpCookieTest.php index a2bdb4b..6650755 100644 --- a/test/Unit/HttpCookieTest.php +++ b/test/Unit/HttpCookieTest.php @@ -4,6 +4,9 @@ use Http\HttpCookie; +/** + * @covers Http\HttpCookie + */ class HttpCookieTest extends \PHPUnit\Framework\TestCase { public function testGetName() diff --git a/test/Unit/HttpRequestTest.php b/test/Unit/HttpRequestTest.php index 17e48fd..167b9cc 100644 --- a/test/Unit/HttpRequestTest.php +++ b/test/Unit/HttpRequestTest.php @@ -4,6 +4,10 @@ use Http\HttpRequest; +/** + * @covers Http\HttpRequest + * @uses Http\MissingRequestMetaVariableException + */ class HttpRequestTest extends \PHPUnit\Framework\TestCase { public function testGetParameter() diff --git a/test/Unit/HttpResponseTest.php b/test/Unit/HttpResponseTest.php index 0d2eb8f..e23ea9a 100644 --- a/test/Unit/HttpResponseTest.php +++ b/test/Unit/HttpResponseTest.php @@ -4,6 +4,9 @@ use Http\HttpResponse; +/** + * @covers Http\HttpResponse + */ class HttpResponseTest extends \PHPUnit\Framework\TestCase { public function testSetStatusCode() From 9c5f7055d898da66f94f616b6797d18646ea9913 Mon Sep 17 00:00:00 2001 From: James Arnold Date: Wed, 5 Apr 2023 17:42:14 +0100 Subject: [PATCH 8/8] changed the php coveralls step --- .github/workflows/push-run-test-suite.yml | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/.github/workflows/push-run-test-suite.yml b/.github/workflows/push-run-test-suite.yml index a9d83aa..e885c91 100644 --- a/.github/workflows/push-run-test-suite.yml +++ b/.github/workflows/push-run-test-suite.yml @@ -14,7 +14,7 @@ jobs: coverage: xdebug tools: composer:v2 - name : Install php-coveralls - run: composer require php-coveralls/php-coveralls:~2.5 + run: composer global require php-coveralls/php-coveralls:~2.5 - name: Install dependencies run: composer install --dev --no-interaction - name: Create build directory @@ -22,8 +22,8 @@ jobs: - name: Run test suite run: ./vendor/bin/phpunit --bootstrap vendor/autoload.php --coverage-clover build/logs/clover.xml test - name: Upload coverage to Coveralls - uses: coverallsapp/github-action@master - with: - github-token: ${{ secrets.GITHUB_TOKEN }} - path-to-lcov: build/logs/clover.xml + env: + COVERALLS_REPO_TOKEN: ${{ secrets.GITHUB_TOKEN }} + run: | + php-coveralls --coverage_clover=build/logs/clover.xml -v \ No newline at end of file