Skip to content

Commit

Permalink
Start testing
Browse files Browse the repository at this point in the history
  • Loading branch information
arcanedev-maroc committed Oct 16, 2019
1 parent 04ff95e commit d8fccef
Show file tree
Hide file tree
Showing 17 changed files with 320 additions and 38 deletions.
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
"arcanedev/gravatar": "^3.0",
"arcanedev/laravel-impersonator": "^2.0",
"arcanedev/laravel-metrics": "^1.0",
"arcanedev/laravel-policies": "@dev",
"arcanedev/laravel-policies": "^1.0",
"arcanedev/log-viewer": "^5.0",
"arcanedev/notify": "^5.0",
"arcanedev/route-viewer": "^2.0",
Expand Down
4 changes: 2 additions & 2 deletions config/modules.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@
*/

'providers' => [
Arcanesoft\Media\MediaServiceProvider::class,
Arcanesoft\Blog\BlogServiceProvider::class,
// Arcanesoft\Media\MediaServiceProvider::class,
// Arcanesoft\Blog\BlogServiceProvider::class,
],

'commands' => [
Expand Down
8 changes: 4 additions & 4 deletions config/sidebar.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@
],

// Modules' sidebar items
'arcanesoft.blog.sidebar.items',
'arcanesoft.media.sidebar.items',
'arcanesoft.passport.sidebar.items',
// 'arcanesoft.blog.sidebar.items',
// 'arcanesoft.media.sidebar.items',
// 'arcanesoft.passport.sidebar.items',

// Authorization
[
Expand Down Expand Up @@ -133,7 +133,7 @@
],
],

'arcanesoft.backups.sidebar.items',
// 'arcanesoft.backups.sidebar.items',
],

];
36 changes: 36 additions & 0 deletions database/factories/UserFactory.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<?php

use Arcanesoft\Foundation\Auth\Auth;
use Faker\Generator as Faker;
use Illuminate\Support\Str;

$userModel = Auth::model('user', Arcanesoft\Foundation\Auth\Models\User::class);

/** @var Illuminate\Database\Eloquent\Factory $factory */

$factory->define($userModel, function (Faker $faker) {
return [
'first_name' => $faker->firstName,
'last_name' => $faker->lastName,
'email' => $faker->unique()->safeEmail,
'password' => '$2y$10$TKh8H1.PfQx37YgCzwiKb.KjNyWgaHb9cbcoQgdIVFlYg7B77UdFm', // secret
'remember_token' => Str::random(10),
];
});

/* -----------------------------------------------------------------
| States
| -----------------------------------------------------------------
*/

$factory->state($userModel, 'email-verified', [
'email_verified_at' => now(),
]);

$factory->state($userModel, 'activated', [
'activated_at' => now(),
]);

$factory->state($userModel, 'super-admin', [
'is_admin' => true,
]);
16 changes: 12 additions & 4 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -8,21 +8,29 @@
convertWarningsToExceptions="true"
processIsolation="false"
stopOnFailure="false"
syntaxCheck="false"
>
<testsuites>
<testsuite name="Package Test Suite">
<directory suffix=".php">./tests/</directory>
<testsuite name="Unit">
<directory suffix="Test.php">./tests/Unit</directory>
</testsuite>

<testsuite name="Feature">
<directory suffix="Test.php">./tests/Feature</directory>
</testsuite>
</testsuites>
<filter>
<whitelist>
<directory suffix=".php">./src/</directory>
</whitelist>
</filter>
<php>
<env name="APP_ENV" value="testing"/>
<env name="APP_KEY" value="AckfSECXIvnK5r28GVIWUAxmbBSjTsmF"/>
<env name="DB_CONNECTION" value="testing"/>
</php>
<logging>
<log type="coverage-clover" target="build/logs/clover.xml"/>
<log type="coverage-text" target="build/logs/coverage.txt"/>
<log type="coverage-html" target="build/logs/coverage" charset="UTF-8" yui="true" highlight="true"/>
<log type="coverage-html" target="build/logs/coverage"/>
</logging>
</phpunit>
11 changes: 6 additions & 5 deletions src/Auth/Repositories/PasswordResetsRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
namespace Arcanesoft\Foundation\Auth\Repositories;

use Arcanesoft\Foundation\Auth\Auth;
use Arcanesoft\Foundation\Auth\Models\PasswordReset;

/**
* Class PasswordResetsRepository
Expand All @@ -17,17 +18,17 @@
class PasswordResetsRepository extends AbstractRepository
{
/* -----------------------------------------------------------------
| Query Methods
| Main Methods
| -----------------------------------------------------------------
*/

