Skip to content
Merged
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
29 changes: 29 additions & 0 deletions database/factories/ServiceFactory.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<?php

namespace Tepuilabs\SimpleCrm\Database\Factories;

use Illuminate\Database\Eloquent\Factories\Factory;

class ServiceFactory extends Factory
{
/**
* The name of the factory's corresponding model.
*
* @var string
*/
protected $model = \Tepuilabs\SimpleCrm\Tests\Models\Service::class;

/**
* Define the model's default state.
*
* @return array
*/
public function definition()
{
return [
'name' => $this->faker->sentence($nbWords = 6, $variableNbWords = true),
'description' => $this->faker->sentence($nbWords = 6, $variableNbWords = true),
'status' => $this->faker->randomElement(['published', 'draft']),
];
}
}
35 changes: 35 additions & 0 deletions database/migrations/create_services_table.php.stub
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

class CreateServicesTable extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::create('services', function (Blueprint $table) {
$table->id();
$table->string('name')->nullable();
$table->text('description')->nullable();
$table->enum('status', ['published', 'draft'])->default('draft');
$table->timestamps();
$table->softDeletes();
});
}

/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::dropIfExists('services');
}
}
22 changes: 22 additions & 0 deletions models/Service.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?php

namespace App\Models\Tepuilabs\SimpleCrm;

use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;

class Service extends Model
{
use HasFactory;

/**
* The attributes that are mass assignable.
*
* @var array
*/
protected $fillable = [
'name',
'description',
'status',
];
}
2 changes: 1 addition & 1 deletion src/SimpleCrmServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,14 @@ class SimpleCrmServiceProvider extends ServiceProvider
public function boot(): void
{
if ($this->app->runningInConsole()) {

$this->publishes([
__DIR__ . '/../models' => app_path('Models/Tepuilabs/SimpleCrm'),
], 'simple-crm-models');

$migrationFileNames = [
'create_leads_table.php',
'create_notes_table.php',
'create_services_table.php',
];

foreach ($migrationFileNames as $key) {
Expand Down
22 changes: 22 additions & 0 deletions tests/Models/Service.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?php

namespace Tepuilabs\SimpleCrm\Tests\Models;

use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;

class Service extends Model
{
use HasFactory;

/**
* The attributes that are mass assignable.
*
* @var array
*/
protected $fillable = [
'name',
'description',
'status',
];
}
2 changes: 2 additions & 0 deletions tests/TestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,12 @@ public function getEnvironmentSetUp($app)

include_once __DIR__.'/../database/migrations/create_leads_table.php.stub';
include_once __DIR__.'/../database/migrations/create_notes_table.php.stub';
include_once __DIR__.'/../database/migrations/create_services_table.php.stub';
include_once __DIR__.'/database/migrations/create_users_table.php.stub';

(new \CreateUsersTable())->up();
(new \CreateLeadsTable())->up();
(new \CreateNotesTable())->up();
(new \CreateServicesTable())->up();
}
}
16 changes: 16 additions & 0 deletions tests/Unit/ServiceTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?php

namespace Tepuilabs\SimpleCrm\Tests\Unit;

use Tepuilabs\SimpleCrm\Tests\TestCase;

class ServiceTest extends TestCase
{
/** @test */
public function test_it_can_create_services()
{
$service = \Tepuilabs\SimpleCrm\Tests\Models\Service::factory()->create();

$this->assertInstanceOf(\Tepuilabs\SimpleCrm\Tests\Models\Service::class, $service);
}
}