From b37585f95e8675a367bd067d41c518af5a6d7210 Mon Sep 17 00:00:00 2001 From: Kai Sassnowski Date: Mon, 18 Apr 2022 18:12:58 +0200 Subject: [PATCH 01/11] wip --- tests/Server/index.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/tests/Server/index.php b/tests/Server/index.php index 5526b43..ebbc329 100644 --- a/tests/Server/index.php +++ b/tests/Server/index.php @@ -60,6 +60,8 @@ $app->get('/crawled-routes', static function (Request $request, Response $response, $args): Response { $stats = \file_get_contents(LOG_PATH); + dump($stats); + $response->getBody()->write($stats); return $response From 7c982d02b20f5aace0342caa4162e3c1b41caa90 Mon Sep 17 00:00:00 2001 From: Kai Sassnowski Date: Mon, 18 Apr 2022 18:15:52 +0200 Subject: [PATCH 02/11] wipgst --- .github/workflows/run-tests.yml | 6 +++--- tests/Server/index.php | 2 -- 2 files changed, 3 insertions(+), 5 deletions(-) diff --git a/.github/workflows/run-tests.yml b/.github/workflows/run-tests.yml index 3502f8e..1215a0b 100644 --- a/.github/workflows/run-tests.yml +++ b/.github/workflows/run-tests.yml @@ -9,7 +9,7 @@ jobs: fail-fast: false matrix: os: [ubuntu-latest] - php: ['8.0', 8.1] + php: [8.1] dependency-version: [prefer-lowest, prefer-stable] name: P${{ matrix.php }} - ${{ matrix.dependency-version }} - ${{ matrix.os }} @@ -45,8 +45,8 @@ jobs: - name: Install dependencies run: composer update --${{ matrix.dependency-version }} --no-interaction --prefer-source - - name: Run psalm - run: composer analyze -- --php-version=${{ matrix.php }} + # - name: Run psalm + # run: composer analyze -- --php-version=${{ matrix.php }} - name: Start server run: (php -S localhost:8000 -t ./tests/Server &) || /bin/true diff --git a/tests/Server/index.php b/tests/Server/index.php index ebbc329..5526b43 100644 --- a/tests/Server/index.php +++ b/tests/Server/index.php @@ -60,8 +60,6 @@ $app->get('/crawled-routes', static function (Request $request, Response $response, $args): Response { $stats = \file_get_contents(LOG_PATH); - dump($stats); - $response->getBody()->write($stats); return $response From 4e13a2dd1247285b5aff5a09f1523552cfa62c58 Mon Sep 17 00:00:00 2001 From: Kai Sassnowski Date: Mon, 18 Apr 2022 18:19:16 +0200 Subject: [PATCH 03/11] wip --- tests/IntegrationTest.php | 2 ++ tests/Server/index.php | 15 +++++++++++---- 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/tests/IntegrationTest.php b/tests/IntegrationTest.php index f64407e..26d57b2 100644 --- a/tests/IntegrationTest.php +++ b/tests/IntegrationTest.php @@ -65,6 +65,8 @@ private function getCrawledRoutes(): array { $response = \file_get_contents("{$this->serverUrl}/crawled-routes"); + dump($response); + if (!$response) { return []; } diff --git a/tests/Server/index.php b/tests/Server/index.php index 5526b43..55d9f3e 100644 --- a/tests/Server/index.php +++ b/tests/Server/index.php @@ -58,12 +58,19 @@ }); $app->get('/crawled-routes', static function (Request $request, Response $response, $args): Response { - $stats = \file_get_contents(LOG_PATH); + try { + $stats = \file_get_contents(LOG_PATH); + + $response->getBody()->write($stats); - $response->getBody()->write($stats); + return $response + ->withHeader('Content-Type', 'application/json'); + } catch (Throwable $e) { + $response->getBody()->write($e->getMessage()); + + return $response; + } - return $response - ->withHeader('Content-Type', 'application/json'); }); $app->get('/robots', static function (Request $request, Response $response, $args): Response { From 753954a350677a1ac9337e5fdd06c91408608a1d Mon Sep 17 00:00:00 2001 From: ksassnowski Date: Mon, 18 Apr 2022 16:19:41 +0000 Subject: [PATCH 04/11] Apply php-cs-fixer changes --- tests/Server/index.php | 1 - 1 file changed, 1 deletion(-) diff --git a/tests/Server/index.php b/tests/Server/index.php index 55d9f3e..d1bc3e2 100644 --- a/tests/Server/index.php +++ b/tests/Server/index.php @@ -70,7 +70,6 @@ return $response; } - }); $app->get('/robots', static function (Request $request, Response $response, $args): Response { From 1b432ee4453774087840305bf9b1a5d9833d3f53 Mon Sep 17 00:00:00 2001 From: Kai Sassnowski Date: Mon, 18 Apr 2022 18:22:02 +0200 Subject: [PATCH 05/11] wip --- tests/IntegrationTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/IntegrationTest.php b/tests/IntegrationTest.php index 26d57b2..f4f60eb 100644 --- a/tests/IntegrationTest.php +++ b/tests/IntegrationTest.php @@ -65,7 +65,7 @@ private function getCrawledRoutes(): array { $response = \file_get_contents("{$this->serverUrl}/crawled-routes"); - dump($response); + var_dump($response); if (!$response) { return []; From 80c4a385e9c7fdb577c10b1aea8d7381d9eec033 Mon Sep 17 00:00:00 2001 From: ksassnowski Date: Mon, 18 Apr 2022 16:23:39 +0000 Subject: [PATCH 06/11] Apply php-cs-fixer changes --- tests/IntegrationTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/IntegrationTest.php b/tests/IntegrationTest.php index f4f60eb..aea9541 100644 --- a/tests/IntegrationTest.php +++ b/tests/IntegrationTest.php @@ -65,7 +65,7 @@ private function getCrawledRoutes(): array { $response = \file_get_contents("{$this->serverUrl}/crawled-routes"); - var_dump($response); + \var_dump($response); if (!$response) { return []; From b3a04aeeb8cf8a0c30c82395817a52bee3a23fb0 Mon Sep 17 00:00:00 2001 From: Kai Sassnowski Date: Mon, 18 Apr 2022 18:26:33 +0200 Subject: [PATCH 07/11] wip --- tests/Server/index.php | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/tests/Server/index.php b/tests/Server/index.php index d1bc3e2..c654ffd 100644 --- a/tests/Server/index.php +++ b/tests/Server/index.php @@ -58,18 +58,16 @@ }); $app->get('/crawled-routes', static function (Request $request, Response $response, $args): Response { - try { - $stats = \file_get_contents(LOG_PATH); + $stats = \file_get_contents(LOG_PATH); - $response->getBody()->write($stats); + if ($stats === false) { + $stats = '{}'; + } - return $response - ->withHeader('Content-Type', 'application/json'); - } catch (Throwable $e) { - $response->getBody()->write($e->getMessage()); + $response->getBody()->write($stats); - return $response; - } + return $response + ->withHeader('Content-Type', 'application/json'); }); $app->get('/robots', static function (Request $request, Response $response, $args): Response { From 85fad0179c92fad17f03f98ec5813d0a641ea7af Mon Sep 17 00:00:00 2001 From: ksassnowski Date: Mon, 18 Apr 2022 16:27:59 +0000 Subject: [PATCH 08/11] Apply php-cs-fixer changes --- tests/Server/index.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/Server/index.php b/tests/Server/index.php index c654ffd..325b0e1 100644 --- a/tests/Server/index.php +++ b/tests/Server/index.php @@ -60,7 +60,7 @@ $app->get('/crawled-routes', static function (Request $request, Response $response, $args): Response { $stats = \file_get_contents(LOG_PATH); - if ($stats === false) { + if (false === $stats) { $stats = '{}'; } From c8b9158cef27f336fd799da1f73eec1ade293002 Mon Sep 17 00:00:00 2001 From: Kai Sassnowski Date: Mon, 18 Apr 2022 18:31:27 +0200 Subject: [PATCH 09/11] wip --- .github/workflows/fix-style.yml | 33 --------------------------------- .github/workflows/run-tests.yml | 4 ++-- tests/IntegrationTest.php | 2 -- 3 files changed, 2 insertions(+), 37 deletions(-) delete mode 100644 .github/workflows/fix-style.yml diff --git a/.github/workflows/fix-style.yml b/.github/workflows/fix-style.yml deleted file mode 100644 index fb27248..0000000 --- a/.github/workflows/fix-style.yml +++ /dev/null @@ -1,33 +0,0 @@ -name: fix-style - -on: [push] - -jobs: - cs-fix: - runs-on: ubuntu-latest - - steps: - - name: Get branch names - id: branch-name - uses: tj-actions/branch-names@v5.1 - - - name: Checkout code - uses: actions/checkout@v2 - with: - ref: ${{ github.head_ref }} - - - name: Setup PHP - uses: shivammathur/setup-php@v2 - with: - php-version: 8.0 - - - name: Install dependencies - run: composer install - - - name: Fix style - run: ./vendor/bin/php-cs-fixer fix --allow-risky=yes --using-cache=no - - - name: Commit style fixes - uses: stefanzweifel/git-auto-commit-action@v4 - with: - commit_message: Apply php-cs-fixer changes diff --git a/.github/workflows/run-tests.yml b/.github/workflows/run-tests.yml index 1215a0b..b365765 100644 --- a/.github/workflows/run-tests.yml +++ b/.github/workflows/run-tests.yml @@ -10,7 +10,7 @@ jobs: matrix: os: [ubuntu-latest] php: [8.1] - dependency-version: [prefer-lowest, prefer-stable] + dependency-version: [prefer-stable] name: P${{ matrix.php }} - ${{ matrix.dependency-version }} - ${{ matrix.os }} @@ -52,4 +52,4 @@ jobs: run: (php -S localhost:8000 -t ./tests/Server &) || /bin/true - name: Execute tests - run: vendor/bin/phpunit + run: vendor/bin/phpunit --filter SpiderTest diff --git a/tests/IntegrationTest.php b/tests/IntegrationTest.php index aea9541..f64407e 100644 --- a/tests/IntegrationTest.php +++ b/tests/IntegrationTest.php @@ -65,8 +65,6 @@ private function getCrawledRoutes(): array { $response = \file_get_contents("{$this->serverUrl}/crawled-routes"); - \var_dump($response); - if (!$response) { return []; } From 8c63fb44b0ec91326dfdf5f14eabcda7bc13d7c7 Mon Sep 17 00:00:00 2001 From: Kai Sassnowski Date: Mon, 18 Apr 2022 18:36:26 +0200 Subject: [PATCH 10/11] wip --- src/Roach.php | 5 +++++ tests/RoachTest.php | 5 +++++ tests/Shell/Commands/RunSpiderCommandTest.php | 5 +++++ 3 files changed, 15 insertions(+) diff --git a/src/Roach.php b/src/Roach.php index 7181197..87f7cd9 100644 --- a/src/Roach.php +++ b/src/Roach.php @@ -41,6 +41,11 @@ public static function fake(): FakeRunner return self::$runnerFake; } + public static function restore(): void + { + self::$runnerFake = null; + } + /** * Start the spider run without collecting scraped items. * diff --git a/tests/RoachTest.php b/tests/RoachTest.php index 9b50635..bc22c19 100644 --- a/tests/RoachTest.php +++ b/tests/RoachTest.php @@ -23,6 +23,11 @@ */ final class RoachTest extends TestCase { + protected function tearDown(): void + { + Roach::restore(); + } + public function testFakingRunnerReturnsRunnerFake(): void { $runner = Roach::fake(); diff --git a/tests/Shell/Commands/RunSpiderCommandTest.php b/tests/Shell/Commands/RunSpiderCommandTest.php index d9040bd..3dfc204 100644 --- a/tests/Shell/Commands/RunSpiderCommandTest.php +++ b/tests/Shell/Commands/RunSpiderCommandTest.php @@ -25,6 +25,11 @@ */ final class RunSpiderCommandTest extends TestCase { + protected function tearDown(): void + { + Roach::restore(); + } + public function testStartRunForProvidedSpider(): void { $runner = Roach::fake(); From b1db8839e4329806d15c9f11afa6098f86047011 Mon Sep 17 00:00:00 2001 From: Kai Sassnowski Date: Mon, 18 Apr 2022 18:36:47 +0200 Subject: [PATCH 11/11] wip --- .github/workflows/run-tests.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/run-tests.yml b/.github/workflows/run-tests.yml index b365765..3cc1d94 100644 --- a/.github/workflows/run-tests.yml +++ b/.github/workflows/run-tests.yml @@ -52,4 +52,4 @@ jobs: run: (php -S localhost:8000 -t ./tests/Server &) || /bin/true - name: Execute tests - run: vendor/bin/phpunit --filter SpiderTest + run: vendor/bin/phpunit