A free open source IT asset/license management system
Migrate to response macros for readability
Marcus Moorea35d83d14a07
diff --git a/tests/Feature/Api/Assets/AssetIndexTest.php b/tests/Feature/Api/Assets/AssetIndexTest.phpindex 9ca415c74d..0fe3a4d306 100644--- a/tests/Feature/Api/Assets/AssetIndexTest.php+++ b/tests/Feature/Api/Assets/AssetIndexTest.php@@ -7,13 +7,11 @@ use App\Models\Company;use App\Models\User;use Illuminate\Testing\Fluent\AssertableJson;use Laravel\Passport\Passport;-use Tests\Support\InteractsWithResponses;use Tests\Support\InteractsWithSettings;use Tests\TestCase;class AssetIndexTest extends TestCase{- use InteractsWithResponses;use InteractsWithSettings;public function testAssetIndexReturnsExpectedAssets()@@ -50,35 +48,35 @@ class AssetIndexTest extends TestCase$this->settings->disableMultipleFullCompanySupport();Passport::actingAs($superUser);- $response = $this->getJson(route('api.assets.index'));- $this->assertResponseContainsInRows($response, $assetA, 'asset_tag');- $this->assertResponseContainsInRows($response, $assetB, 'asset_tag');+ $this->getJson(route('api.assets.index'))+ ->assertResponseContainsInRows($assetA, 'asset_tag')+ ->assertResponseContainsInRows($assetB, 'asset_tag');Passport::actingAs($userInCompanyA);- $response = $this->getJson(route('api.assets.index'));- $this->assertResponseContainsInRows($response, $assetA, 'asset_tag');- $this->assertResponseContainsInRows($response, $assetB, 'asset_tag');+ $this->getJson(route('api.assets.index'))+ ->assertResponseContainsInRows($assetA, 'asset_tag')+ ->assertResponseContainsInRows($assetB, 'asset_tag');Passport::actingAs($userInCompanyB);- $response = $this->getJson(route('api.assets.index'));- $this->assertResponseContainsInRows($response, $assetA, 'asset_tag');- $this->assertResponseContainsInRows($response, $assetB, 'asset_tag');+ $this->getJson(route('api.assets.index'))+ ->assertResponseContainsInRows($assetA, 'asset_tag')+ ->assertResponseContainsInRows($assetB, 'asset_tag');$this->settings->enableMultipleFullCompanySupport();Passport::actingAs($superUser);- $response = $this->getJson(route('api.assets.index'));- $this->assertResponseContainsInRows($response, $assetA, 'asset_tag');- $this->assertResponseContainsInRows($response, $assetB, 'asset_tag');+ $this->getJson(route('api.assets.index'))+ ->assertResponseContainsInRows($assetA, 'asset_tag')+ ->assertResponseContainsInRows($assetB, 'asset_tag');Passport::actingAs($userInCompanyA);- $response = $this->getJson(route('api.assets.index'));- $this->assertResponseContainsInRows($response, $assetA, 'asset_tag');- $this->assertResponseDoesNotContainInRows($response, $assetB, 'asset_tag');+ $this->getJson(route('api.assets.index'))+ ->assertResponseContainsInRows($assetA, 'asset_tag')+ ->assertResponseDoesNotContainInRows($assetB, 'asset_tag');Passport::actingAs($userInCompanyB);- $response = $this->getJson(route('api.assets.index'));- $this->assertResponseDoesNotContainInRows($response, $assetA, 'asset_tag');- $this->assertResponseContainsInRows($response, $assetB, 'asset_tag');+ $this->getJson(route('api.assets.index'))+ ->assertResponseDoesNotContainInRows($assetA, 'asset_tag')+ ->assertResponseContainsInRows($assetB, 'asset_tag');}}diff --git a/tests/Feature/Api/Assets/AssetsForSelectListTest.php b/tests/Feature/Api/Assets/AssetsForSelectListTest.phpindex fbc5a1e332..a3210b9886 100644--- a/tests/Feature/Api/Assets/AssetsForSelectListTest.php+++ b/tests/Feature/Api/Assets/AssetsForSelectListTest.php@@ -6,13 +6,11 @@ use App\Models\Asset;use App\Models\Company;use App\Models\User;use Laravel\Passport\Passport;-use Tests\Support\InteractsWithResponses;use Tests\Support\InteractsWithSettings;use Tests\TestCase;class AssetsForSelectListTest extends TestCase{- use InteractsWithResponses;use InteractsWithSettings;public function testAssetsCanBeSearchedForByAssetTag()@@ -45,35 +43,35 @@ class AssetsForSelectListTest extends TestCase$this->settings->disableMultipleFullCompanySupport();Passport::actingAs($superUser);- $response = $this->getJson(route('assets.selectlist', ['search' => '000']));- $this->assertResponseContainsInResults($response, $assetA);- $this->assertResponseContainsInResults($response, $assetB);+ $this->getJson(route('assets.selectlist', ['search' => '000']))+ ->assertResponseContainsInResults($assetA)+ ->assertResponseContainsInResults($assetB);Passport::actingAs($userInCompanyA);- $response = $this->getJson(route('assets.selectlist', ['search' => '000']));- $this->assertResponseContainsInResults($response, $assetA);- $this->assertResponseContainsInResults($response, $assetB);+ $this->getJson(route('assets.selectlist', ['search' => '000']))+ ->assertResponseContainsInResults($assetA)+ ->assertResponseContainsInResults($assetB);Passport::actingAs($userInCompanyB);- $response = $this->getJson(route('assets.selectlist', ['search' => '000']));- $this->assertResponseContainsInResults($response, $assetA);- $this->assertResponseContainsInResults($response, $assetB);+ $this->getJson(route('assets.selectlist', ['search' => '000']))+ ->assertResponseContainsInResults($assetA)+ ->assertResponseContainsInResults($assetB);$this->settings->enableMultipleFullCompanySupport();Passport::actingAs($superUser);- $response = $this->getJson(route('assets.selectlist', ['search' => '000']));- $this->assertResponseContainsInResults($response, $assetA);- $this->assertResponseContainsInResults($response, $assetB);+ $this->getJson(route('assets.selectlist', ['search' => '000']))+ ->assertResponseContainsInResults($assetA)+ ->assertResponseContainsInResults($assetB);Passport::actingAs($userInCompanyA);- $response = $this->getJson(route('assets.selectlist', ['search' => '000']));- $this->assertResponseContainsInResults($response, $assetA);- $this->assertResponseDoesNotContainInResults($response, $assetB);+ $this->getJson(route('assets.selectlist', ['search' => '000']))+ ->assertResponseContainsInResults($assetA)+ ->assertResponseDoesNotContainInResults($assetB);Passport::actingAs($userInCompanyB);- $response = $this->getJson(route('assets.selectlist', ['search' => '000']));- $this->assertResponseDoesNotContainInResults($response, $assetA);- $this->assertResponseContainsInResults($response, $assetB);+ $this->getJson(route('assets.selectlist', ['search' => '000']))+ ->assertResponseDoesNotContainInResults($assetA)+ ->assertResponseContainsInResults($assetB);}}diff --git a/tests/Feature/Api/Assets/RequestableAssetsTest.php b/tests/Feature/Api/Assets/RequestableAssetsTest.phpindex 7c9b4e1204..7ecddeaa02 100644--- a/tests/Feature/Api/Assets/RequestableAssetsTest.php+++ b/tests/Feature/Api/Assets/RequestableAssetsTest.php@@ -6,13 +6,11 @@ use App\Models\Asset;use App\Models\Company;use App\Models\User;use Laravel\Passport\Passport;-use Tests\Support\InteractsWithResponses;use Tests\Support\InteractsWithSettings;use Tests\TestCase;class RequestableAssetsTest extends TestCase{- use InteractsWithResponses;use InteractsWithSettings;public function testViewingRequestableAssetsRequiresCorrectPermission()@@ -27,10 +25,10 @@ class RequestableAssetsTest extends TestCase$nonRequestableAsset = Asset::factory()->nonrequestable()->create(['asset_tag' => 'non-requestable']);Passport::actingAs(User::factory()->viewRequestableAssets()->create());- $response = $this->getJson(route('api.assets.requestable'))->assertOk();-- $this->assertResponseContainsInRows($response, $requestableAsset, 'asset_tag');- $this->assertResponseDoesNotContainInRows($response, $nonRequestableAsset, 'asset_tag');+ $this->getJson(route('api.assets.requestable'))+ ->assertOk()+ ->assertResponseContainsInRows($requestableAsset, 'asset_tag')+ ->assertResponseDoesNotContainInRows($nonRequestableAsset, 'asset_tag');}public function testRequestableAssetsAreScopedToCompanyWhenMultipleCompanySupportEnabled()@@ -47,35 +45,35 @@ class RequestableAssetsTest extends TestCase$this->settings->disableMultipleFullCompanySupport();Passport::actingAs($superUser);- $response = $this->getJson(route('api.assets.requestable'));- $this->assertResponseContainsInRows($response, $assetA, 'asset_tag');- $this->assertResponseContainsInRows($response, $assetB, 'asset_tag');+ $this->getJson(route('api.assets.requestable'))+ ->assertResponseContainsInRows($assetA, 'asset_tag')+ ->assertResponseContainsInRows($assetB, 'asset_tag');Passport::actingAs($userInCompanyA);- $response = $this->getJson(route('api.assets.requestable'));- $this->assertResponseContainsInRows($response, $assetA, 'asset_tag');- $this->assertResponseContainsInRows($response, $assetB, 'asset_tag');+ $this->getJson(route('api.assets.requestable'))+ ->assertResponseContainsInRows($assetA, 'asset_tag')+ ->assertResponseContainsInRows($assetB, 'asset_tag');Passport::actingAs($userInCompanyB);- $response = $this->getJson(route('api.assets.requestable'));- $this->assertResponseContainsInRows($response, $assetA, 'asset_tag');- $this->assertResponseContainsInRows($response, $assetB, 'asset_tag');+ $this->getJson(route('api.assets.requestable'))+ ->assertResponseContainsInRows($assetA, 'asset_tag')+ ->assertResponseContainsInRows($assetB, 'asset_tag');$this->settings->enableMultipleFullCompanySupport();Passport::actingAs($superUser);- $response = $this->getJson(route('api.assets.requestable'));- $this->assertResponseContainsInRows($response, $assetA, 'asset_tag');- $this->assertResponseContainsInRows($response, $assetB, 'asset_tag');+ $this->getJson(route('api.assets.requestable'))+ ->assertResponseContainsInRows($assetA, 'asset_tag')+ ->assertResponseContainsInRows($assetB, 'asset_tag');Passport::actingAs($userInCompanyA);- $response = $this->getJson(route('api.assets.requestable'));- $this->assertResponseContainsInRows($response, $assetA, 'asset_tag');- $this->assertResponseDoesNotContainInRows($response, $assetB, 'asset_tag');+ $this->getJson(route('api.assets.requestable'))+ ->assertResponseContainsInRows($assetA, 'asset_tag')+ ->assertResponseDoesNotContainInRows($assetB, 'asset_tag');Passport::actingAs($userInCompanyB);- $response = $this->getJson(route('api.assets.requestable'));- $this->assertResponseDoesNotContainInRows($response, $assetA, 'asset_tag');- $this->assertResponseContainsInRows($response, $assetB, 'asset_tag');+ $this->getJson(route('api.assets.requestable'))+ ->assertResponseDoesNotContainInRows($assetA, 'asset_tag')+ ->assertResponseContainsInRows($assetB, 'asset_tag');}}diff --git a/tests/Feature/Api/Components/ComponentIndexTest.php b/tests/Feature/Api/Components/ComponentIndexTest.phpindex 845ce29b99..276f22e6f1 100644--- a/tests/Feature/Api/Components/ComponentIndexTest.php+++ b/tests/Feature/Api/Components/ComponentIndexTest.php@@ -6,13 +6,11 @@ use App\Models\Company;use App\Models\Component;use App\Models\User;use Laravel\Passport\Passport;-use Tests\Support\InteractsWithResponses;use Tests\Support\InteractsWithSettings;use Tests\TestCase;class ComponentIndexTest extends TestCase{- use InteractsWithResponses;use InteractsWithSettings;public function testComponentIndexAdheresToCompanyScoping()@@ -29,35 +27,35 @@ class ComponentIndexTest extends TestCase$this->settings->disableMultipleFullCompanySupport();Passport::actingAs($superUser);- $response = $this->getJson(route('api.components.index'));- $this->assertResponseContainsInRows($response, $componentA);- $this->assertResponseContainsInRows($response, $componentB);+ $this->getJson(route('api.components.index'))+ ->assertResponseContainsInRows($componentA)+ ->assertResponseContainsInRows($componentB);Passport::actingAs($userInCompanyA);- $response = $this->getJson(route('api.components.index'));- $this->assertResponseContainsInRows($response, $componentA);- $this->assertResponseContainsInRows($response, $componentB);+ $this->getJson(route('api.components.index'))+ ->assertResponseContainsInRows($componentA)+ ->assertResponseContainsInRows($componentB);Passport::actingAs($userInCompanyB);- $response = $this->getJson(route('api.components.index'));- $this->assertResponseContainsInRows($response, $componentA);- $this->assertResponseContainsInRows($response, $componentB);+ $this->getJson(route('api.components.index'))+ ->assertResponseContainsInRows($componentA)+ ->assertResponseContainsInRows($componentB);$this->settings->enableMultipleFullCompanySupport();Passport::actingAs($superUser);- $response = $this->getJson(route('api.components.index'));- $this->assertResponseContainsInRows($response, $componentA);- $this->assertResponseContainsInRows($response, $componentB);+ $this->getJson(route('api.components.index'))+ ->assertResponseContainsInRows($componentA)+ ->assertResponseContainsInRows($componentB);Passport::actingAs($userInCompanyA);- $response = $this->getJson(route('api.components.index'));- $this->assertResponseContainsInRows($response, $componentA);- $this->assertResponseDoesNotContainInRows($response, $componentB);+ $this->getJson(route('api.components.index'))+ ->assertResponseContainsInRows($componentA)+ ->assertResponseDoesNotContainInRows($componentB);Passport::actingAs($userInCompanyB);- $response = $this->getJson(route('api.components.index'));- $this->assertResponseDoesNotContainInRows($response, $componentA);- $this->assertResponseContainsInRows($response, $componentB);+ $this->getJson(route('api.components.index'))+ ->assertResponseDoesNotContainInRows($componentA)+ ->assertResponseContainsInRows($componentB);}}diff --git a/tests/Feature/Api/Consumables/ConsumablesIndexTest.php b/tests/Feature/Api/Consumables/ConsumablesIndexTest.phpindex 11a4d79afa..6e6e809c6c 100644--- a/tests/Feature/Api/Consumables/ConsumablesIndexTest.php+++ b/tests/Feature/Api/Consumables/ConsumablesIndexTest.php@@ -6,13 +6,11 @@ use App\Models\Company;use App\Models\Consumable;use App\Models\User;use Laravel\Passport\Passport;-use Tests\Support\InteractsWithResponses;use Tests\Support\InteractsWithSettings;use Tests\TestCase;class ConsumablesIndexTest extends TestCase{- use InteractsWithResponses;use InteractsWithSettings;public function testConsumableIndexAdheresToCompanyScoping()@@ -29,35 +27,35 @@ class ConsumablesIndexTest extends TestCase$this->settings->disableMultipleFullCompanySupport();Passport::actingAs($superUser);- $response = $this->getJson(route('api.consumables.index'));- $this->assertResponseContainsInRows($response, $consumableA);- $this->assertResponseContainsInRows($response, $consumableB);+ $this->getJson(route('api.consumables.index'))+ ->assertResponseContainsInRows($consumableA)+ ->assertResponseContainsInRows($consumableB);Passport::actingAs($userInCompanyA);- $response = $this->getJson(route('api.consumables.index'));- $this->assertResponseContainsInRows($response, $consumableA);- $this->assertResponseContainsInRows($response, $consumableB);+ $this->getJson(route('api.consumables.index'))+ ->assertResponseContainsInRows($consumableA)+ ->assertResponseContainsInRows($consumableB);Passport::actingAs($userInCompanyB);- $response = $this->getJson(route('api.consumables.index'));- $this->assertResponseContainsInRows($response, $consumableA);- $this->assertResponseContainsInRows($response, $consumableB);+ $this->getJson(route('api.consumables.index'))+ ->assertResponseContainsInRows($consumableA)+ ->assertResponseContainsInRows($consumableB);$this->settings->enableMultipleFullCompanySupport();Passport::actingAs($superUser);- $response = $this->getJson(route('api.consumables.index'));- $this->assertResponseContainsInRows($response, $consumableA);- $this->assertResponseContainsInRows($response, $consumableB);+ $this->getJson(route('api.consumables.index'))+ ->assertResponseContainsInRows($consumableA)+ ->assertResponseContainsInRows($consumableB);Passport::actingAs($userInCompanyA);- $response = $this->getJson(route('api.consumables.index'));- $this->assertResponseContainsInRows($response, $consumableA);- $this->assertResponseDoesNotContainInRows($response, $consumableB);+ $this->getJson(route('api.consumables.index'))+ ->assertResponseContainsInRows($consumableA)+ ->assertResponseDoesNotContainInRows($consumableB);Passport::actingAs($userInCompanyB);- $response = $this->getJson(route('api.consumables.index'));- $this->assertResponseDoesNotContainInRows($response, $consumableA);- $this->assertResponseContainsInRows($response, $consumableB);+ $this->getJson(route('api.consumables.index'))+ ->assertResponseDoesNotContainInRows($consumableA)+ ->assertResponseContainsInRows($consumableB);}}diff --git a/tests/Feature/Api/Departments/DepartmentsIndexTest.php b/tests/Feature/Api/Departments/DepartmentsIndexTest.phpindex 7e813ad9cb..9570e85307 100644--- a/tests/Feature/Api/Departments/DepartmentsIndexTest.php+++ b/tests/Feature/Api/Departments/DepartmentsIndexTest.php@@ -6,13 +6,11 @@ use App\Models\Company;use App\Models\Department;use App\Models\User;use Laravel\Passport\Passport;-use Tests\Support\InteractsWithResponses;use Tests\Support\InteractsWithSettings;use Tests\TestCase;class DepartmentsIndexTest extends TestCase{- use InteractsWithResponses;use InteractsWithSettings;public function testDepartmentsIndexAdheresToCompanyScoping()@@ -33,35 +31,35 @@ class DepartmentsIndexTest extends TestCase$this->settings->disableMultipleFullCompanySupport();Passport::actingAs($superUser);- $response = $this->getJson(route('api.departments.index'));- $this->assertResponseContainsInRows($response, $departmentA);- $this->assertResponseContainsInRows($response, $departmentB);+ $this->getJson(route('api.departments.index'))+ ->assertResponseContainsInRows($departmentA)+ ->assertResponseContainsInRows($departmentB);Passport::actingAs($userInCompanyA);- $response = $this->getJson(route('api.departments.index'));- $this->assertResponseContainsInRows($response, $departmentA);- $this->assertResponseContainsInRows($response, $departmentB);+ $this->getJson(route('api.departments.index'))+ ->assertResponseContainsInRows($departmentA)+ ->assertResponseContainsInRows($departmentB);Passport::actingAs($userInCompanyB);- $response = $this->getJson(route('api.departments.index'));- $this->assertResponseContainsInRows($response, $departmentA);- $this->assertResponseContainsInRows($response, $departmentB);+ $this->getJson(route('api.departments.index'))+ ->assertResponseContainsInRows($departmentA)+ ->assertResponseContainsInRows($departmentB);$this->settings->enableMultipleFullCompanySupport();Passport::actingAs($superUser);- $response = $this->getJson(route('api.departments.index'));- $this->assertResponseContainsInRows($response, $departmentA);- $this->assertResponseContainsInRows($response, $departmentB);+ $this->getJson(route('api.departments.index'))+ ->assertResponseContainsInRows($departmentA)+ ->assertResponseContainsInRows($departmentB);Passport::actingAs($userInCompanyA);- $response = $this->getJson(route('api.departments.index'));- $this->assertResponseContainsInRows($response, $departmentA);- $this->assertResponseDoesNotContainInRows($response, $departmentB);+ $this->getJson(route('api.departments.index'))+ ->assertResponseContainsInRows($departmentA)+ ->assertResponseDoesNotContainInRows($departmentB);Passport::actingAs($userInCompanyB);- $response = $this->getJson(route('api.departments.index'));- $this->assertResponseDoesNotContainInRows($response, $departmentA);- $this->assertResponseContainsInRows($response, $departmentB);+ $this->getJson(route('api.departments.index'))+ ->assertResponseDoesNotContainInRows($departmentA)+ ->assertResponseContainsInRows($departmentB);}}diff --git a/tests/Feature/Api/Licenses/LicensesIndexTest.php b/tests/Feature/Api/Licenses/LicensesIndexTest.phpindex 404eb31238..fd85239928 100644--- a/tests/Feature/Api/Licenses/LicensesIndexTest.php+++ b/tests/Feature/Api/Licenses/LicensesIndexTest.php@@ -6,13 +6,11 @@ use App\Models\Company;use App\Models\License;use App\Models\User;use Laravel\Passport\Passport;-use Tests\Support\InteractsWithResponses;use Tests\Support\InteractsWithSettings;use Tests\TestCase;class LicensesIndexTest extends TestCase{- use InteractsWithResponses;use InteractsWithSettings;public function testLicensesIndexAdheresToCompanyScoping()@@ -29,35 +27,35 @@ class LicensesIndexTest extends TestCase$this->settings->disableMultipleFullCompanySupport();Passport::actingAs($superUser);- $response = $this->getJson(route('api.licenses.index'));- $this->assertResponseContainsInRows($response, $licenseA);- $this->assertResponseContainsInRows($response, $licenseB);+ $this->getJson(route('api.licenses.index'))+ ->assertResponseContainsInRows($licenseA)+ ->assertResponseContainsInRows($licenseB);Passport::actingAs($userInCompanyA);- $response = $this->getJson(route('api.licenses.index'));- $this->assertResponseContainsInRows($response, $licenseA);- $this->assertResponseContainsInRows($response, $licenseB);+ $this->getJson(route('api.licenses.index'))+ ->assertResponseContainsInRows($licenseA)+ ->assertResponseContainsInRows($licenseB);Passport::actingAs($userInCompanyB);- $response = $this->getJson(route('api.licenses.index'));- $this->assertResponseContainsInRows($response, $licenseA);- $this->assertResponseContainsInRows($response, $licenseB);+ $this->getJson(route('api.licenses.index'))+ ->assertResponseContainsInRows($licenseA)+ ->assertResponseContainsInRows($licenseB);$this->settings->enableMultipleFullCompanySupport();Passport::actingAs($superUser);- $response = $this->getJson(route('api.licenses.index'));- $this->assertResponseContainsInRows($response, $licenseA);- $this->assertResponseContainsInRows($response, $licenseB);+ $this->getJson(route('api.licenses.index'))+ ->assertResponseContainsInRows($licenseA)+ ->assertResponseContainsInRows($licenseB);Passport::actingAs($userInCompanyA);- $response = $this->getJson(route('api.licenses.index'));- $this->assertResponseContainsInRows($response, $licenseA);- $this->assertResponseDoesNotContainInRows($response, $licenseB);+ $this->getJson(route('api.licenses.index'))+ ->assertResponseContainsInRows($licenseA)+ ->assertResponseDoesNotContainInRows($licenseB);Passport::actingAs($userInCompanyB);- $response = $this->getJson(route('api.licenses.index'));- $this->assertResponseDoesNotContainInRows($response, $licenseA);- $this->assertResponseContainsInRows($response, $licenseB);+ $this->getJson(route('api.licenses.index'))+ ->assertResponseDoesNotContainInRows($licenseA)+ ->assertResponseContainsInRows($licenseB);}}diff --git a/tests/Feature/Api/Users/UsersIndexTest.php b/tests/Feature/Api/Users/UsersIndexTest.phpindex b48da4483d..ed91976ccb 100644--- a/tests/Feature/Api/Users/UsersIndexTest.php+++ b/tests/Feature/Api/Users/UsersIndexTest.php@@ -5,13 +5,11 @@ namespace Tests\Feature\Api\Users;use App\Models\Company;use App\Models\User;use Laravel\Passport\Passport;-use Tests\Support\InteractsWithResponses;use Tests\Support\InteractsWithSettings;use Tests\TestCase;class UsersIndexTest extends TestCase{- use InteractsWithResponses;use InteractsWithSettings;public function testUsersIndexAdheresToCompanyScoping()@@ -32,35 +30,35 @@ class UsersIndexTest extends TestCase$this->settings->disableMultipleFullCompanySupport();Passport::actingAs($superUser);- $response = $this->getJson(route('api.users.index'));- $this->assertResponseContainsInRows($response, $userA, 'first_name');- $this->assertResponseContainsInRows($response, $userB, 'first_name');+ $this->getJson(route('api.users.index'))+ ->assertResponseContainsInRows($userA, 'first_name')+ ->assertResponseContainsInRows($userB, 'first_name');Passport::actingAs($userInCompanyA);- $response = $this->getJson(route('api.users.index'));- $this->assertResponseContainsInRows($response, $userA, 'first_name');- $this->assertResponseContainsInRows($response, $userB, 'first_name');+ $this->getJson(route('api.users.index'))+ ->assertResponseContainsInRows($userA, 'first_name')+ ->assertResponseContainsInRows($userB, 'first_name');Passport::actingAs($userInCompanyB);- $response = $this->getJson(route('api.users.index'));- $this->assertResponseContainsInRows($response, $userA, 'first_name');- $this->assertResponseContainsInRows($response, $userB, 'first_name');+ $this->getJson(route('api.users.index'))+ ->assertResponseContainsInRows($userA, 'first_name')+ ->assertResponseContainsInRows($userB, 'first_name');$this->settings->enableMultipleFullCompanySupport();Passport::actingAs($superUser);- $response = $this->getJson(route('api.users.index'));- $this->assertResponseContainsInRows($response, $userA, 'first_name');- $this->assertResponseContainsInRows($response, $userB, 'first_name');+ $this->getJson(route('api.users.index'))+ ->assertResponseContainsInRows($userA, 'first_name')+ ->assertResponseContainsInRows($userB, 'first_name');Passport::actingAs($userInCompanyA);- $response = $this->getJson(route('api.users.index'));- $this->assertResponseContainsInRows($response, $userA, 'first_name');- $this->assertResponseDoesNotContainInRows($response, $userB, 'first_name');+ $this->getJson(route('api.users.index'))+ ->assertResponseContainsInRows($userA, 'first_name')+ ->assertResponseDoesNotContainInRows($userB, 'first_name');Passport::actingAs($userInCompanyB);- $response = $this->getJson(route('api.users.index'));- $this->assertResponseDoesNotContainInRows($response, $userA, 'first_name');- $this->assertResponseContainsInRows($response, $userB, 'first_name');+ $this->getJson(route('api.users.index'))+ ->assertResponseDoesNotContainInRows($userA, 'first_name')+ ->assertResponseContainsInRows($userB, 'first_name');}}diff --git a/tests/Support/CustomTestMacros.php b/tests/Support/CustomTestMacros.phpnew file mode 100644index 0000000000..0a30d7c243--- /dev/null+++ b/tests/Support/CustomTestMacros.php@@ -0,0 +1,66 @@+<?php++namespace Tests\Support;++use Illuminate\Database\Eloquent\Model;+use Illuminate\Testing\TestResponse;+use PHPUnit\Framework\Assert;+use RuntimeException;++trait CustomTestMacros+{+ protected function registerCustomMacros()+ {+ $guardAgainstNullProperty = function (Model $model, string $property) {+ if (is_null($model->{$property})) {+ throw new RuntimeException(+ "The property ({$property}) either does not exist or is null on the model which isn't helpful for comparison."+ );+ }+ };++ TestResponse::macro(+ 'assertResponseContainsInRows',+ function (Model $model, string $property = 'name') use ($guardAgainstNullProperty) {+ $guardAgainstNullProperty($model, $property);++ Assert::assertTrue(collect($this['rows'])->pluck($property)->contains($model->{$property}));++ return $this;+ }+ );++ TestResponse::macro(+ 'assertResponseDoesNotContainInRows',+ function (Model $model, string $property = 'name') use ($guardAgainstNullProperty) {+ $guardAgainstNullProperty($model, $property);++ Assert::assertFalse(collect($this['rows'])->pluck($property)->contains($model->{$property}));++ return $this;+ }+ );++ TestResponse::macro(+ 'assertResponseContainsInResults',+ function (Model $model, string $property = 'id') use ($guardAgainstNullProperty) {+ $guardAgainstNullProperty($model, $property);++ Assert::assertTrue(collect($this->json('results'))->pluck('id')->contains($model->{$property}));++ return $this;+ }+ );++ TestResponse::macro(+ 'assertResponseDoesNotContainInResults',+ function (Model $model, string $property = 'id') use ($guardAgainstNullProperty) {+ $guardAgainstNullProperty($model, $property);++ Assert::assertFalse(collect($this->json('results'))->pluck('id')->contains($model->{$property}));++ return $this;+ }+ );+ }+}diff --git a/tests/Support/InteractsWithResponses.php b/tests/Support/InteractsWithResponses.phpdeleted file mode 100644index 03faf0ef22..0000000000--- a/tests/Support/InteractsWithResponses.php+++ /dev/null@@ -1,47 +0,0 @@-<?php--namespace Tests\Support;--use Illuminate\Database\Eloquent\Model;-use Illuminate\Testing\TestResponse;-use RuntimeException;--trait InteractsWithResponses-{- protected function assertResponseContainsInRows(TestResponse $response, Model $model, string $property = 'name')- {- $this->guardAgainstNullProperty($model, $property);-- $this->assertTrue(collect($response['rows'])->pluck($property)->contains($model->{$property}));- }-- protected function assertResponseDoesNotContainInRows(TestResponse $response, Model $model, string $property = 'name')- {- $this->guardAgainstNullProperty($model, $property);-- $this->assertFalse(collect($response['rows'])->pluck($property)->contains($model->{$property}));- }-- protected function assertResponseContainsInResults(TestResponse $response, Model $model, string $property = 'id')- {- $this->guardAgainstNullProperty($model, $property);-- $this->assertTrue(collect($response->json('results'))->pluck('id')->contains($model->{$property}));- }-- protected function assertResponseDoesNotContainInResults(TestResponse $response, Model $model, string $property = 'id')- {- $this->guardAgainstNullProperty($model, $property);-- $this->assertFalse(collect($response->json('results'))->pluck('id')->contains($model->{$property}));- }-- private function guardAgainstNullProperty(Model $model, string $property): void- {- if (is_null($model->{$property})) {- throw new RuntimeException(- "The property ({$property}) either does not exist or is null on the model which isn't helpful for comparison."- );- }- }-}diff --git a/tests/TestCase.php b/tests/TestCase.phpindex 28051c7c7f..4a5c3da692 100644--- a/tests/TestCase.php+++ b/tests/TestCase.php@@ -5,11 +5,13 @@ namespace Tests;use App\Http\Middleware\SecurityHeaders;use Illuminate\Foundation\Testing\LazilyRefreshDatabase;use Illuminate\Foundation\Testing\TestCase as BaseTestCase;+use Tests\Support\CustomTestMacros;use Tests\Support\InteractsWithSettings;abstract class TestCase extends BaseTestCase{use CreatesApplication;+ use CustomTestMacros;use LazilyRefreshDatabase;private array $globallyDisabledMiddleware = [@@ -25,5 +27,7 @@ abstract class TestCase extends BaseTestCaseif (collect(class_uses_recursive($this))->contains(InteractsWithSettings::class)) {$this->initializeSettings();}++ $this->registerCustomMacros();}}