Skip to content

Commit

Permalink
Merge pull request #31 from dvicklund/dev
Browse files Browse the repository at this point in the history
Dev
  • Loading branch information
dvicklund authored Apr 9, 2022
2 parents cabe293 + 5446063 commit 5d6696c
Show file tree
Hide file tree
Showing 17 changed files with 291 additions and 444 deletions.
14 changes: 12 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,16 @@
"license": "MIT",
"require": {
"php": ">=7.3.0",
"laravel/framework": "^9.0",
"laravel/framework": "^9.6",
"gazsp/baum": "^2.0"
},
"require-dev": {
"phpunit/phpunit": "^9.5.10",
"mockery/mockery": "^1.0",
"fakerphp/faker": "^1.19"
"fakerphp/faker": "^1.19",
"orchestra/testbench": "^7.3",
"brianium/paratest": "^6.4",
"nunomaduro/collision": "^6.1"
},
"archive": {
"exclude": ["/tests"]
Expand All @@ -42,5 +45,12 @@
"allow-plugins": {
"kylekatarnls/update-helper": true
}
},
"extra": {
"laravel": {
"providers": [
"Stevebauman\\Inventory\\InventoryServiceProvider"
]
}
}
}
3 changes: 3 additions & 0 deletions phpunit.xml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@
<directory suffix=".php">src</directory>
</include>
</coverage>
<php>
<env name="DB_CONNECTION" value="testing"/>
</php>
</phpunit>
<!-- beStrictAboutCoversAnnotation="true" -->
<!-- forceCoversAnnotation="true" -->
Expand Down
12 changes: 9 additions & 3 deletions src/InventoryServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace Stevebauman\Inventory;

use Illuminate\Support\ServiceProvider;
use Illuminate\Support\Facades\Config;

/**
* Class InventoryServiceProvider.
Expand Down Expand Up @@ -66,9 +67,14 @@ public function boot()
/*
* Assign the migrations as publishable, and tag it as 'migrations'
*/
$this->publishes([
__DIR__.'/migrations/' => base_path('database/migrations'),
], 'migrations');
// $this->publishes([
// __DIR__.'/migrations/' => base_path('database/migrations'),
// ], 'migrations');

/**
* Load migrations
*/
$this->loadMigrationsFrom(__DIR__.'/migrations');
}

