Skip to content

Instantly share code, notes, and snippets.

@christophrumpel
Last active August 26, 2022 06:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save christophrumpel/c90e3bc5fcd901904ff5cdbafdd353b6 to your computer and use it in GitHub Desktop.
Save christophrumpel/c90e3bc5fcd901904ff5cdbafdd353b6 to your computer and use it in GitHub Desktop.
Created by Pest Playground
<?php
namespace App;
class Math
{
public static function add($a, $b)
{
return $a + $b;
}
public static function subtract($a, $b)
{
return $a - $b;
}
public static function multiply($a, $b)
{
return $a * $b;
}
public static function divide($a, $b)
{
return $a / $b;
}
}
<?php
use App\Math;
it('can add two numbers', function () {
expect(Math::add(1, 2))->toBe(3);
});
it('can subtract two numbers', function () {
expect(Math::subtract(3, 2))->toBe(1);
});
it('can multiply two numbers', function ($a, $b, $result) {
expect(Math::multiply($a, $b))->toBe($result);
})->with([
[1, 1, 1],
[1, 2, 2],
[2, 3, 6],
]);
it('can divide two numbers');
<?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 "uses()" function to bind a different classes or traits.
|
*/
// uses(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()
{
// ..
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment