diff --git a/.env.testing b/.env.testing deleted file mode 100644 index a60fc4e09d..0000000000 --- a/.env.testing +++ /dev/null @@ -1,75 +0,0 @@ -# -------------------------------------------- -# REQUIRED: BASIC APP SETTINGS -# -------------------------------------------- -APP_ENV=testing -APP_DEBUG=true -APP_KEY=base64:glJpcM7BYwWiBggp3SQ/+NlRkqsBQMaGEOjemXqJzOU= -APP_URL=http://localhost:8000 -APP_TIMEZONE='US/Pacific' -APP_LOCALE=en -FILESYSTEM_DISK=local - -# -------------------------------------------- -# REQUIRED: DATABASE SETTINGS -# -------------------------------------------- -DB_CONNECTION=sqlite_testing -DB_HOST=localhost -DB_PORT=3306 -DB_DATABASE=testing.sqlite -DB_USERNAME=null -DB_PASSWORD=null - -# -------------------------------------------- -# REQUIRED: OUTGOING MAIL SERVER SETTINGS -# -------------------------------------------- -MAIL_DRIVER=log -MAIL_HOST=email-smtp.us-west-2.amazonaws.com -MAIL_PORT=587 -MAIL_USERNAME=YOURUSERNAME -MAIL_PASSWORD=YOURPASSWORD -MAIL_ENCRYPTION=null -MAIL_FROM_ADDR=you@example.com -MAIL_FROM_NAME=Snipe-IT - -# -------------------------------------------- -# REQUIRED: IMAGE LIBRARY -# This should be gd or imagick -# -------------------------------------------- -IMAGE_LIB=gd - - -# -------------------------------------------- -# OPTIONAL: AWS SETTINGS -# -------------------------------------------- -AWS_SECRET_ACCESS_KEY=null -AWS_ACCESS_KEY_ID=null -AWS_DEFAULT_REGION=null -AWS_BUCKET=null -AWS_BUCKET_ROOT=null -AWS_URL=null - - -# -------------------------------------------- -# OPTIONAL: CACHE SETTINGS -# -------------------------------------------- -CACHE_DRIVER=file -SESSION_DRIVER=file -QUEUE_DRIVER=sync - - -# -------------------------------------------- -# OPTIONAL: SESSION SETTINGS -# -------------------------------------------- -SESSION_LIFETIME=12000 -EXPIRE_ON_CLOSE=false -ENCRYPT=false -COOKIE_NAME=snipeittest_session -COOKIE_DOMAIN=null -SECURE_COOKIES=false - - -# -------------------------------------------- -# OPTIONAL: APP LOG FORMAT -# -------------------------------------------- -LOG_CHANNEL=single -LOG_LEVEL=debug diff --git a/.env.testing.example b/.env.testing.example new file mode 100644 index 0000000000..3391d62726 --- /dev/null +++ b/.env.testing.example @@ -0,0 +1,19 @@ +# -------------------------------------------- +# REQUIRED: BASIC APP SETTINGS +# -------------------------------------------- +APP_ENV=testing +APP_DEBUG=true +APP_KEY=base64:glJpcM7BYwWiBggp3SQ/+NlRkqsBQMaGEOjemXqJzOU= +APP_URL=http://localhost:8000 +APP_TIMEZONE='UTC' +APP_LOCALE=en + +# -------------------------------------------- +# REQUIRED: DATABASE SETTINGS +# -------------------------------------------- +DB_CONNECTION=mysql +DB_HOST=127.0.0.1 +DB_PORT=3306 +DB_DATABASE=null +DB_USERNAME=null +DB_PASSWORD=null diff --git a/.gitignore b/.gitignore index e49e69c9ae..f0e9bfcec2 100755 --- a/.gitignore +++ b/.gitignore @@ -3,6 +3,7 @@ .env .env.dusk.* !.env.dusk.example +.env.testing phpstan.neon .idea /bin/ diff --git a/TESTING.md b/TESTING.md index 8a430d498e..3f0e588105 100644 --- a/TESTING.md +++ b/TESTING.md @@ -1,45 +1,23 @@ -# Using the Test Suite +# Running the Test Suite -This document is targeted at developers looking to make modifications to -this application's code base and want to run the existing test suite. +This document is targeted at developers looking to make modifications to this application's code base and want to run the existing test suite. +Before starting, follow the [instructions](README.md#installation) for installing the application locally and ensure you can load it in a browser properly. -## Setup +## Unit and Feature Tests -Follow the instructions for installing the application locally, -making sure to have also run the [database migrations](link to db migrations). +Before attempting to run the test suite copy the example environment file for tests and update the values to match your environment: +`cp .env.testing.example .env.testing` +> Since the data in the database is flushed after each test it is recommended you create a separate mysql database for specifically for tests -## Unit Tests +Now you are ready to run the entire test suite from your terminal: -The application will use values in the `.env.testing` file located -in the root directory to override the -default settings and/or other values that exist in your `.env` files. +`php artisan test` -Make sure to modify the section in `.env.testing` that has the -database settings. In the example below, it is connecting to the -[MariaDB](link-to-maria-db) server that is used if you install the -application using [Docker](https://docker.com). +To run individual test files, you can pass the path to the test that you want to run: -```dotenv -# -------------------------------------------- -# REQUIRED: DATABASE SETTINGS -# -------------------------------------------- -DB_CONNECTION=mysql -DB_HOST=127.0.0.1 -DB_DATABASE=snipeit -DB_USERNAME=root -DB_PASSWORD=changeme1234 -``` - -To run the entire unit test suite, use the following command from your terminal: - -`php artisan test --env=testing` - -To run individual test files, you can pass the path to the test that -you want to run. - -`php artisan test --env=testing tests/Unit/AccessoryTest.php` +`php artisan test tests/Unit/AccessoryTest.php` ## Browser Tests @@ -52,11 +30,9 @@ Before attempting to run Dusk tests copy the example environment file for Dusk a **Important**: Dusk tests cannot be run using an in-memory SQLite database. Additionally, the Dusk test suite uses the `DatabaseMigrations` trait which will leave the database in a fresh state after running. Therefore, it is recommended that you create a test database and point `DB_DATABASE` in `.env.dusk.local` to it. -### Test Setup +### Running Browser Tests -Your application needs to be configured and up and running in order for the browser -tests to actually run. When running the tests locally, you can start the application -using the following command: +Your application needs to be configured and up and running in order for the browser tests to actually run. When running the tests locally, you can start the application using the following command: `php artisan serve` diff --git a/app/Http/Controllers/Api/CategoriesController.php b/app/Http/Controllers/Api/CategoriesController.php index c518813405..91b0d7f7dc 100644 --- a/app/Http/Controllers/Api/CategoriesController.php +++ b/app/Http/Controllers/Api/CategoriesController.php @@ -24,10 +24,50 @@ class CategoriesController extends Controller public function index(Request $request) { $this->authorize('view', Category::class); - $allowed_columns = ['id', 'name', 'category_type', 'category_type', 'use_default_eula', 'eula_text', 'require_acceptance', 'checkin_email', 'assets_count', 'accessories_count', 'consumables_count', 'components_count', 'licenses_count', 'image']; + $allowed_columns = [ + 'id', + 'name', + 'category_type', + 'category_type', + 'use_default_eula', + 'eula_text', + 'require_acceptance', + 'checkin_email', + 'assets_count', + 'accessories_count', + 'consumables_count', + 'components_count', + 'licenses_count', + 'image', + ]; + + $categories = Category::select([ + 'id', + 'created_at', + 'updated_at', + 'name', 'category_type', + 'use_default_eula', + 'eula_text', + 'require_acceptance', + 'checkin_email', + 'image' + ])->withCount('accessories as accessories_count', 'consumables as consumables_count', 'components as components_count', 'licenses as licenses_count'); + + + /* + * This checks to see if we should override the Admin Setting to show archived assets in list. + * We don't currently use it within the Snipe-IT GUI, but will be useful for API integrations where they + * may actually need to fetch assets that are archived. + * + * @see \App\Models\Category::showableAssets() + */ + if ($request->input('archived')=='true') { + $categories = $categories->withCount('assets as assets_count'); + } else { + $categories = $categories->withCount('showableAssets as assets_count'); + } + - $categories = Category::select(['id', 'created_at', 'updated_at', 'name', 'category_type', 'use_default_eula', 'eula_text', 'require_acceptance', 'checkin_email', 'image']) - ->withCount('assets as assets_count', 'accessories as accessories_count', 'consumables as consumables_count', 'components as components_count', 'licenses as licenses_count'); if ($request->filled('search')) { $categories = $categories->TextSearch($request->input('search')); diff --git a/app/Models/Category.php b/app/Models/Category.php index b00e5a7bf9..c06ac38543 100755 --- a/app/Models/Category.php +++ b/app/Models/Category.php @@ -194,7 +194,25 @@ class Category extends SnipeModel */ public function assets() { - return $this->hasManyThrough(\App\Models\Asset::class, \App\Models\AssetModel::class, 'category_id', 'model_id'); + return $this->hasManyThrough(Asset::class, \App\Models\AssetModel::class, 'category_id', 'model_id'); + } + + /** + * Establishes the category -> assets relationship but also takes into consideration + * the setting to show archived in lists. + * + * We could have complicated the assets() method above, but keeping this separate + * should give us more flexibility if we need to return actually archived assets + * by their category. + * + * @author [A. Gianotto] [] + * @since [v6.1.0] + * @see \App\Models\Asset::scopeAssetsForShow() + * @return \Illuminate\Database\Eloquent\Relations\Relation + */ + public function showableAssets() + { + return $this->hasManyThrough(Asset::class, \App\Models\AssetModel::class, 'category_id', 'model_id')->AssetsForShow(); } /** diff --git a/database/factories/AssetFactory.php b/database/factories/AssetFactory.php index 6f3cce8722..6b77b8b078 100644 --- a/database/factories/AssetFactory.php +++ b/database/factories/AssetFactory.php @@ -38,8 +38,8 @@ class AssetFactory extends Factory { return [ 'name' => null, - 'rtd_location_id' => Location::all()->random()->id, - 'serial' => $this->faker->uuid, + 'rtd_location_id' => Location::factory(), + 'serial' => $this->faker->uuid(), 'status_id' => 1, 'user_id' => 1, 'asset_tag' => $this->faker->unixTime('now'), @@ -47,7 +47,7 @@ class AssetFactory extends Factory 'purchase_date' => $this->faker->dateTimeBetween('-1 years', 'now', date_default_timezone_get())->format('Y-m-d'), 'purchase_cost' => $this->faker->randomFloat(2, '299.99', '2999.99'), 'order_number' => $this->faker->numberBetween(1000000, 50000000), - 'supplier_id' => Supplier::all()->random()->id, + 'supplier_id' => Supplier::factory(), 'requestable' => $this->faker->boolean(), 'assigned_to' => null, 'assigned_type' => null, diff --git a/database/factories/SupplierFactory.php b/database/factories/SupplierFactory.php index 344dfe7d5b..47ec2ceee8 100644 --- a/database/factories/SupplierFactory.php +++ b/database/factories/SupplierFactory.php @@ -39,18 +39,18 @@ class SupplierFactory extends Factory public function definition() { return [ - 'name' => $this->faker->company, - 'address' => $this->faker->streetAddress, - 'address2' => $this->faker->secondaryAddress, - 'city' => $this->faker->city, - 'state' => $this->faker->stateAbbr, - 'zip' => $this->faker->postCode, - 'country' => $this->faker->countryCode, - 'contact' => $this->faker->name, - 'phone' => $this->faker->phoneNumber, - 'fax' => $this->faker->phoneNumber, - 'email' => $this->faker->safeEmail, - 'url' => $this->faker->url, + 'name' => $this->faker->company(), + 'address' => $this->faker->streetAddress(), + 'address2' => $this->faker->secondaryAddress(), + 'city' => $this->faker->city(), + 'state' => $this->faker->stateAbbr(), + 'zip' => $this->faker->postCode(), + 'country' => $this->faker->countryCode(), + 'contact' => $this->faker->name(), + 'phone' => $this->faker->phoneNumber(), + 'fax' => $this->faker->phoneNumber(), + 'email' => $this->faker->safeEmail(), + 'url' => $this->faker->url(), 'notes' => $this->faker->text(191), // Supplier notes can be a max of 255 characters. ]; } diff --git a/phpunit.xml b/phpunit.xml index bf3fd2dc33..4ee53b57b3 100644 --- a/phpunit.xml +++ b/phpunit.xml @@ -1,22 +1,36 @@ - + app/ - - ./tests/ + + ./tests/Unit + + + ./tests/Feature - + + - + - - + diff --git a/resources/views/categories/view.blade.php b/resources/views/categories/view.blade.php index 6e33594b17..9b361c46c7 100644 --- a/resources/views/categories/view.blade.php +++ b/resources/views/categories/view.blade.php @@ -39,7 +39,7 @@
  • {{ ucwords($category_type_route) }} @if ($category->category_type=='asset') - {{ $category->assets()->AssetsForShow()->count() }} + {{ $category->showableAssets()->count() }} @endif
  • diff --git a/resources/views/dashboard.blade.php b/resources/views/dashboard.blade.php index 1dd732b97a..296a940b3f 100755 --- a/resources/views/dashboard.blade.php +++ b/resources/views/dashboard.blade.php @@ -274,7 +274,7 @@
    - +

    {{ trans('general.asset') }} {{ trans('general.locations') }}

    diff --git a/resources/views/licenses/view.blade.php b/resources/views/licenses/view.blade.php index b8f6d7f684..21260ae4bb 100755 --- a/resources/views/licenses/view.blade.php +++ b/resources/views/licenses/view.blade.php @@ -358,7 +358,7 @@
    - {{ $license->reassignable ? 'Yes' : 'No' }} + {!! $license->reassignable ? ' '.trans('general.yes') : ' '.trans('general.no') !!}
    diff --git a/tests/Feature/Api/Users/UsersForSelectListTest.php b/tests/Feature/Api/Users/UsersForSelectListTest.php index 558f362646..b4ede4b117 100644 --- a/tests/Feature/Api/Users/UsersForSelectListTest.php +++ b/tests/Feature/Api/Users/UsersForSelectListTest.php @@ -5,15 +5,12 @@ namespace Tests\Feature\Api\Users; use App\Models\Company; use App\Models\Setting; use App\Models\User; -use Illuminate\Foundation\Testing\RefreshDatabase; use Illuminate\Testing\Fluent\AssertableJson; use Laravel\Passport\Passport; use Tests\TestCase; class UsersForSelectListTest extends TestCase { - use RefreshDatabase; - public function testUsersAreReturned() { Setting::factory()->create(); diff --git a/tests/TestCase.php b/tests/TestCase.php index 5082341307..efa533b8cc 100644 --- a/tests/TestCase.php +++ b/tests/TestCase.php @@ -2,17 +2,26 @@ namespace Tests; +use App\Http\Middleware\SecurityHeaders; use App\Models\Setting; +use Illuminate\Foundation\Testing\LazilyRefreshDatabase; use Illuminate\Foundation\Testing\TestCase as BaseTestCase; abstract class TestCase extends BaseTestCase { use CreatesApplication; + use LazilyRefreshDatabase; + + private array $globallyDisabledMiddleware = [ + SecurityHeaders::class, + ]; protected function setUp(): void { parent::setUp(); $this->beforeApplicationDestroyed(fn() => Setting::$_cache = null); + + $this->withoutMiddleware($this->globallyDisabledMiddleware); } } diff --git a/tests/Unit/AccessoryTest.php b/tests/Unit/AccessoryTest.php index dafcce663f..ec931fad6e 100644 --- a/tests/Unit/AccessoryTest.php +++ b/tests/Unit/AccessoryTest.php @@ -6,20 +6,10 @@ use App\Models\Manufacturer; use App\Models\Location; use App\Models\Category; use App\Models\Company; -use Illuminate\Foundation\Testing\DatabaseMigrations; -use Illuminate\Foundation\Testing\DatabaseTransactions; -use Illuminate\Foundation\Testing\WithoutMiddleware; -use Tests\Unit\BaseTest; +use Tests\TestCase; -class AccessoryTest extends BaseTest +class AccessoryTest extends TestCase { - /** - * @var \UnitTester - */ - protected $tester; - - - public function testAnAccessoryBelongsToACompany() { $accessory = Accessory::factory() @@ -57,12 +47,10 @@ class AccessoryTest extends BaseTest public function testAnAccessoryHasAManufacturer() { - $this->createValidManufacturer('apple'); - $this->createValidCategory('accessory-keyboard-category'); $accessory = Accessory::factory()->appleBtKeyboard()->create( [ 'category_id' => Category::factory()->create(), - 'category_id' => Manufacturer::factory()->apple()->create() + 'manufacturer_id' => Manufacturer::factory()->apple()->create() ]); $this->assertInstanceOf(Manufacturer::class, $accessory->manufacturer); } diff --git a/tests/Unit/AssetMaintenanceTest.php b/tests/Unit/AssetMaintenanceTest.php index ccae46ed76..31b68c0cf5 100644 --- a/tests/Unit/AssetMaintenanceTest.php +++ b/tests/Unit/AssetMaintenanceTest.php @@ -2,20 +2,12 @@ namespace Tests\Unit; use App\Models\AssetMaintenance; -use Tests\Unit\BaseTest; use Carbon\Carbon; +use Tests\TestCase; -class AssetMaintenanceTest extends BaseTest +class AssetMaintenanceTest extends TestCase { - /** - * @var \UnitTester - */ - protected $tester; - - /** - * @test - */ - public function it_zeros_out_warranty_if_blank() + public function testZerosOutWarrantyIfBlank() { $c = new AssetMaintenance; $c->is_warranty = ''; @@ -24,10 +16,7 @@ class AssetMaintenanceTest extends BaseTest $this->assertTrue($c->is_warranty == 4); } - /** - * @test - */ - public function it_sets_costs_appropriately() + public function testSetsCostsAppropriately() { $c = new AssetMaintenance(); $c->cost = '0.00'; @@ -38,10 +27,7 @@ class AssetMaintenanceTest extends BaseTest $this->assertTrue($c->cost === 9.5); } - /** - * @test - */ - public function it_nulls_out_notes_if_blank() + public function testNullsOutNotesIfBlank() { $c = new AssetMaintenance; $c->notes = ''; @@ -50,10 +36,7 @@ class AssetMaintenanceTest extends BaseTest $this->assertTrue($c->notes === 'This is a long note'); } - /** - * @test - */ - public function it_nulls_out_completion_date_if_blank_or_invalid() + public function testNullsOutCompletionDateIfBlankOrInvalid() { $c = new AssetMaintenance; $c->completion_date = ''; diff --git a/tests/Unit/AssetModelTest.php b/tests/Unit/AssetModelTest.php index d7c18dc9a7..7050ea307d 100644 --- a/tests/Unit/AssetModelTest.php +++ b/tests/Unit/AssetModelTest.php @@ -4,18 +4,10 @@ namespace Tests\Unit; use App\Models\Asset; use App\Models\Category; use App\Models\AssetModel; -use Illuminate\Foundation\Testing\DatabaseMigrations; -use Illuminate\Foundation\Testing\DatabaseTransactions; -use Illuminate\Foundation\Testing\WithoutMiddleware; -use Tests\Unit\BaseTest; +use Tests\TestCase; -class AssetModelTest extends BaseTest +class AssetModelTest extends TestCase { - /** - * @var \UnitTester - */ - protected $tester; - public function testAnAssetModelZerosOutBlankEols() { $am = new AssetModel; @@ -42,6 +34,4 @@ class AssetModelTest extends BaseTest ); $this->assertEquals(1, $model->assets()->count()); } - - } diff --git a/tests/Unit/AssetTest.php b/tests/Unit/AssetTest.php index 0cc27d80db..f0a9b11f19 100644 --- a/tests/Unit/AssetTest.php +++ b/tests/Unit/AssetTest.php @@ -1,28 +1,14 @@ assertEquals($expected, $next); // } - - /** - * @test - */ public function testWarrantyExpiresAttribute() { @@ -66,5 +48,4 @@ class AssetTest extends BaseTest $this->assertEquals(Carbon::createFromDate(2019, 1, 1)->format('Y-m-d'), $asset->warranty_expires->format('Y-m-d')); } - } diff --git a/tests/Unit/BaseTest.php b/tests/Unit/BaseTest.php deleted file mode 100644 index 83f1181083..0000000000 --- a/tests/Unit/BaseTest.php +++ /dev/null @@ -1,107 +0,0 @@ -create(); - } - - protected function signIn($user = null) - { - if (! $user) { - $user = User::factory()->superuser()->create([ - 'location_id' => $this->createValidLocation()->id, - ]); - } - Auth::login($user); - return $user; - } - - protected function createValidAssetModel() - { - return \App\Models\AssetModel::factory()->create([ - 'category_id' => $this->createValidCategory(), - 'manufacturer_id' => $this->createValidManufacturer(), - 'depreciation_id' => $this->createValidDepreciation(), - ]); - } - - protected function createValidCategory() - { - return \App\Models\Category::factory()->make(); - } - - protected function createValidCompany() - { - return \App\Models\Company::factory()->create(); - } - - protected function createValidDepartment($state = 'engineering', $overrides = []) - { - return \App\Models\Department::factory()->create(array_merge([ - 'location_id' => $this->createValidLocation()->id, - ], $overrides)); - } - - protected function createValidDepreciation() - { - return \App\Models\Depreciation::factory()->create(); - } - - protected function createValidLocation($overrides = []) - { - return \App\Models\Location::factory()->create($overrides); - } - - protected function createValidManufacturer() - { - return \App\Models\Manufacturer::factory()->create(); - } - - protected function createValidSupplier($overrides = []) - { - return \App\Models\Supplier::factory()->create($overrides); - } - - protected function createValidStatuslabel($state = 'rtd', $overrides = []) - { - return \App\Models\Statuslabel::factory()->state()->create($overrides); - } - - protected function createValidUser($overrides = []) - { - return \App\Models\User::factory()->create( - array_merge([ - 'location_id'=>$this->createValidLocation()->id, - ], $overrides) - ); - } - - protected function createValidAsset($overrides = []) - { - $locId = $this->createValidLocation()->id; - $this->createValidAssetModel(); - - return \App\Models\Asset::factory()->laptopMbp()->create( - array_merge([ - 'rtd_location_id' => $locId, - 'location_id' => $locId, - 'supplier_id' => $this->createValidSupplier()->id, - ], $overrides) - ); - } -} diff --git a/tests/Unit/CategoryTest.php b/tests/Unit/CategoryTest.php index eb1c06e696..8d749a3b22 100644 --- a/tests/Unit/CategoryTest.php +++ b/tests/Unit/CategoryTest.php @@ -2,21 +2,12 @@ namespace Tests\Unit; use App\Models\Category; -use Illuminate\Foundation\Testing\DatabaseMigrations; -use Illuminate\Foundation\Testing\DatabaseTransactions; -use Illuminate\Foundation\Testing\WithoutMiddleware; -use Tests\Unit\BaseTest; use App\Models\AssetModel; use App\Models\Asset; -use App\Models\Accessory; +use Tests\TestCase; -class CategoryTest extends BaseTest +class CategoryTest extends TestCase { - /** - * @var \UnitTester - */ - protected $tester; - public function testFailsEmptyValidation() { // An Asset requires a name, a qty, and a category_id. diff --git a/tests/Unit/CompanyTest.php b/tests/Unit/CompanyTest.php index c5c7600290..6e04504843 100644 --- a/tests/Unit/CompanyTest.php +++ b/tests/Unit/CompanyTest.php @@ -2,23 +2,11 @@ namespace Tests\Unit; use App\Models\Company; -use Illuminate\Foundation\Testing\DatabaseMigrations; -use Illuminate\Foundation\Testing\DatabaseTransactions; -use Illuminate\Foundation\Testing\WithoutMiddleware; -use Tests\Unit\BaseTest; -use App\Models\Component; -use App\Models\Asset; -use App\Models\Consumable; use App\Models\User; +use Tests\TestCase; -class CompanyTest extends BaseTest +class CompanyTest extends TestCase { - /** - * @var \UnitTester - */ - protected $tester; - - public function testACompanyCanHaveUsers() { $company = Company::factory()->create(); diff --git a/tests/Unit/ComponentTest.php b/tests/Unit/ComponentTest.php index bca8f3e67c..df8f64771f 100644 --- a/tests/Unit/ComponentTest.php +++ b/tests/Unit/ComponentTest.php @@ -5,20 +5,10 @@ use App\Models\Category; use App\Models\Company; use App\Models\Component; use App\Models\Location; -use Illuminate\Foundation\Testing\DatabaseMigrations; -use Illuminate\Foundation\Testing\DatabaseTransactions; -use Illuminate\Foundation\Testing\WithoutMiddleware; -use Tests\Unit\BaseTest; +use Tests\TestCase; -class ComponentTest extends BaseTest +class ComponentTest extends TestCase { - /** - * @var \UnitTester - */ - protected $tester; - - - public function testAComponentBelongsToACompany() { $component = Component::factory() diff --git a/tests/Unit/ConsumableTest.php b/tests/Unit/ConsumableTest.php deleted file mode 100644 index cbe89b13bb..0000000000 --- a/tests/Unit/ConsumableTest.php +++ /dev/null @@ -1,19 +0,0 @@ -make(['format' => 'IP']); diff --git a/tests/Unit/DepreciationTest.php b/tests/Unit/DepreciationTest.php index abe11d7f85..900ae73671 100644 --- a/tests/Unit/DepreciationTest.php +++ b/tests/Unit/DepreciationTest.php @@ -2,23 +2,15 @@ namespace Tests\Unit; use App\Models\Depreciation; -use Tests\Unit\BaseTest; use App\Models\Category; use App\Models\License; use App\Models\AssetModel; +use Tests\TestCase; -class DepreciationTest extends BaseTest +class DepreciationTest extends TestCase { - /** - * @var \UnitTester - */ - protected $tester; - - - public function testADepreciationHasModels() { - $this->createValidAssetModel(); $depreciation = Depreciation::factory()->create(); AssetModel::factory() diff --git a/tests/Unit/ImporterTest.php b/tests/Unit/ImporterTest.php index dcd7927c2a..b3d5da8b38 100644 --- a/tests/Unit/ImporterTest.php +++ b/tests/Unit/ImporterTest.php @@ -13,19 +13,11 @@ use App\Models\Category; use App\Models\CustomField; use App\Models\Location; use App\Models\User; -use Illuminate\Foundation\Testing\DatabaseMigrations; -use Illuminate\Foundation\Testing\DatabaseTransactions; -use Illuminate\Foundation\Testing\WithoutMiddleware; use Illuminate\Support\Facades\Notification; -use Tests\Unit\BaseTest; +use Tests\TestCase; -class ImporterTest extends BaseTest +class ImporterTest extends TestCase { - /** - * @var \UnitTester - */ -// protected $tester; - // public function testDefaultImportAssetWithCustomFields() // { // $this->signIn(); diff --git a/tests/Unit/LocationTest.php b/tests/Unit/LocationTest.php index eda9c6a896..3fded9e568 100644 --- a/tests/Unit/LocationTest.php +++ b/tests/Unit/LocationTest.php @@ -2,24 +2,16 @@ namespace Tests\Unit; use App\Models\Location; -use Tests\Unit\BaseTest; +use Tests\TestCase; - -class LocationTest extends BaseTest +class LocationTest extends TestCase { - /** - * @var \UnitTester - */ - protected $tester; - public function testPassesIfNotSelfParent() { - $this->createValidLocation(['id' => 10]); - $a = Location::factory()->make([ 'name' => 'Test Location', 'id' => 1, - 'parent_id' => 10, + 'parent_id' => Location::factory()->create(['id' => 10])->id, ]); $this->assertTrue($a->isValid()); diff --git a/tests/Unit/NotificationTest.php b/tests/Unit/NotificationTest.php index 509aee6845..33687ef639 100644 --- a/tests/Unit/NotificationTest.php +++ b/tests/Unit/NotificationTest.php @@ -8,19 +8,13 @@ use App\Models\Category; use Carbon\Carbon; use App\Notifications\CheckoutAssetNotification; use Illuminate\Support\Facades\Notification; -use Tests\Unit\BaseTest; +use Tests\TestCase; - -class NotificationTest extends BaseTest +class NotificationTest extends TestCase { - /** - * @var \UnitTester - */ - protected $tester; - public function testAUserIsEmailedIfTheyCheckoutAnAssetWithEULA() { - + $admin = User::factory()->superuser()->create(); $user = User::factory()->create(); $asset = Asset::factory() ->create( @@ -30,14 +24,13 @@ class NotificationTest extends BaseTest [ 'category_id' => Category::factory()->assetLaptopCategory()->id ] - )->id, + )->id, 'warranty_months' => 24, - 'purchase_date' => Carbon::createFromDate(2017, 1, 1)->hour(0)->minute(0)->second(0) + 'purchase_date' => Carbon::createFromDate(2017, 1, 1)->hour(0)->minute(0)->second(0)->format('Y-m-d') ]); - //dd($asset); Notification::fake(); - $asset->checkOut($user, $asset->id); + $asset->checkOut($user, $admin->id); Notification::assertSentTo($user, CheckoutAssetNotification::class); } } diff --git a/tests/Unit/PermissionsTest.php b/tests/Unit/PermissionsTest.php index 86d40de866..e788585dd2 100644 --- a/tests/Unit/PermissionsTest.php +++ b/tests/Unit/PermissionsTest.php @@ -7,12 +7,9 @@ use App\Models\Component; use App\Models\Consumable; use App\Models\License; use App\Models\User; -use Illuminate\Foundation\Testing\DatabaseMigrations; -use Illuminate\Foundation\Testing\DatabaseTransactions; -use Illuminate\Foundation\Testing\WithoutMiddleware; -use Tests\Unit\BaseTest; +use Tests\TestCase; -class PermissionsTest extends BaseTest +class PermissionsTest extends TestCase { // public function _before() // { diff --git a/tests/Unit/SnipeModelTest.php b/tests/Unit/SnipeModelTest.php index 8884ecf6d3..2bc81da61b 100644 --- a/tests/Unit/SnipeModelTest.php +++ b/tests/Unit/SnipeModelTest.php @@ -2,21 +2,11 @@ namespace Tests\Unit; use App\Models\SnipeModel; -use Tests\Unit\BaseTest; +use Tests\TestCase; -class SnipeModelTest extends BaseTest +class SnipeModelTest extends TestCase { - /** - * @var \UnitTester - */ - protected $tester; - - // tests - - /** - * @test - */ - public function it_sets_purchase_dates_appropriately() + public function testSetsPurchaseDatesAppropriately() { $c = new SnipeModel; $c->purchase_date = ''; @@ -25,10 +15,7 @@ class SnipeModelTest extends BaseTest $this->assertTrue($c->purchase_date === '2016-03-25 12:35:50'); } - /** - * @test - */ - public function it_sets_purchase_costs_appropriately() + public function testSetsPurchaseCostsAppropriately() { $c = new SnipeModel; $c->purchase_cost = '0.00'; @@ -39,10 +26,7 @@ class SnipeModelTest extends BaseTest $this->assertTrue($c->purchase_cost === 9.5); } - /** - * @test - */ - public function it_nulls_blank_location_ids_but_not_others() + public function testNullsBlankLocationIdsButNotOthers() { $c = new SnipeModel; $c->location_id = ''; @@ -51,10 +35,7 @@ class SnipeModelTest extends BaseTest $this->assertTrue($c->location_id == 5); } - /** - * @test - */ - public function it_nulls_blank_categories_but_not_others() + public function testNullsBlankCategoriesButNotOthers() { $c = new SnipeModel; $c->category_id = ''; @@ -63,10 +44,7 @@ class SnipeModelTest extends BaseTest $this->assertTrue($c->category_id == 1); } - /** - * @test - */ - public function it_nulls_blank_suppliers_but_not_others() + public function testNullsBlankSuppliersButNotOthers() { $c = new SnipeModel; $c->supplier_id = ''; @@ -75,10 +53,7 @@ class SnipeModelTest extends BaseTest $this->assertTrue($c->supplier_id == 4); } - /** - * @test - */ - public function it_nulls_blank_depreciations_but_not_others() + public function testNullsBlankDepreciationsButNotOthers() { $c = new SnipeModel; $c->depreciation_id = ''; @@ -87,10 +62,7 @@ class SnipeModelTest extends BaseTest $this->assertTrue($c->depreciation_id == 4); } - /** - * @test - */ - public function it_nulls_blank_manufacturers_but_not_others() + public function testNullsBlankManufacturersButNotOthers() { $c = new SnipeModel; $c->manufacturer_id = ''; diff --git a/tests/Unit/StatuslabelTest.php b/tests/Unit/StatuslabelTest.php index 5ec209af1b..fe5f3cacc0 100644 --- a/tests/Unit/StatuslabelTest.php +++ b/tests/Unit/StatuslabelTest.php @@ -2,18 +2,10 @@ namespace Tests\Unit; use App\Models\Statuslabel; -use Illuminate\Foundation\Testing\DatabaseMigrations; -use Illuminate\Foundation\Testing\DatabaseTransactions; -use Illuminate\Foundation\Testing\WithoutMiddleware; -use Tests\Unit\BaseTest; +use Tests\TestCase; -class StatuslabelTest extends BaseTest +class StatuslabelTest extends TestCase { - /** - * @var \UnitTester - */ - protected $tester; - public function testRTDStatuslabelAdd() { $statuslabel = Statuslabel::factory()->rtd()->create(); diff --git a/tests/Unit/UserTest.php b/tests/Unit/UserTest.php index d5891a8323..e089fc4023 100644 --- a/tests/Unit/UserTest.php +++ b/tests/Unit/UserTest.php @@ -2,18 +2,10 @@ namespace Tests\Unit; use App\Models\User; -use Illuminate\Foundation\Testing\DatabaseMigrations; -use Illuminate\Foundation\Testing\DatabaseTransactions; -use Illuminate\Foundation\Testing\WithoutMiddleware; -use Tests\Unit\BaseTest; +use Tests\TestCase; -class UserTest extends BaseTest +class UserTest extends TestCase { - /** - * @var \UnitTester - */ - protected $tester; - public function testFirstNameSplit() { $fullname = "Natalia Allanovna Romanova-O'Shostakova";