From 21361b996b05bfe8bdee32c9bbcdd57e69a36e39 Mon Sep 17 00:00:00 2001 From: "Vladyslav G." Date: Sat, 22 Feb 2025 23:31:18 +0100 Subject: [PATCH 1/3] =?UTF-8?q?=F0=9F=94=A8Added=20dev=20dependency=20for?= =?UTF-8?q?=20testing=20with=20initial=20files?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- composer.json | 8 ++++++- phpunit.xml | 18 ++++++++++++++ tests/Feature/ExampleTest.php | 5 ++++ tests/Pest.php | 45 +++++++++++++++++++++++++++++++++++ tests/TestCase.php | 10 ++++++++ tests/Unit/ExampleTest.php | 5 ++++ 6 files changed, 90 insertions(+), 1 deletion(-) create mode 100644 phpunit.xml create mode 100644 tests/Feature/ExampleTest.php create mode 100644 tests/Pest.php create mode 100644 tests/TestCase.php create mode 100644 tests/Unit/ExampleTest.php diff --git a/composer.json b/composer.json index c948b4e..6066aba 100644 --- a/composer.json +++ b/composer.json @@ -39,7 +39,9 @@ "team-reflex/discord-php": "^10.3" }, "require-dev": { - "laravel/pint": "^1.15" + "laravel/pint": "^1.15", + "pestphp/pest": "^3.7", + "pestphp/pest-plugin-laravel": "^3.1" }, "autoload": { "psr-4": { @@ -49,9 +51,13 @@ "src/helpers.php" ] }, + "scripts": { + "test": "./vendor/bin/pest" + }, "config": { "sort-packages": true, "allow-plugins": { + "pestphp/pest-plugin": true, "php-http/discovery": true } } diff --git a/phpunit.xml b/phpunit.xml new file mode 100644 index 0000000..7d0904f --- /dev/null +++ b/phpunit.xml @@ -0,0 +1,18 @@ + + + + + ./tests + + + + + ./app + ./src + + + diff --git a/tests/Feature/ExampleTest.php b/tests/Feature/ExampleTest.php new file mode 100644 index 0000000..61cd84c --- /dev/null +++ b/tests/Feature/ExampleTest.php @@ -0,0 +1,5 @@ +toBeTrue(); +}); diff --git a/tests/Pest.php b/tests/Pest.php new file mode 100644 index 0000000..fd279ad --- /dev/null +++ b/tests/Pest.php @@ -0,0 +1,45 @@ +extend(Tests\TestCase::class)->in('Feature'); + +/* +|-------------------------------------------------------------------------- +| Expectations +|-------------------------------------------------------------------------- +| +| When you're writing tests, you often need to check that values meet certain conditions. The +| "expect()" function gives you access to a set of "expectations" methods that you can use +| to assert different things. Of course, you may extend the Expectation API at any time. +| +*/ + +expect()->extend('toBeOne', function () { + return $this->toBe(1); +}); + +/* +|-------------------------------------------------------------------------- +| Functions +|-------------------------------------------------------------------------- +| +| While Pest is very powerful out-of-the-box, you may have some testing code specific to your +| project that you don't want to repeat in every file. Here you can also expose helpers as +| global functions to help you to reduce the number of lines of code in your test files. +| +*/ + +function something() +{ + // .. +} diff --git a/tests/TestCase.php b/tests/TestCase.php new file mode 100644 index 0000000..cfb05b6 --- /dev/null +++ b/tests/TestCase.php @@ -0,0 +1,10 @@ +toBeTrue(); +}); From dd9da3cda4df5ce0dc5a6a0cbb10d01dd117d5a5 Mon Sep 17 00:00:00 2001 From: "Vladyslav G." Date: Sun, 23 Feb 2025 00:27:58 +0100 Subject: [PATCH 2/3] =?UTF-8?q?=E2=9C=85=20Add=20basic=20CommandTest=20and?= =?UTF-8?q?=20bootstrap=20Laravel=20functionality=20for=20testing?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- composer.json | 5 ++++- tests/Feature/CommandsTest.php | 27 +++++++++++++++++++++++++++ tests/Feature/ExampleTest.php | 5 ----- tests/Pest.php | 9 ++++++--- tests/TestCase.php | 14 ++++++++++---- tests/TestLaracordServiceProvider.php | 14 ++++++++++++++ 6 files changed, 61 insertions(+), 13 deletions(-) create mode 100644 tests/Feature/CommandsTest.php delete mode 100644 tests/Feature/ExampleTest.php create mode 100644 tests/TestLaracordServiceProvider.php diff --git a/composer.json b/composer.json index 6066aba..918385d 100644 --- a/composer.json +++ b/composer.json @@ -40,12 +40,15 @@ }, "require-dev": { "laravel/pint": "^1.15", + "orchestra/testbench": "^9.11", "pestphp/pest": "^3.7", + "pestphp/pest-plugin-arch": "^3.0", "pestphp/pest-plugin-laravel": "^3.1" }, "autoload": { "psr-4": { - "Laracord\\": "src/" + "Laracord\\": "src/", + "Tests\\": "tests/" }, "files": [ "src/helpers.php" diff --git a/tests/Feature/CommandsTest.php b/tests/Feature/CommandsTest.php new file mode 100644 index 0000000..d461782 --- /dev/null +++ b/tests/Feature/CommandsTest.php @@ -0,0 +1,27 @@ +registerCommand(ValidCommand::class); + + + + expect(ValidCommand::class)->toBeRegistered(); + + }); +}); \ No newline at end of file diff --git a/tests/Feature/ExampleTest.php b/tests/Feature/ExampleTest.php deleted file mode 100644 index 61cd84c..0000000 --- a/tests/Feature/ExampleTest.php +++ /dev/null @@ -1,5 +0,0 @@ -toBeTrue(); -}); diff --git a/tests/Pest.php b/tests/Pest.php index fd279ad..bad4ebb 100644 --- a/tests/Pest.php +++ b/tests/Pest.php @@ -11,7 +11,7 @@ | */ -// pest()->extend(Tests\TestCase::class)->in('Feature'); +pest()->extend(Tests\TestCase::class)->in('Feature'); /* |-------------------------------------------------------------------------- @@ -24,8 +24,11 @@ | */ -expect()->extend('toBeOne', function () { - return $this->toBe(1); +expect()->extend('toBeRegistered', function () { + $laracord = app(\Laracord\Laracord::class); + if (str_contains($this->value, 'Command')) { + return $this->toBeIn(array_keys($laracord->getCommands())); + } }); /* diff --git a/tests/TestCase.php b/tests/TestCase.php index cfb05b6..df109c0 100644 --- a/tests/TestCase.php +++ b/tests/TestCase.php @@ -2,9 +2,15 @@ namespace Tests; -use PHPUnit\Framework\TestCase as BaseTestCase; +use Orchestra\Testbench\TestCase as Orchestra; -abstract class TestCase extends BaseTestCase +abstract class TestCase extends Orchestra { - // -} + protected function getPackageProviders($app): array + { + return [ + TestLaracordServiceProvider::class, + ]; + } + +} \ No newline at end of file diff --git a/tests/TestLaracordServiceProvider.php b/tests/TestLaracordServiceProvider.php new file mode 100644 index 0000000..d26817e --- /dev/null +++ b/tests/TestLaracordServiceProvider.php @@ -0,0 +1,14 @@ + Date: Sun, 23 Feb 2025 00:40:37 +0100 Subject: [PATCH 3/3] =?UTF-8?q?=F0=9F=9A=A8=20fix=20code=20style=20with=20?= =?UTF-8?q?pint?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- tests/Feature/CommandsTest.php | 7 +------ tests/TestCase.php | 3 +-- tests/TestLaracordServiceProvider.php | 2 +- 3 files changed, 3 insertions(+), 9 deletions(-) diff --git a/tests/Feature/CommandsTest.php b/tests/Feature/CommandsTest.php index d461782..95bd907 100644 --- a/tests/Feature/CommandsTest.php +++ b/tests/Feature/CommandsTest.php @@ -8,10 +8,8 @@ public function getName(): string { return 'valid-command'; } - } - describe('in order to communicate with the bot, developer should be able to register commands into Laracord instance', function () { test('a command could be registered on laracord', function () { @@ -19,9 +17,6 @@ public function getName(): string $laracord->registerCommand(ValidCommand::class); - - expect(ValidCommand::class)->toBeRegistered(); - }); -}); \ No newline at end of file +}); diff --git a/tests/TestCase.php b/tests/TestCase.php index df109c0..313482f 100644 --- a/tests/TestCase.php +++ b/tests/TestCase.php @@ -12,5 +12,4 @@ protected function getPackageProviders($app): array TestLaracordServiceProvider::class, ]; } - -} \ No newline at end of file +} diff --git a/tests/TestLaracordServiceProvider.php b/tests/TestLaracordServiceProvider.php index d26817e..dfb24a0 100644 --- a/tests/TestLaracordServiceProvider.php +++ b/tests/TestLaracordServiceProvider.php @@ -11,4 +11,4 @@ public function bot(Laracord $bot): Laracord { return $bot; } -} \ No newline at end of file +}