/**
Expand Down
3 changes: 3 additions & 0 deletions src/Models/CustomAttribute.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ class CustomAttribute extends BaseModel
'display_name',
'value_type',
'reserved',
'required',
'rule',
'rule_desc',
'display_type',
'has_default',
'default_value',
Expand Down
1 change: 1 addition & 0 deletions src/Models/Inventory.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ class Inventory extends BaseModel
'metric_id',
'name',
'description',
'is_parent',
];

/**
Expand Down
6 changes: 6 additions & 0 deletions src/Models/Metric.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,12 @@
*/
class Metric extends BaseModel
{
protected $fillable = [
"name",
"symbol",
"created_by",
];

protected $table = 'metrics';

/**
Expand Down
2 changes: 2 additions & 0 deletions src/Traits/InventoryStockTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,8 @@ public function postCreate()
/*
* Generate the movement
*/
$this->quantity = is_null($this->quantity) ? 0 : $this->quantity;

$this->generateStockMovement(0, $this->quantity, $this->reason, $this->cost);
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/config/config.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
*
* @var bool
*/
'skus_enabled' => true,
'skus_enabled' => false,

/*
* The sku prefix length, not including the code for example:
Expand Down
89 changes: 76 additions & 13 deletions tests/FunctionalTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,50 +3,111 @@
namespace Stevebauman\Inventory\Tests;

use Illuminate\Database\Capsule\Manager as DB;
use PHPUnit\Framework\TestCase;
// use Illuminate\Support\Facades\Lang;
// use Illuminate\Support\Facades\Event;
// use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Config;
use Orchestra\Testbench\TestCase;
use Stevebauman\Inventory\Models\Inventory;
use Stevebauman\Inventory\Models\InventoryStock;
use Stevebauman\Inventory\Models\Location;
use Stevebauman\Inventory\Models\Metric;
use Stevebauman\Inventory\Models\Category;
use Stevebauman\Inventory\Models\Supplier;
use Stevebauman\Inventory\InventoryServiceProvider;
use Illuminate\Database\Eloquent\Model as Eloquent;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Illuminate\Foundation\Testing\DatabaseTransactions;
use Faker\Factory;

abstract class FunctionalTestCase extends TestCase
class FunctionalTestCase extends TestCase
{
use DatabaseTransactions;
// use RefreshDatabase;
// use DatabaseTransactions;

protected static $db = null;
protected static $connection = null;

protected static $migrated = false;

public static $faker = null;

protected function setUp(): void
{
parent::setUp();

Config::set('inventory'.InventoryServiceProvider::$packageConfigSeparator.'allow_no_user', true);
Config::set('inventory'.InventoryServiceProvider::$packageConfigSeparator.'skus_enabled', true);
Config::set('inventory'.InventoryServiceProvider::$packageConfigSeparator.'sku_separator', '-');
Config::set('inventory'.InventoryServiceProvider::$packageConfigSeparator.'sku_prefix_length', '3');
Config::set('inventory'.InventoryServiceProvider::$packageConfigSeparator.'sku_code_length', '6');
// $this->configureDatabase();
// $this->migrateTables();
}

public static function setUpBeforeClass(): void
{
FunctionalTestCase::$faker = Factory::create();
if (!FunctionalTestCase::$db) {
FunctionalTestCase::configureDatabase();
FunctionalTestCase::migrateTables();
Eloquent::unguard();
}

// if (!FunctionalTestCase::$db) {
// FunctionalTestCase::configureDatabase();
// FunctionalTestCase::migrateTables();
// // Eloquent::unguard();
// }
}

public static function tearDownAfterClass(): void
{
FunctionalTestCase::dropTables();
// FunctionalTestCase::dropTables();
// FunctionalTestCase::$db->getConnection('default')->disconnect();
}

/**
* Get package providers.
*
* @param \Illuminate\Foundation\Application $app
*
* @return array
*/
protected function getPackageProviders($app)
{
return [
'Stevebauman\Inventory\InventoryServiceProvider',
];
}

protected function getEnvironmentSetUp($app)
{
// Setup default database to use sqlite :memory:
$app['config']->set('database.default', 'testbench');
$app['config']->set('database.connections.testbench', [
'driver' => 'sqlite',
'database' => ':memory:',
'prefix' => '',
]);
}

/**
* Define database migrations.
*
* @return void
*/
protected function defineDatabaseMigrations()
{
// if(!FunctionalTestCase::$migrated) {

// echo "Running database migrations...\n";
// $this->loadLaravelMigrations();
$this->loadMigrationsFrom(__DIR__ . '/test_migrations');
$this->artisan('migrate', ['--database' => 'testbench'])->run();

// FunctionalTestCase::$migrated = true;
// }

// $this->beforeApplicationDestroyed(function() {
// $this->artisan('migrate:rollback')->run();
// });
}

private static function configureDatabase()
{
$db = FunctionalTestCase::$db;
Expand Down Expand Up @@ -409,7 +470,7 @@ protected function newInventory(array $attributes = [])

$category = $this->newCategory();

if(count($attributes) > 0) {
if (count($attributes) > 0) {
return Inventory::create($attributes);
}

Expand Down Expand Up @@ -500,8 +561,10 @@ protected function newInventoryStock()
protected function newInventorySku()
{
$item = $this->newInventory();

return $item->generateSku();

// Item already has a sku, dammit.
// return $item->generateSku();
return $item->with("sku")->first()->sku;
}

/**
Expand Down
Loading

0 comments on commit 5d6696c

Please sign in to comment.