A free open source IT asset/license management system
Consolidate streamed response macros into CustomTestMacros trait
Marcus Mooreba1040e29e94
diff --git a/tests/Feature/Reporting/Custom/CustomAssetReportTest.php b/tests/Feature/Reporting/Custom/CustomAssetReportTest.phpindex 1d66953643..71df447d40 100644--- a/tests/Feature/Reporting/Custom/CustomAssetReportTest.php+++ b/tests/Feature/Reporting/Custom/CustomAssetReportTest.php@@ -8,46 +8,13 @@ use App\Models\CustomField;use App\Models\ReportTemplate;use App\Models\User;use Illuminate\Support\Facades\Crypt;-use Illuminate\Testing\TestResponse;use League\Csv\Reader;-use PHPUnit\Framework\Assert;use PHPUnit\Framework\Attributes\Group;use Tests\TestCase;#[Group('custom-reporting')]class CustomAssetReportTest extends TestCase{- protected function setUp(): void- {- parent::setUp();-- TestResponse::macro(- 'assertSeeTextInStreamedResponse',- function (string $needle) {- Assert::assertTrue(- collect(Reader::createFromString($this->streamedContent())->getRecords())- ->pluck(0)- ->contains($needle)- );-- return $this;- }- );-- TestResponse::macro(- 'assertDontSeeTextInStreamedResponse',- function (string $needle) {- Assert::assertFalse(- collect(Reader::createFromString($this->streamedContent())->getRecords())- ->pluck(0)- ->contains($needle)- );-- return $this;- }- );- }-public function test_requires_permission_to_view_page(){$this->actingAs(User::factory()->create())diff --git a/tests/Feature/Reporting/UnacceptedAssetReportTest.php b/tests/Feature/Reporting/UnacceptedAssetReportTest.phpindex 738e68e5ca..b16c6ecf62 100644--- a/tests/Feature/Reporting/UnacceptedAssetReportTest.php+++ b/tests/Feature/Reporting/UnacceptedAssetReportTest.php@@ -3,44 +3,10 @@namespace Tests\Feature\Reporting;use App\Models\User;-use Illuminate\Testing\TestResponse;-use League\Csv\Reader;-use PHPUnit\Framework\Assert;use Tests\TestCase;class UnacceptedAssetReportTest extends TestCase{- protected function setUp(): void- {- parent::setUp();-- TestResponse::macro(- 'assertSeeTextInStreamedResponse',- function (string $needle) {- Assert::assertTrue(- collect(Reader::createFromString($this->streamedContent())->getRecords())- ->pluck(0)- ->contains($needle)- );-- return $this;- }- );-- TestResponse::macro(- 'assertDontSeeTextInStreamedResponse',- function (string $needle) {- Assert::assertFalse(- collect(Reader::createFromString($this->streamedContent())->getRecords())- ->pluck(0)- ->contains($needle)- );-- return $this;- }- );- }-public function test_permission_required_to_view_unaccepted_asset_report(){$this->actingAs(User::factory()->create())diff --git a/tests/Support/CustomTestMacros.php b/tests/Support/CustomTestMacros.phpindex be9a527f4c..157ed988e5 100644--- a/tests/Support/CustomTestMacros.php+++ b/tests/Support/CustomTestMacros.php@@ -4,6 +4,7 @@ namespace Tests\Support;use Illuminate\Database\Eloquent\Model;use Illuminate\Testing\TestResponse;+use League\Csv\Reader;use PHPUnit\Framework\Assert;use RuntimeException;@@ -11,6 +12,32 @@ trait CustomTestMacros{protected function registerCustomMacros(){+ TestResponse::macro(+ 'assertSeeTextInStreamedResponse',+ function (string $needle): self {+ Assert::assertTrue(+ collect(Reader::createFromString($this->streamedContent())->getRecords())+ ->pluck(0)+ ->contains($needle)+ );++ return $this;+ }+ );++ TestResponse::macro(+ 'assertDontSeeTextInStreamedResponse',+ function (string $needle): self {+ Assert::assertFalse(+ collect(Reader::createFromString($this->streamedContent())->getRecords())+ ->pluck(0)+ ->contains($needle)+ );++ return $this;+ }+ );+$guardAgainstNullProperty = function (Model $model, string $property) {if (is_null($model->{$property})) {throw new RuntimeException(