Skip to content

Commit

Permalink
feature: add test coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
bornemisza committed Mar 27, 2024
1 parent 99f6fec commit 2d6a031
Show file tree
Hide file tree
Showing 4 changed files with 115 additions and 0 deletions.
45 changes: 45 additions & 0 deletions tests/Pest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
<?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()
{
// ..
}
10 changes: 10 additions & 0 deletions tests/TestCase.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?php

namespace Tests;

use PHPUnit\Framework\TestCase as BaseTestCase;

abstract class TestCase extends BaseTestCase
{
//
}
29 changes: 29 additions & 0 deletions tests/Unit/CollectionTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<?php

use Omisai\Continents\Collection;
use Omisai\Continents\Continent;

it('should return an array of continents', function () {
$collection = new Collection();
$continents = $collection->getContinents();

expect($continents)->toBeArray();
expect($continents)->toHaveCount(7);
expect($continents[0])->toBeInstanceOf(Continent::class);
});

it('should return a continent by code', function () {
$collection = new Collection();
$continent = $collection->getContinentByCode('AF');

expect($continent)->toBeInstanceOf(Continent::class);
expect($continent->code)->toBe('AF');
});

it('should return a continent by name', function () {
$collection = new Collection();
$continent = $collection->getContinentByName('Africa');

expect($continent)->toBeInstanceOf(Continent::class);
expect($continent->name)->toBe('Africa');
});
31 changes: 31 additions & 0 deletions tests/Unit/ContinentTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<?php

use Omisai\Continents\Continent;
use Omisai\Continents\Models\Europe;

it('can get the name in English', function () {
$continent = new Europe();

expect($continent->getName())->toBe('Europe');
});
it('can access the name in English without get', function () {
$continent = new Europe();

expect($continent->name)->toBe('Europe');
});

it('can validate a valid locale', function () {
Continent::validate('en');
})->throwsNoExceptions();

it('throws an exception for an invalid locale', function () {
Continent::validate('invalid');
})->throws(\InvalidArgumentException::class);;


it('can access other locale', function () {
$continent = new Europe();

expect($continent->getName('hu'))->toBe('Európa');
expect($continent->getName('es'))->toBe('Europa');
});

0 comments on commit 2d6a031

Please sign in to comment.