Skip to content

Commit 63af4b5

Browse files
spawniaclaude
andcommitted
Refactor: simplify createHasConditionInputType and test assertions
- Delegate createHasConditionInputType to createWhereConditionsInputType to eliminate code duplication (37 lines reduced to 6) - Replace assert() with $this->assertInstanceOf() for PHPUnit consistency Co-Authored-By: Claude <noreply@anthropic.com>
1 parent f5e8e70 commit 63af4b5

File tree

2 files changed

+9
-39
lines changed

2 files changed

+9
-39
lines changed

src/WhereConditions/WhereConditionsServiceProvider.php

Lines changed: 4 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -107,40 +107,10 @@ public static function createWhereConditionsInputType(string $name, string $desc
107107

108108
public static function createHasConditionInputType(string $name, string $description, string $columnType): InputObjectTypeDefinitionNode
109109
{
110-
$hasRelationInputName = $name . self::DEFAULT_WHERE_RELATION_CONDITIONS;
111-
$name .= self::DEFAULT_HAS_CONDITION;
112-
113-
$operator = Container::getInstance()->make(Operator::class);
114-
115-
$operatorName = Parser::enumTypeDefinition(
116-
$operator->enumDefinition(),
117-
)
118-
->name
119-
->value;
120-
$operatorDefault = $operator->default();
121-
122-
return Parser::inputObjectTypeDefinition(/** @lang GraphQL */ <<<GRAPHQL
123-
"{$description}"
124-
input {$name} {
125-
"The column that is used for the condition."
126-
column: {$columnType}
127-
128-
"The operator that is used for the condition."
129-
operator: {$operatorName} = {$operatorDefault}
130-
131-
"The value that is used for the condition."
132-
value: Mixed
133-
134-
"A set of conditions that requires all conditions to match."
135-
AND: [{$name}!]
136-
137-
"A set of conditions that requires at least one condition to match."
138-
OR: [{$name}!]
139-
140-
"Check whether a relation exists. Extra conditions or a minimum amount can be applied."
141-
HAS: {$hasRelationInputName}
142-
}
143-
GRAPHQL
110+
return self::createWhereConditionsInputType(
111+
$name . self::DEFAULT_HAS_CONDITION,
112+
$description,
113+
$columnType,
144114
);
145115
}
146116

tests/Integration/WhereConditions/WhereConditionsDirectiveTest.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -271,12 +271,12 @@ public function testOperatorIn(): void
271271
public function testOperatorIsNull(): void
272272
{
273273
$postWithoutBody = factory(Post::class)->make();
274-
assert($postWithoutBody instanceof Post);
274+
$this->assertInstanceOf(Post::class, $postWithoutBody);
275275
$postWithoutBody->body = null;
276276
$postWithoutBody->save();
277277

278278
$postWithBody = factory(Post::class)->make();
279-
assert($postWithBody instanceof Post);
279+
$this->assertInstanceOf(Post::class, $postWithBody);
280280
$postWithBody->body = 'foobar';
281281
$postWithBody->save();
282282

@@ -305,12 +305,12 @@ public function testOperatorIsNull(): void
305305
public function testOperatorNotNull(): void
306306
{
307307
$postWithoutBody = factory(Post::class)->make();
308-
assert($postWithoutBody instanceof Post);
308+
$this->assertInstanceOf(Post::class, $postWithoutBody);
309309
$postWithoutBody->body = null;
310310
$postWithoutBody->save();
311311

312312
$postWithBody = factory(Post::class)->make();
313-
assert($postWithBody instanceof Post);
313+
$this->assertInstanceOf(Post::class, $postWithBody);
314314
$postWithBody->body = 'foobar';
315315
$postWithBody->save();
316316

@@ -904,7 +904,7 @@ public function testQueryForNull(): void
904904
factory(User::class, 3)->create();
905905

906906
$userNamedNull = factory(User::class)->make();
907-
assert($userNamedNull instanceof User);
907+
$this->assertInstanceOf(User::class, $userNamedNull);
908908
$userNamedNull->name = null;
909909
$userNamedNull->save();
910910

0 commit comments

Comments
 (0)