Skip to content

Commit

Permalink
added tests
Browse files Browse the repository at this point in the history
  • Loading branch information
theHocineSaad committed Sep 4, 2022
1 parent df0f9c6 commit a896a10
Show file tree
Hide file tree
Showing 7 changed files with 157 additions and 3 deletions.
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ build
composer.lock
coverage
docs
phpunit.xml
phpstan.neon
testbench.yaml
vendor
Expand Down
6 changes: 4 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,14 @@
},
"require-dev": {
"laravel/pint": "^1.1",
"orchestra/testbench": "^6.0",
"orchestra/testbench": "^7.0",
"phpunit/phpunit": "^9.0"
},
"autoload": {
"psr-4": {
"TheHocineSaad\\LaravelAlgereography\\": "src"
"TheHocineSaad\\LaravelAlgereography\\": "src",
"Database\\Migrations\\": "database/migrations/",
"Database\\Seeders\\": "database/seeders/"
}
},
"autoload-dev": {
Expand Down
21 changes: 21 additions & 0 deletions database/seeders/DatabaseSeeder.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?php

namespace Database\Seeders;

use Illuminate\Database\Seeder;

class DatabaseSeeder extends Seeder
{
/**
* Seed the application's database.
*
* @return void
*/
public function run()
{
$this->call([
WilayaSeeder::class,
DairaSeeder::class,
]);
}
}
33 changes: 33 additions & 0 deletions phpunit.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
bootstrap="vendor/autoload.php"
backupGlobals="false"
backupStaticAttributes="false"
colors="true"
verbose="true"
convertErrorsToExceptions="true"
convertNoticesToExceptions="true"
convertWarningsToExceptions="true"
processIsolation="false"
stopOnFailure="false"
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.3/phpunit.xsd"
>
<coverage>
<include>
<directory suffix=".php">src/</directory>
</include>
</coverage>
<testsuites>
<testsuite name="Unit">
<directory suffix="Test.php">./tests/Unit</directory>
</testsuite>
<testsuite name="Feature">
<directory suffix="Test.php">./tests/Feature</directory>
</testsuite>
</testsuites>
<php>
<env name="DB_CONNECTION" value="testing"/>
<env name="APP_KEY" value="base64:USGB1pG+heJfX9iwg5MNrpNWFOYVv+TM3LaTDGt6iDw="/>
</php>
</phpunit>
36 changes: 36 additions & 0 deletions tests/TestCase.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<?php

namespace TheHocineSaad\LaravelAlgereography\Tests;

use Illuminate\Support\Facades\Artisan;
use Illuminate\Support\Facades\Schema;
use TheHocineSaad\LaravelAlgereography\LaravelAlgereographyServiceProvider;

class TestCase extends \Orchestra\Testbench\TestCase
{
public function setUp(): void
{
parent::setUp();
}

protected function getPackageProviders($app)
{
return [
LaravelAlgereographyServiceProvider::class,
];
}

protected function getEnvironmentSetUp($app)
{
Schema::hasTable('wilayas') ?? Schema::drop('wilayas');
Schema::hasTable('dairas') ?? Schema::drop('dairas');

$migration = include __DIR__.'/../database/migrations/1999_03_11_000000_create_wilayas_table.php';
$migration->up();

$migration = include __DIR__.'/../database/migrations/1999_03_11_000001_create_dairas_table.php';
$migration->up();

Artisan::call('db:seed');
}
}
32 changes: 32 additions & 0 deletions tests/Unit/DairaTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<?php

namespace TheHocineSaad\LaravelAlgereography\Tests\Unit;

use Illuminate\Support\Facades\Schema;
use TheHocineSaad\LaravelAlgereography\Models\Daira;
use TheHocineSaad\LaravelAlgereography\Models\Wilaya;
use TheHocineSaad\LaravelAlgereography\Tests\TestCase;

class DairaTest extends TestCase
{
public function test_if_dairas_table_is_created()
{
$this->assertTrue(Schema::hasTable('dairas'));
}

public function test_if_dairas_table_has_all_columns()
{
$this->assertTrue(Schema::hasColumns('dairas', ['id', 'name', 'ar_name', 'wilaya_id']));
}

public function test_if_all_dairas_exists()
{
$this->assertDatabaseCount('dairas', 548);
}

public function test_if_relationship_with_wilayas_is_working()
{
$daira = Daira::find(1);
$this->assertInstanceOf(Wilaya::class, $daira->wilaya);
}
}
31 changes: 31 additions & 0 deletions tests/Unit/WilayaTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<?php

namespace TheHocineSaad\LaravelAlgereography\Tests\Unit;

use Illuminate\Support\Facades\Schema;
use TheHocineSaad\LaravelAlgereography\Models\Wilaya;
use TheHocineSaad\LaravelAlgereography\Tests\TestCase;

class WilayaTest extends TestCase
{
public function test_if_wilayas_table_is_created()
{
$this->assertTrue(Schema::hasTable('wilayas'));
}

public function test_if_wilayas_table_has_all_columns()
{
$this->assertTrue(Schema::hasColumns('wilayas', ['id', 'name', 'ar_name']));
}

public function test_if_all_wilayas_exists()
{
$this->assertDatabaseCount('wilayas', 58);
}

public function test_if_relationship_with_dairas_is_working()
{
$wilaya = Wilaya::find(1);
$this->assertInstanceOf('Illuminate\Database\Eloquent\Collection', $wilaya->dairas);
}
}

0 comments on commit a896a10

Please sign in to comment.