Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

🔨Test coverage #137

Draft
wants to merge 3 commits into
base: next
Choose a base branch
from
Draft
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
13 changes: 11 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,19 +39,28 @@
"team-reflex/discord-php": "^10.3"
},
"require-dev": {
"laravel/pint": "^1.15"
"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"
]
},
"scripts": {
"test": "./vendor/bin/pest"
},
"config": {
"sort-packages": true,
"allow-plugins": {
"pestphp/pest-plugin": true,
"php-http/discovery": true
}
}
Expand Down
18 changes: 18 additions & 0 deletions phpunit.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/10.3/phpunit.xsd"
bootstrap="vendor/autoload.php"
colors="true"
>
<testsuites>
<testsuite name="Test Suite">
<directory suffix="Test.php">./tests</directory>
</testsuite>
</testsuites>
<source>
<include>
<directory suffix=".php">./app</directory>
<directory suffix=".php">./src</directory>
</include>
</source>
</phpunit>
22 changes: 22 additions & 0 deletions tests/Feature/CommandsTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?php

use Laracord\Commands\Command;

class ValidCommand extends Command
{
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 () {
$laracord = app(\Laracord\Laracord::class);

$laracord->registerCommand(ValidCommand::class);

expect(ValidCommand::class)->toBeRegistered();
});
});
48 changes: 48 additions & 0 deletions tests/Pest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
<?php

/*
|--------------------------------------------------------------------------
| Test Case
|--------------------------------------------------------------------------
|
| The closure you provide to your test functions is always bound to a specific PHPUnit test
| case class. By default, that class is "PHPUnit\Framework\TestCase". Of course, you may
| need to change it using the "pest()" function to bind a different classes or traits.
|
*/

pest()->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('toBeRegistered', function () {
$laracord = app(\Laracord\Laracord::class);
if (str_contains($this->value, 'Command')) {
return $this->toBeIn(array_keys($laracord->getCommands()));
}
});

/*
|--------------------------------------------------------------------------
| 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()
{
// ..
}
15 changes: 15 additions & 0 deletions tests/TestCase.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?php

namespace Tests;

use Orchestra\Testbench\TestCase as Orchestra;

abstract class TestCase extends Orchestra
{
protected function getPackageProviders($app): array
{
return [
TestLaracordServiceProvider::class,
];
}
}
14 changes: 14 additions & 0 deletions tests/TestLaracordServiceProvider.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?php

namespace Tests;

use Laracord\Laracord;
use Laracord\LaracordServiceProvider;

class TestLaracordServiceProvider extends LaracordServiceProvider
{
public function bot(Laracord $bot): Laracord
{
return $bot;
}
}
5 changes: 5 additions & 0 deletions tests/Unit/ExampleTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<?php

test('example', function () {
expect(true)->toBeTrue();
});