/**
* Get the permission instance.
* Get the model FQN class.
*
* @return \Arcanesoft\Foundation\Auth\Models\Permission|mixed
* @return string
*/
public static function model()
public static function modelClass(): string
{
return Auth::makeModel('password-resets');
return Auth::model('password-resets', PasswordReset::class);
}
}
10 changes: 5 additions & 5 deletions src/Auth/Repositories/PermissionsGroupsRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,18 +18,18 @@
class PermissionsGroupsRepository extends AbstractRepository
{
/* -----------------------------------------------------------------
| Query Methods
| Main Methods
| -----------------------------------------------------------------
*/

/**
* Get the permission instance.
* Get the model FQN class.
*
* @return \Arcanesoft\Foundation\Auth\Models\PermissionsGroup|mixed
* @return string
*/
public static function model()
public static function modelClass(): string
{
return Auth::makeModel('permissions-group', PermissionsGroup::class);
return Auth::model('permissions-group', PermissionsGroup::class);
}

/* -----------------------------------------------------------------
Expand Down
10 changes: 5 additions & 5 deletions src/Auth/Repositories/PermissionsRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,18 +20,18 @@
class PermissionsRepository extends AbstractRepository
{
/* -----------------------------------------------------------------
| Query Methods
| Main Methods
| -----------------------------------------------------------------
*/

/**
* Get the permission instance.
* Get the model FQN class.
*
* @return \Arcanesoft\Foundation\Auth\Models\Permission|mixed
* @return string
*/
public static function model()
public static function modelClass(): string
{
return Auth::makeModel('permission');
return Auth::model('permission', Permission::class);
}

/* -----------------------------------------------------------------
Expand Down
10 changes: 5 additions & 5 deletions src/Auth/Repositories/RolesRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,18 +23,18 @@
class RolesRepository extends AbstractRepository
{
/* -----------------------------------------------------------------
| Query Methods
| Main Methods
| -----------------------------------------------------------------
*/

/**
* Get the model instance.
* Get the model FQN class.
*
* @return \Arcanesoft\Foundation\Auth\Models\Role|mixed
* @return string
*/
public static function model(): Role
public static function modelClass(): string
{
return Auth::makeModel('role');
return Auth::model('role', Role::class);
}

/* -----------------------------------------------------------------
Expand Down
8 changes: 4 additions & 4 deletions src/Auth/Repositories/UsersRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,13 @@ class UsersRepository extends AbstractRepository
*/

/**
* Get the model instance.
* Get the model FQN class.
*
* @return \Arcanesoft\Foundation\Auth\Models\User|mixed
* @return string
*/
public static function model(): User
public static function modelClass(): string
{
return Auth::makeModel('user');
return Auth::model('user', User::class);
}

/* -----------------------------------------------------------------
Expand Down
1 change: 1 addition & 0 deletions src/FoundationServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ public function boot(): void
$this->publishViews();
$this->publishTranslations();
$this->publishAssets();
$this->publishFactories();

Foundation::$runsMigrations ? $this->loadMigrations() : $this->publishMigrations();
}
Expand Down
17 changes: 14 additions & 3 deletions src/Support/Repositories/Repository.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
namespace Arcanesoft\Foundation\Support\Repositories;

use Arcanesoft\Foundation\Support\Contracts\Repository as RepositoryContract;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Support\Traits\ForwardsCalls;

/**
Expand All @@ -29,12 +30,22 @@ abstract class Repository implements RepositoryContract
| -----------------------------------------------------------------
*/

/**
* Get the model FQN class.
*
* @return string
*/
abstract public static function modelClass(): string;

/**
* Get the model instance.
*
* @return \Illuminate\Database\Eloquent\Model|mixed
*/
abstract public static function model();
public function model(): Model
{
return app()->make(static::modelClass());
}

/**
* Get the query builder.
Expand All @@ -43,7 +54,7 @@ abstract public static function model();
*/
public function query()
{
return static::model()->newQuery();
return $this->model()->newQuery();
}

/* -----------------------------------------------------------------
Expand All @@ -60,7 +71,7 @@ public function query()
*/
public function all($columns = ['*'])
{
return $this->query()->get($columns);
return $this->get($columns);
}

/* -----------------------------------------------------------------
Expand Down
17 changes: 17 additions & 0 deletions tests/Stubs/Models/User.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?php

namespace Arcanesoft\Foundation\Tests\Stubs\Models;

use Arcanesoft\Foundation\Auth\Models\User as Authenticatable;
use Illuminate\Contracts\Auth\MustVerifyEmail;

/**
* Class User
*
* @package Arcanesoft\Foundation\Tests\Stubs\Models
* @author ARCANEDEV <arcanedev.maroc@gmail.com>
*/
class User extends Authenticatable implements MustVerifyEmail
{
//
}
70 changes: 70 additions & 0 deletions tests/TestCase.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
<?php

namespace Arcanesoft\Foundation\Tests;

use Orchestra\Testbench\TestCase as OrchestraTestCase;

/**
* Class TestCase
*
* @package Arcanesoft\Foundation\Tests
* @author ARCANEDEV <arcanedev.maroc@gmail.com>
*/
abstract class TestCase extends OrchestraTestCase
{
/* -----------------------------------------------------------------
| Main Methods
| -----------------------------------------------------------------
*/

/**
* Get package providers.
*
* @param \Illuminate\Foundation\Application $app
*
* @return array
*/
protected function getPackageProviders($app)
{
return [
// Main Provider
\Arcanesoft\Foundation\FoundationServiceProvider::class,

// Dependencies
\Arcanedev\LaravelImpersonator\ImpersonatorServiceProvider::class,
\Arcanedev\LaravelPolicies\PoliciesServiceProvider::class,
\Arcanedev\LaravelMetrics\MetricServiceProvider::class,
\Arcanedev\Notify\NotifyServiceProvider::class,
];
}

/**
* Define environment setup.
*
* @param \Illuminate\Foundation\Application $app
*/
protected function getEnvironmentSetUp($app): void
{
// Configuration
$app['config']->set(
'arcanesoft.foundation.auth.database.models.user',
Stubs\Models\User::class
);
}

/**
* Load the migrations.
*/
protected function loadMigrations(): void
{
$this->loadMigrationsFrom(__DIR__ . '/../database/migrations');
}

/**
* Load the factories.
*/
protected function loadFactories(): void
{
$this->withFactories(__DIR__.'/../database/factories');
}
}
Empty file removed tests/Unit/.gitkeep
Empty file.

0 comments on commit d8fccef

Please sign in to comment.