diff --git a/.editorconfig b/.editorconfig index a828607..5e5b915 100644 --- a/.editorconfig +++ b/.editorconfig @@ -11,6 +11,6 @@ indent_style = tab indent_size = tab tab_width = 4 -[{*.json,*.yml,*.yaml,*.md}] +[*.{json,yaml,yml,md}] indent_style = space indent_size = 2 diff --git a/.gitattributes b/.gitattributes index 12910b6..3645ae7 100644 --- a/.gitattributes +++ b/.gitattributes @@ -1,10 +1,10 @@ # Not archived .docs export-ignore +.github export-ignore tests export-ignore .editorconfig export-ignore .gitattributes export-ignore .gitignore export-ignore -.travis.yml export-ignore Makefile export-ignore phpstan.neon export-ignore README.md export-ignore diff --git a/.github/.kodiak.toml b/.github/.kodiak.toml deleted file mode 100644 index 60c34b6..0000000 --- a/.github/.kodiak.toml +++ /dev/null @@ -1,10 +0,0 @@ -version = 1 - -[merge] -automerge_label = "automerge" -blacklist_title_regex = "^WIP.*" -blacklist_labels = ["WIP"] -method = "rebase" -delete_branch_on_merge = true -notify_on_conflict = true -optimistic_updates = false diff --git a/.github/workflows/codesniffer.yml b/.github/workflows/codesniffer.yml index dfc76ff..1d975aa 100644 --- a/.github/workflows/codesniffer.yml +++ b/.github/workflows/codesniffer.yml @@ -3,6 +3,8 @@ name: "Codesniffer" on: pull_request: + workflow_dispatch: + push: branches: ["*"] @@ -12,4 +14,6 @@ on: jobs: codesniffer: name: "Codesniffer" - uses: contributte/.github/.github/workflows/codesniffer.yml@v1 + uses: contributte/.github/.github/workflows/codesniffer.yml@master + with: + php: "8.2" diff --git a/.github/workflows/coverage.yml b/.github/workflows/coverage.yml index 121f718..0cabb25 100644 --- a/.github/workflows/coverage.yml +++ b/.github/workflows/coverage.yml @@ -3,6 +3,8 @@ name: "Coverage" on: pull_request: + workflow_dispatch: + push: branches: ["*"] @@ -12,4 +14,6 @@ on: jobs: coverage: name: "Nette Tester" - uses: contributte/.github/.github/workflows/nette-tester-coverage.yml@v1 + uses: contributte/.github/.github/workflows/nette-tester-coverage-v2.yml@master + with: + php: "8.2" diff --git a/.github/workflows/phpstan.yml b/.github/workflows/phpstan.yml index 43545cf..8eb74da 100644 --- a/.github/workflows/phpstan.yml +++ b/.github/workflows/phpstan.yml @@ -3,6 +3,8 @@ name: "PHPStan" on: pull_request: + workflow_dispatch: + push: branches: ["*"] @@ -12,4 +14,6 @@ on: jobs: phpstan: name: "PHPStan" - uses: contributte/.github/.github/workflows/phpstan.yml@v1 + uses: contributte/.github/.github/workflows/phpstan.yml@master + with: + php: "8.2" diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 7dc19e9..7decc81 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -3,6 +3,8 @@ name: "Nette Tester" on: pull_request: + workflow_dispatch: + push: branches: ["*"] @@ -10,27 +12,33 @@ on: - cron: "0 8 * * 1" jobs: - test82: + test85: + name: "Nette Tester" + uses: contributte/.github/.github/workflows/nette-tester.yml@master + with: + php: "8.5" + + test84: name: "Nette Tester" - uses: contributte/.github/.github/workflows/nette-tester.yml@v1 + uses: contributte/.github/.github/workflows/nette-tester.yml@master with: - php: "8.2" + php: "8.4" - test81: + test83: name: "Nette Tester" - uses: contributte/.github/.github/workflows/nette-tester.yml@v1 + uses: contributte/.github/.github/workflows/nette-tester.yml@master with: - php: "8.1" + php: "8.3" - test80: + test82: name: "Nette Tester" - uses: contributte/.github/.github/workflows/nette-tester.yml@v1 + uses: contributte/.github/.github/workflows/nette-tester.yml@master with: - php: "8.0" + php: "8.2" testlowest: name: "Nette Tester" - uses: contributte/.github/.github/workflows/nette-tester.yml@v1 + uses: contributte/.github/.github/workflows/nette-tester.yml@master with: - php: "8.0" + php: "8.2" composer: "composer update --no-interaction --no-progress --prefer-dist --prefer-stable --prefer-lowest" diff --git a/.gitignore b/.gitignore index b0fa45a..8ce352a 100644 --- a/.gitignore +++ b/.gitignore @@ -6,4 +6,9 @@ /composer.lock # Tests -/coverage.xml +/tests/tmp +/coverage.* +*.expected +*.actual +*.log +*.html diff --git a/Makefile b/Makefile index af542a9..33bc117 100644 --- a/Makefile +++ b/Makefile @@ -1,26 +1,31 @@ -.PHONY: install qa cs csf phpstan tests coverage - +.PHONY: install install: composer update +.PHONY: qa qa: phpstan cs +.PHONY: cs cs: ifdef GITHUB_ACTION - vendor/bin/phpcs --standard=ruleset.xml --encoding=utf-8 --colors -nsp -q --report=checkstyle src tests | cs2pr + vendor/bin/phpcs --standard=ruleset.xml --encoding=utf-8 --extensions="php,phpt" --colors -nsp -q --report=checkstyle src tests | cs2pr else - vendor/bin/phpcs --standard=ruleset.xml --encoding=utf-8 --colors -nsp src tests + vendor/bin/phpcs --standard=ruleset.xml --encoding=utf-8 --extensions="php,phpt" --colors -nsp src tests endif +.PHONY: csf csf: - vendor/bin/phpcbf --standard=ruleset.xml --encoding=utf-8 --colors -nsp src tests + vendor/bin/phpcbf --standard=ruleset.xml --encoding=utf-8 --extensions="php,phpt" --colors -nsp src tests +.PHONY: phpstan phpstan: vendor/bin/phpstan analyse -c phpstan.neon +.PHONY: tests tests: vendor/bin/tester -s -p php --colors 1 -C tests/Cases +.PHONY: coverage coverage: ifdef GITHUB_ACTION vendor/bin/tester -s -p phpdbg --colors 1 -C --coverage coverage.xml --coverage-src src tests/Cases diff --git a/composer.json b/composer.json index c770fac..03b55c5 100644 --- a/composer.json +++ b/composer.json @@ -19,7 +19,7 @@ } ], "require": { - "php": ">=8.0", + "php": ">=8.2", "guzzlehttp/guzzle": "^7.5.0", "nette/di": "^3.1.2", "nette/utils": "^3.2.8 || ^4.0.0", @@ -27,8 +27,8 @@ }, "require-dev": { "mockery/mockery": "^1.5.1", - "contributte/tester": "^0.1.0", - "contributte/qa": "^0.4.0", + "contributte/tester": "~0.4.0", + "contributte/qa": "~0.4.0", "phpstan/phpstan": "^1.9.4", "phpstan/phpstan-deprecation-rules": "^1.1.1", "phpstan/phpstan-nette": "^1.2.0", @@ -39,6 +39,11 @@ "Contributte\\Guzzlette\\": "src" } }, + "autoload-dev": { + "psr-4": { + "Tests\\": "tests" + } + }, "minimum-stability": "dev", "prefer-stable": true, "config": { diff --git a/phpstan.neon b/phpstan.neon index 0ec6e59..588d49b 100644 --- a/phpstan.neon +++ b/phpstan.neon @@ -6,7 +6,7 @@ includes: parameters: level: 9 - phpVersion: 80000 + phpVersion: 80200 scanDirectories: - src @@ -18,3 +18,4 @@ parameters: - src ignoreErrors: + - '#Call to an undefined method Nette\\Schema\\Elements\\Structure\|Nette\\Schema\\Elements\\Type::dynamic\(\)#' diff --git a/ruleset.xml b/ruleset.xml index 5fd3edf..e335cc6 100644 --- a/ruleset.xml +++ b/ruleset.xml @@ -1,7 +1,7 @@ - + diff --git a/tests/.coveralls.yml b/tests/.coveralls.yml deleted file mode 100644 index 403f48b..0000000 --- a/tests/.coveralls.yml +++ /dev/null @@ -1,4 +0,0 @@ -# for php-coveralls -service_name: github-actions -coverage_clover: coverage.xml -json_path: coverage.json \ No newline at end of file diff --git a/tests/Cases/GuzzleExtensionTest.phpt b/tests/Cases/GuzzleExtensionTest.phpt index ff2c993..50e8c14 100644 --- a/tests/Cases/GuzzleExtensionTest.phpt +++ b/tests/Cases/GuzzleExtensionTest.phpt @@ -1,84 +1,73 @@ load(function (Compiler $compiler): void { + $compiler->addConfig([ + 'guzzle' => [ + 'debug' => true, + ], + ]); + $compiler->addExtension('guzzle', new GuzzleExtension()); + }, [getmypid(), 1]); - public function testExtensionDebug(): void - { - $loader = new ContainerLoader(TEMP_DIR, true); - $class = $loader->load(function (Compiler $compiler): void { - $compiler->addConfig([ - 'guzzle' => [ - 'debug' => true, - ], - ]); - $compiler->addExtension('guzzle', new GuzzleExtension()); - }, [getmypid(), 1]); + /** @var Container $container */ + $container = new $class(); - /** @var Container $container */ - $container = new $class(); + Assert::count(1, $container->findByType(Client::class)); + Assert::count(1, $container->findByType(ClientFactory::class)); +}); - Assert::count(1, $container->findByType(Client::class)); - Assert::count(1, $container->findByType(ClientFactory::class)); - } +Toolkit::test(function (): void { + $loader = new ContainerLoader(Environment::getTestDir(), true); + $class = $loader->load(function (Compiler $compiler): void { + $compiler->addConfig([ + 'guzzle' => [ + 'debug' => false, + ], + ]); + $compiler->addExtension('guzzle', new GuzzleExtension()); + }, [getmypid(), 2]); - public function testExtensionProduction(): void - { - $loader = new ContainerLoader(TEMP_DIR, true); - $class = $loader->load(function (Compiler $compiler): void { - $compiler->addConfig([ - 'guzzle' => [ - 'debug' => false, - ], - ]); - $compiler->addExtension('guzzle', new GuzzleExtension()); - }, [getmypid(), 2]); + /** @var Container $container */ + $container = new $class(); - /** @var Container $container */ - $container = new $class(); + Assert::count(1, $container->findByType(Client::class)); + Assert::count(1, $container->findByType(ClientFactory::class)); +}); - Assert::count(1, $container->findByType(Client::class)); - Assert::count(1, $container->findByType(ClientFactory::class)); - } +Toolkit::test(function (): void { + $loader = new ContainerLoader(Environment::getTestDir(), true); + $class = $loader->load(function (Compiler $compiler): void { + $compiler->setDynamicParameterNames(['guzzle-client']); + $compiler->addConfig([ + 'parameters' => [ + 'guzzle-client' => [], + ], + 'guzzle' => [ + 'client' => '%guzzle-client%', + ], + ]); + $compiler->addExtension('guzzle', new GuzzleExtension()); + }, [getmypid(), 3]); - public function testExtensionDynamic(): void - { - $loader = new ContainerLoader(TEMP_DIR, true); - $class = $loader->load(function (Compiler $compiler): void { - $compiler->setDynamicParameterNames(['guzzle-client']); - $compiler->addConfig([ - 'parameters'=>[ - 'guzzle-client' => [], - ], - 'guzzle' => [ - 'client' => '%guzzle-client%' - ], - ]); - $compiler->addExtension('guzzle', new GuzzleExtension()); - }, [getmypid(), 1]); + /** @var Container $container */ + $container = new $class(); - /** @var Container $container */ - $container = new $class(); - - Assert::count(1, $container->findByType(Client::class)); - Assert::count(1, $container->findByType(ClientFactory::class)); - } -} - -(new GuzzleExtensionTest())->run(); + Assert::count(1, $container->findByType(Client::class)); + Assert::count(1, $container->findByType(ClientFactory::class)); +}); diff --git a/tests/Cases/GuzzleHandlerTest.phpt b/tests/Cases/GuzzleHandlerTest.phpt index 67c329e..75daf49 100644 --- a/tests/Cases/GuzzleHandlerTest.phpt +++ b/tests/Cases/GuzzleHandlerTest.phpt @@ -1,72 +1,58 @@ 'Bar']), + new Response(202, ['Content-Length' => 0]), + new RequestException('Error Communicating with Server', new Request('GET', 'test')), + ]); - $mock = new MockHandler([ - new Response(200, ['X-Foo' => 'Bar']), - new Response(202, ['Content-Length' => 0]), - new RequestException('Error Communicating with Server', new Request('GET', 'test')), - ]); + $handler = HandlerStack::create($mock); - $handler = HandlerStack::create($mock); + $client = $factory->createClient(['handler' => $handler]); - $client = $factory->createClient(['handler' => $handler]); + // The first request is intercepted with the first response. + Assert::same(200, $client->request('GET', '/')->getStatusCode()); + Assert::same(202, $client->request('GET', '/')->getStatusCode()); - // The first request is intercepted with the first response. - Assert::same(200, $client->request('GET', '/')->getStatusCode()); - Assert::same(202, $client->request('GET', '/')->getStatusCode()); + Assert::same(2, count($snapshotStack->getSnapshots())); + Assert::notSame(0.0, $snapshotStack->getTotalTime()); +}); - Assert::same(2, count($snapshotStack->getSnapshots())); - Assert::notSame(0.0, $snapshotStack->getTotalTime()); - } +Toolkit::test(function (): void { + $snapshotStack = new SnapshotStack(); + $factory = new ClientFactory($snapshotStack); + $mock = new MockHandler([ + new Response(200, ['X-Foo' => 'Bar']), + new Response(202, ['Content-Length' => 0]), + new RequestException('Error Communicating with Server', new Request('GET', 'test')), + ]); - public function testHandlerProduction(): void - { - $snapshotStack = new SnapshotStack(); - $factory = new ClientFactory($snapshotStack); + $handler = HandlerStack::create($mock); - $mock = new MockHandler([ - new Response(200, ['X-Foo' => 'Bar']), - new Response(202, ['Content-Length' => 0]), - new RequestException('Error Communicating with Server', new Request('GET', 'test')), - ]); + $client = $factory->createClient(['handler' => $handler]); - $handler = HandlerStack::create($mock); + Assert::same(200, $client->request('GET', '/')->getStatusCode()); + Assert::same(202, $client->request('GET', '/')->getStatusCode()); - $client = $factory->createClient(['handler' => $handler]); - - Assert::same(200, $client->request('GET', '/')->getStatusCode()); - Assert::same(202, $client->request('GET', '/')->getStatusCode()); - - Assert::same(0, count($snapshotStack->getSnapshots())); - Assert::same(0.0, $snapshotStack->getTotalTime()); - } - -} - - -(new GuzzleHandlerTest())->run(); + Assert::same(0, count($snapshotStack->getSnapshots())); + Assert::same(0.0, $snapshotStack->getTotalTime()); +}); diff --git a/tests/Cases/SnapshotStackTest.phpt b/tests/Cases/SnapshotStackTest.phpt index caaf023..c7f6b6d 100644 --- a/tests/Cases/SnapshotStackTest.phpt +++ b/tests/Cases/SnapshotStackTest.phpt @@ -1,41 +1,29 @@ addSnapshot($snapshot); + $stack->addSnapshot($snapshot); + $stack->addSnapshot($snapshot); + $stack->addSnapshot($snapshot); - $stack = new SnapshotStack(); - $stack->addSnapshot($snapshot); - $stack->addSnapshot($snapshot); - $stack->addSnapshot($snapshot); - $stack->addSnapshot($snapshot); - - Assert::equal(40.0, $stack->getTotalTime()); - Assert::equal(4, count($stack->getSnapshots())); - } - -} - - -(new SnapshotStackTest())->run(); + Assert::equal(40.0, $stack->getTotalTime()); + Assert::equal(4, count($stack->getSnapshots())); +}); diff --git a/tests/Cases/TracyPanelTest.phpt b/tests/Cases/TracyPanelTest.phpt index 66c15a2..9bc1c11 100644 --- a/tests/Cases/TracyPanelTest.phpt +++ b/tests/Cases/TracyPanelTest.phpt @@ -1,61 +1,49 @@ 'Bar', 'Content-Type' => 'application/json'], '{"status": "ok"}'), + new Response(200, ['X-Foo' => 'Bar', 'Content-Type' => 'text/plain'], 'ok'), + ]); - $mock = new MockHandler([ - new Response(200, ['X-Foo' => 'Bar', 'Content-Type' => 'application/json'], '{"status": "ok"}'), - new Response(200, ['X-Foo' => 'Bar', 'Content-Type' => 'text/plain'], 'ok'), - ]); + $handler = HandlerStack::create($mock); - $handler = HandlerStack::create($mock); + $client = $factory->createClient(['handler' => $handler]); - $client = $factory->createClient(['handler' => $handler]); + $panel = new Panel($snapshotStack); + Assert::contains('fill="#aaa"', $panel->getTab()); + Assert::equal('', $panel->getPanel()); - $panel = new Panel($snapshotStack); - Assert::contains('fill="#aaa"', $panel->getTab()); - Assert::equal('', $panel->getPanel()); + $client->request('GET', '/'); + $client->request('GET', '/'); - $client->request('GET', '/'); - $client->request('GET', '/'); + Assert::same(2, count($snapshotStack->getSnapshots())); + Assert::contains('fill="#6bcbfd"', $panel->getTab()); - Assert::same(2, count($snapshotStack->getSnapshots())); - Assert::contains('fill="#6bcbfd"', $panel->getTab()); + $snapshot = $snapshotStack->getSnapshots()[1]; + Assert::type(Snapshot::class, $snapshot); + Assert::type(RequestInterface::class, $snapshot->getRequest()); + Assert::type(ResponseInterface::class, $snapshot->getResponse()); - $snapshot = $snapshotStack->getSnapshots()[1]; - Assert::type(Snapshot::class, $snapshot); - Assert::type(RequestInterface::class, $snapshot->getRequest()); - Assert::type(ResponseInterface::class, $snapshot->getResponse()); - - // Is panel rendering OK? - $panel->getPanel(); - } - -} - - -(new TracyPanelTest())->run(); + // Is panel rendering OK? + $panel->getPanel(); +});