generated from tenantcloud/php-package-skeleton
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Move conditionalUpdate to regular query builder (#37)
* feat: Add conditionalUpdate to regular query builder * fix: Failing tests
- Loading branch information
1 parent
7c57285
commit 66f7fe9
Showing
9 changed files
with
87 additions
and
41 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
providers: | ||
- TenantCloud\Mixins\MixinsServiceProvider |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
40 changes: 40 additions & 0 deletions
40
tests/QueryBuilderMixin/QueryBuilderConditionalUpdateTest.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
<?php | ||
|
||
namespace Tests\QueryBuilderMixin; | ||
|
||
use Illuminate\Foundation\Testing\RefreshDatabase; | ||
use TenantCloud\Mixins\Mixins\QueryBuilderMixin; | ||
use Tests\Database\Factories\TestStubFactory; | ||
use Tests\Database\Models\TestStub; | ||
use Tests\TestCase; | ||
|
||
/** @see QueryBuilderMixin::conditionalUpdate() */ | ||
class QueryBuilderConditionalUpdateTest extends TestCase | ||
{ | ||
use RefreshDatabase; | ||
|
||
public function testUpdatesRecordsUsingAMap(): void | ||
{ | ||
$stub1 = TestStubFactory::new()->create([ | ||
'name' => 'one', | ||
]); | ||
$stub2 = TestStubFactory::new()->create([ | ||
'name' => 'two', | ||
'description' => 'unchanged', | ||
]); | ||
$stub3 = TestStubFactory::new()->create([ | ||
'name' => 'three', | ||
]); | ||
|
||
TestStub::query() | ||
->getQuery() | ||
->conditionalUpdate('description', 'name', [ | ||
'one' => 'one description', | ||
'three' => 'three description', | ||
]); | ||
|
||
self::assertSame('one description', $stub1->fresh()->description); | ||
self::assertSame('unchanged', $stub2->fresh()->description); | ||
self::assertSame('three description', $stub3->fresh()->description); | ||
} | ||
} |